fix(mcp): trust process project override#378
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR restores a process-level project override for the MCP server so long-lived MCP hosts can reliably scope reads/writes to a configured project (via engram mcp --project or ENGRAM_PROJECT) instead of being forced to rely on cwd-based detection.
Changes:
- Add
MCPConfig.DefaultProjectand thread it through MCP tool handlers to take precedence over cwd detection for current-project, read resolution, and write resolution. - Wire
--projectandENGRAM_PROJECTintocmdMCPand pass them into the MCP server config. - Update/extend tests to cover the new process-override precedence and to keep per-call project validation strict.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| internal/mcp/mcp.go | Introduces DefaultProject process override, adds helpers to apply it before cwd detection across read/write resolution and selected tools. |
| internal/mcp/mcp_test.go | Updates handler call signatures and adds tests asserting override precedence and validation invariants. |
| cmd/engram/main.go | Parses --project and ENGRAM_PROJECT for engram mcp and passes the override into mcp.MCPConfig. |
| cmd/engram/main_test.go | Updates tests to assert the new DefaultProject wiring from flag/env. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+2036
to
+2047
| func processProjectResult(project string) (projectpkg.DetectionResult, bool) { | ||
| project = strings.TrimSpace(project) | ||
| if project == "" { | ||
| return projectpkg.DetectionResult{}, false | ||
| } | ||
| normalized, warning := store.NormalizeProject(project) | ||
| return projectpkg.DetectionResult{ | ||
| Project: normalized, | ||
| Source: sourceProcessOverride, | ||
| Path: "", | ||
| Warning: warning, | ||
| }, true |
Comment on lines
872
to
+874
| res := projectpkg.DetectProjectFull(cwd) | ||
| if processRes, ok := processProjectResult(cfg.DefaultProject); ok { | ||
| res = processRes |
Comment on lines
832
to
855
| func cmdMCP(cfg store.Config) { | ||
| // Parse --tools flag. Project is always auto-detected from cwd at call time (JR2-4). | ||
| toolsFilter := "" | ||
| projectOverride := strings.TrimSpace(os.Getenv("ENGRAM_PROJECT")) | ||
| for i := 2; i < len(os.Args); i++ { | ||
| if strings.HasPrefix(os.Args[i], "--tools=") { | ||
| toolsFilter = strings.TrimPrefix(os.Args[i], "--tools=") | ||
| } else if os.Args[i] == "--tools" && i+1 < len(os.Args) { | ||
| toolsFilter = os.Args[i+1] | ||
| i++ | ||
| } else if strings.HasPrefix(os.Args[i], "--project=") { | ||
| projectOverride = strings.TrimSpace(strings.TrimPrefix(os.Args[i], "--project=")) | ||
| if projectOverride == "" { | ||
| fatal(fmt.Errorf("--project requires a value")) | ||
| } | ||
| } else if os.Args[i] == "--project" { | ||
| if i+1 >= len(os.Args) { | ||
| fatal(fmt.Errorf("--project requires a value")) | ||
| } | ||
| projectOverride = strings.TrimSpace(os.Args[i+1]) | ||
| if projectOverride == "" { | ||
| fatal(fmt.Errorf("--project requires a value")) | ||
| } | ||
| i++ | ||
| } |
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
engram mcp --projectandENGRAM_PROJECTinto MCP process configFixes #312
Fixes #248
Fixes #347
Non-goals
Tests
go test ./internal/mcp ./cmd/engramgo test ./...Review