Convert gitgram/ and aitimemachine/ from embedded git repos (which showed as opaque submodule gitlinks on GitHub) into fully-tracked first-party content. AITM now merges its 7 vendored repos as first-party engines: - memory: beads (Go task DAG) + context7 (docs SDK), unified into saved_contexts - git: vendored C git (bundled binary) + gitnexus (in-process code intelligence) - agentic: a2a (@a2a-js/sdk) + pal (AITM-managed Python subprocess) Includes the full session's product build: Gitgram web/mobile/backend features, AITM website/CLI/MCP, the unified memory layer, engine build tooling (scripts/build-engines.sh, Dockerfile, CI), docs (README, ENGINES.md, ARCHITECTURE.md), and extensive test suites. Build artifacts, node_modules, external/, and gemini-cli are gitignored. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
3.5 KiB
Context Management for Multi-Repo Support
Problem
MCP servers don't receive working directory context from AI clients (Claude Code/Amp), causing database routing issues:
- MCP server process starts with its own CWD
bduses tree-walking to discover databases based on CWD- Without correct CWD,
bddiscovers wrong database or falls back to~/.beads - Result: Issues get misrouted across repositories
Current Implementation (Partial Solution)
We've added two new MCP tools to allow explicit context management:
Tools
set_context
Sets the workspace root directory for all bd operations.
Parameters:
workspace_root(string): Absolute path to workspace/project root directory
Returns: Confirmation message with resolved paths (workspace root and database)
Behavior:
- Resolves to git repo root if inside a git repository
- Walks up directory tree to find
.beads/*.db - Sets
BEADS_WORKING_DIR,BEADS_DB, andBEADS_CONTEXT_SETenvironment variables
where_am_i
Shows current workspace context and database path for debugging.
Returns: Current context information including workspace root, database path, and actor
Write Operation Protection
All write operations (create, update, close, reopen, dep, init) are decorated with @require_context.
Enforcement: Only enforced when BEADS_REQUIRE_CONTEXT=1 environment variable is set.
This allows backward compatibility while adding safety for multi-repo setups.
Limitations
Environment Variable Persistence: FastMCP's architecture doesn't guarantee environment variables persist between tool calls. This means:
set_contextsets env vars for that tool call- Subsequent tool calls may not see those env vars
- Context needs to be re-established for each session
Recommended Usage
For Single Repository (Current Default)
No changes needed. The MCP server works as before with auto-discovery.
For Multiple Repositories (Future)
Option 1: Explicit Database Path (Current Workaround)
{
"mcpServers": {
"beads-repo1": {
"command": "uvx",
"args": ["beads-mcp"],
"env": {
"BEADS_DB": "/path/to/repo1/.beads/prefix.db"
}
},
"beads-repo2": {
"command": "uvx",
"args": ["beads-mcp"],
"env": {
"BEADS_DB": "/path/to/repo2/.beads/prefix.db"
}
}
}
}
Option 2: Client-Side Context Management (Future) AI clients would need to:
- Call
set_contextat session start with workspace root - MCP protocol would need to support persistent session state
Option 3: Dolt Server with RPC (Future - Path 1.5 from bd-105)
- Add
cwdparameter to Dolt server RPC protocol - Server performs tree-walking per request
- MCP server passes workspace_root via RPC
- Benefits: Centralized routing, supports multiple contexts per server
Option 4: Advanced Routing Server (Future - Path 2 from bd-105) For >50 repos:
- Dedicated routing server with repo->DB mappings
- MCP becomes thin shim
- Enables shared connection pooling, cross-repo queries
Testing
The context management tools are tested in:
tests/test_mcp_server_integration.py: MCP tool tests- Manual testing: See
/tmp/test-repo-{1,2}example
Run tests:
uv run pytest tests/test_mcp_server_integration.py -v
Future Work
See bd-105 for full architectural analysis and roadmap.
Priority: P0/P1 - Active data corruption risk in multi-repo setups.