Skip to content

Remote/client sessions load MCP config from server cwd instead of session working directory #420

Closed

Description

@ravshansbox

Bug

In remote/client mode, project-local .mcp.json is not loaded for a client session even when the file exists in that session's project root.

The TUI header shows the correct client working directory, but MCP status remains:

mcp: (none)

Reproduction

  1. Create or use a project with a valid .mcp.json at the project root.
  2. Configure stdio MCP servers using Claude-compatible mcpServers, for example:
{
  "mcpServers": {
    "example-server": {
      "command": "npx",
      "args": ["-y", "some-mcp-server"]
    }
  }
}
  1. Start a remote/client session with that project as the session working directory.
  2. Observe the header shows mcp: (none).

Evidence

Runtime logs show the client session working directory is set, but MCP registration completes with no configured servers:

mcp_register=0ms
mcp_servers=0

The same .mcp.json shape is valid for jcode's loader because it uses mcpServers and stdio-compatible command entries.

Suspected root cause

The remote subscribe path calls MCP registration without passing the session working directory.

register_mcp_tools creates an McpManager, whose constructors call:

McpConfig::load()

McpConfig::load() reads project-local config relative to the server process cwd, not the subscribed client session working directory.

So the UI/session can show the correct project cwd while MCP discovery happens relative to the shared server's cwd.

Expected behavior

For remote/client sessions, MCP config loading should resolve project-local config from the session working directory, including:

  • .mcp.json
  • .jcode/mcp.json
  • legacy .claude/mcp.json

The server process cwd should not determine project-local MCP config for subscribed client sessions.

Possible fix

Thread the session working directory through MCP registration, for example:

  • add McpConfig::load_for_dir(path)
  • add McpManager::{new_for_dir, with_shared_pool_for_dir}
  • pass the subscribe/session working directory into register_mcp_tools
  • keep current McpConfig::load() as the default for local/headless paths

Add a regression test for remote subscribe with a session working dir containing .mcp.json.

Activity

  1. added
    bug
    priority: medium
    triage: reproducible
    autonomous: likely
    on Jul 2, 2026
  2. 1jehuang commented on Jul 3, 2026

    @1jehuang
    Owner

    Fixed on master in a0a4b87.

    Root cause confirmed as suspected: the remote subscribe path called register_mcp_tools -> McpManager::with_shared_pool -> McpConfig::load(), which resolved .mcp.json / .jcode/mcp.json / .claude/mcp.json (and the per-project entries in ~/.claude.json) against the long-lived server's process cwd, not the session working directory.

    The fix threads the session working dir all the way through:

    • McpConfig::load_for_dir(dir) resolves project-local config against an explicit directory; load() keeps cwd behavior for local/headless use.
    • McpManager::with_shared_pool_for_dir stores the project dir, and reload() reuses it so /mcp reload stays session-scoped too.
    • Registry::register_mcp_tools_for_dir passes the session working dir at every server call site: subscribe (prefers the subscribe request's dir, falls back to the agent's stored session dir), both resume paths, headless session creation, and startup recovery.

    Regression tests cover resolution against an explicit dir (not cwd) and the .jcode -> .mcp -> .claude merge order. Thanks for the precise diagnosis, it pointed at exactly the right seams.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    autonomous: likelybugpriority: mediumtriage: reproducible

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions