fix(mcp): fall back to cwd basename on ambiguous project (#248)#258
Open
CarlosPlasencia wants to merge 1 commit intoGentleman-Programming:mainfrom
Open
Conversation
…rogramming#248) When the MCP server is launched from a directory that is the parent of multiple git repositories, all write tools (mem_save, mem_session_summary, etc.) fail with ErrAmbiguousProject. This is a regression from v1.12.0 where filepath.Base(cwd) was used as a fallback. resolveWriteProject now mirrors the CLI wrapper DetectProject(): on ErrAmbiguousProject it falls back to the lowercased cwd basename, sets Source=SourceDirBasename, and emits a Warning that lists the cwd repos so the user knows the project name was derived from the workspace folder. This makes engram MCP usable again from workspace directories (the common setup with multiple cloned repos under one parent) without removing the structured detection result for non-ambiguous cases. Tests adapted to assert the new fallback behavior (success + envelope + warning) instead of the previous fail-fast error envelope.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #248. Restores v1.12.0 behavior for MCP write tools launched from a directory that is the parent of multiple git repositories.
When the MCP server is launched from a workspace folder containing several cloned repos, all write tools (
mem_save,mem_session_summary,mem_session_start, etc.) currently fail with:This is a regression from v1.12.0 → v1.13.0 introduced by the
mcp-project-autodetectionchange, which switchedresolveWriteProjectfrom the basename-fallback CLI helper to the strictDetectProjectFulland propagatedErrAmbiguousProjectunconditionally.What changed
internal/mcp/mcp.go—resolveWriteProject:ErrAmbiguousProject, fall back tofilepath.Base(cwd)lowercased — same behavior as the CLI wrapperDetectProject(internal/project/detect.go:224).Source = SourceDirBasename.Warninglisting the cwd repo children so the caller knows the project name was derived from the workspace folder, not from a specific repo.Test changes
Five tests were rewritten to assert the new fallback contract instead of the old fail-fast contract:
TestMemSave_AmbiguousEnvelopeTestMemSave_AmbiguousFallbackTestResolveWriteProject_AmbiguousErrorTestResolveWriteProject_AmbiguousFallbackTestMemSessionSummary_AmbiguousReturnsErrorTestMemSessionSummary_AmbiguousFallbackTestWriteTool_AmbiguousErrorUsesCwdRepos_NotAllProjectsTestWriteTool_AmbiguousFallbackWarningListsCwdReposTestHandleGetObservation_DegradedPathNoEnvelopeTestHandleGetObservation_AmbiguousFallbackEnvelopeEach new test verifies: (1) write succeeds, (2)
project_source = "dir_basename", (3)warningis present, (4) for the JW1 test, the warning lists cwd repos and not unrelated store projects.Full test suite passes locally on macOS arm64 (Go 1.26.2):
Spec note
The archived change
2026-04-24-mcp-project-autodetection(REQ-309) currently specifies fail-fast on ambiguous cwd. After this PR is merged, that requirement is no longer accurate for the runtime contract. A follow-up SDD change should update the spec to document the basename fallback (Source=dir_basename+ non-empty Warning) so the spec and code stay aligned. Happy to open it as a separate PR if you prefer.Test plan
go test ./internal/mcp/...— passesgo test ./...— passesmem_savefrom a workspace with multiple git children — write now succeeds withproject_source: "dir_basename"and a warning listing the children.