Auto-detect Project Root from MCP Client
Problem Statement
The context.md file (used for preserving context across conversation compaction) works correctly in the codingbuddy project but fails to work in other projects.
Root Cause Analysis
Why it works in this project
In /Users/jeremy/workspace/codebuddy/.mcp.json:
"codingbuddy": {
"command": "npx",
"args": ["codingbuddy@2.4.1", "mcp"],
"env": {
"CODINGBUDDY_PROJECT_ROOT": "/Users/jeremy/workspace/codebuddy"
}
}
The CODINGBUDDY_PROJECT_ROOT environment variable is hardcoded for this specific project.
Why it fails in other projects
Other projects have:
- No
CODINGBUDDY_PROJECT_ROOT environment variable configured
- No
codingbuddy.config.js file
When neither is present, the MCP server falls back to process.cwd(), which may not point to the actual project directory when the MCP server is launched by Claude Code.
Impact
| Scenario |
This Project |
Other Projects |
CODINGBUDDY_PROJECT_ROOT |
Hardcoded |
Not set |
codingbuddy.config.js |
Exists |
Missing |
context.md creation |
Works |
Fails |
Why This Work is Needed
- Poor Developer Experience: Users must manually configure
CODINGBUDDY_PROJECT_ROOT for every project
- Hidden Failure: No error messages when
context.md is created in the wrong location
- Context Loss: PLAN → ACT → EVAL workflow breaks when context is not persisted correctly
- Inconsistent Behavior: Works in some projects but not others, causing confusion
Proposed Solution
Utilize the MCP protocol's roots/list capability:
- MCP clients (like Claude Code) can expose their workspace directories via
roots/list request
- The MCP server can request this information after connection
- Automatically detect the correct project root without manual configuration
Acceptance Criteria
Auto-detect Project Root from MCP Client
Problem Statement
The
context.mdfile (used for preserving context across conversation compaction) works correctly in the codingbuddy project but fails to work in other projects.Root Cause Analysis
Why it works in this project
In
/Users/jeremy/workspace/codebuddy/.mcp.json:The
CODINGBUDDY_PROJECT_ROOTenvironment variable is hardcoded for this specific project.Why it fails in other projects
Other projects have:
CODINGBUDDY_PROJECT_ROOTenvironment variable configuredcodingbuddy.config.jsfileWhen neither is present, the MCP server falls back to
process.cwd(), which may not point to the actual project directory when the MCP server is launched by Claude Code.Impact
CODINGBUDDY_PROJECT_ROOTcodingbuddy.config.jscontext.mdcreationWhy This Work is Needed
CODINGBUDDY_PROJECT_ROOTfor every projectcontext.mdis created in the wrong locationProposed Solution
Utilize the MCP protocol's
roots/listcapability:roots/listrequestAcceptance Criteria
roots/listfrom client after connection