Repository navigation
Description
Summary
McpConfig::load() documents itself as "resolving project-local config against the process working directory," but it delegates to load_for_dir(None), which skips project-local loading entirely rather than falling back to the cwd. Every caller of load() therefore sees global config only: .mcp.json, .jcode/mcp.json, .claude/mcp.json, and the projects.<abs_path>.mcpServers entries in ~/.claude.json are all invisible.
#420 threaded a project directory through the daemon session paths, which is why interactive daemon-backed sessions work. The non-daemon and pool-level paths were left on load() and still silently drop project scope.
Repro
/tmp/probe/server.sh — a minimal stdio server that answers initialize and stays up long enough to be seen:
#!/bin/bash
read -r line
echo '{"jsonrpc":"2.0","id":1,"result":{"protocolVersion":"2024-11-05","capabilities":{"tools":{}},"serverInfo":{"name":"probe","version":"1"}}}'
sleep 2Two config files, one global and one project-scoped:
# global
cat > ~/.jcode/mcp.json <<'EOF'
{"mcpServers": {"probe": {"command": "/tmp/probe/server.sh", "args": ["--global"]}}}
EOF
# project
mkdir -p /tmp/proj && cat > /tmp/proj/.mcp.json <<'EOF'
{"mcpServers": {"projectonly": {"command": "/tmp/probe/server.sh", "args": ["--project-scope"]}}}
EOFRun from the project directory:
cd /tmp/proj
jcode run "reply ok"From ~/.jcode/logs/jcode-<date>.log:
MCP: Found 1 server(s) in config
MCP: Connecting to 'probe' (/tmp/probe/server.sh ["--global"]) cwd=None
Expected: both servers load — probe from global config and projectonly from the .mcp.json in the working directory, which the README lists as a supported Claude Code compatibility path.
Actual: only probe loads. projectonly is never read, and cwd=None on the connect line shows the manager was constructed with no project directory at all.
Reproduced on the released v0.61.1 binary; the master code paths cited below are unchanged as of aadd92f. Isolating with JCODE_HOME reproduces it without touching a real config.
Cause
crates/jcode-base/src/mcp/protocol.rs:478-530:
pub fn load() -> Self {
Self::load_for_dir(None)
}and inside load_for_dir:
// Project-local config files, resolved against the project directory.
if let Some(project_root) = project_dir {
Self::merge_servers_preferring_runnable(
&mut merged.servers,
Self::load_project_locals(project_root).servers,
);
}With project_dir == None the whole block is skipped — there is no current_dir() fallback. The same None also reaches load_claude_json(&claude_json, cwd) at protocol.rs:512-516, so per-project ~/.claude.json entries are dropped too.
Callers still on load():
| Site | Effect |
|---|---|
src/cli/commands.rs:2390 — register_mcp_tools(None, None, None) |
jcode run gets no project config (this is the repro above) |
crates/jcode-tui/src/tui/app/tui_lifecycle.rs:348, 760 — McpManager::new() |
in-process TUI construction sets project_dir: None |
crates/jcode-base/src/mcp/pool.rs:62 — SharedMcpPool::from_default_config() |
the shared pool's own config has no project scope |
crates/jcode-base/src/mcp/pool.rs:253 — SharedMcpPool::reload() |
reload re-reads with load(), so a daemon session that did have project servers loses them from the pool config on reload |
crates/jcode-app-core/src/server/debug_command_exec.rs:249 |
debug view reports the wrong server set |
crates/jcode-base/src/mcp/manager.rs:68 — McpManager::new() |
the project_dir: None constructor behind several of the above |
crates/jcode-base/src/mcp/protocol.rs:463-476 (load_project_locals) is correct and needs no change; it simply never gets called on these paths.
Impact
The README's Claude Code compatibility section (lines 508-513) promises .mcp.json at the repo root and per-project ~/.claude.json entries. On the paths above, neither loads, with no log line indicating the omission — the only symptom is a server that "should be there" being absent.
This defeats the main use for a repo-committed .mcp.json: a team config that every clone picks up. jcode run in CI or a script sees global config only, which is the environment least likely to have any.
The pool.reload() case is the sharper one, because it is a regression within a working session: /mcp reload silently narrows the pool config to global-only.
Suggestion
Make load() honor its own documentation:
pub fn load() -> Self {
Self::load_for_dir(std::env::current_dir().ok().as_deref())
}That fixes jcode run, McpManager::new(), and from_default_config() in one place, and matches what the doc comment already claims. load_for_dir(Some(dir)) callers are unaffected.
SharedMcpPool::reload() (pool.rs:253) needs separate handling — the pool is shared across sessions with different project directories, so a cwd fallback there is arguably wrong. Either store the config-resolution directory on the pool at construction and reuse it on reload, or have reload() take the directory from the caller the way McpManager::reload() does at manager.rs:422.
Worth a test that asserts a .mcp.json in the process cwd is visible via load(), since the current gap is precisely that no test exercises the None path against a populated project directory.
Activity
fix(mcp): load project config from cwd on default paths (#790)
1jehuang commentedon Aug 5, 2026
Fixed on master. Default MCP config loading now honors the process cwd, while shared-pool reload remains bound to its original project directory. Regression coverage verifies cwd switching and reload behavior.
fix(mcp): load project config from cwd on default paths (1jehuang#790)
fix(mcp): load project config from cwd on default paths (1jehuang#790)
fix(mcp): load project config from cwd on default paths (1jehuang#790)
fix(mcp): load project config from cwd on default paths (1jehuang#790)
fix(mcp): load project config from cwd on default paths (1jehuang#790)
fix(mcp): load project config from cwd on default paths (1jehuang#790)