fix(mcp): default stdio server cwd to the session directory#994
Open
Zehee wants to merge 1 commit into
Open
Conversation
When kimi web launches the background server daemon, the server process runs from ~/.kimi-code/server. stdio MCP servers that omitted cwd therefore inherited that directory instead of the user's project directory, breaking workspace-relative storage. loadMcpServers now assigns a sensible default cwd to every config source: - user-global ~/.kimi-code/mcp.json -> session working directory - repo-root .mcp.json -> repo root (unchanged) - project-local .kimi-code/mcp.json -> session working directory Closes MoonshotAI#982
🦋 Changeset detectedLatest commit: 894b477 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
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.
When kimi web launches the background server daemon, the server process runs from ~/.kimi-code/server. stdio MCP servers that omitted cwd therefore inherited that directory instead of the user's project directory, breaking workspace-relative storage.
loadMcpServers now assigns a sensible default cwd to every config source:
Closes #982
Problem
When launching a session via
kimi web, Kimi Code starts a long-lived background daemon whose working directory is intentionally set to~/.kimi-code/server(to avoid pinning the caller's directory on Windows). As a result, any stdio MCP server that omitscwdin its config inherited the daemon's directory instead of the user's project directory.Session-context tools were unaffected because they resolve the active workspace at request time, but storage-oriented tools (e.g. custom memory/note MCP servers) wrote data into a server-side workspace, making
kimi webbehave differently from localkimi.Root cause
packages/agent-core/src/mcp/config-loader.tsonly supplied a defaultstdioCwdBasefor repo-root.mcp.json:With
cwd: undefined,StdioClientTransportfalls back toprocess.cwd()of the spawning process —~/.kimi-code/serverinkimi webmode.Fix
Assign a sensible default
cwdto every MCP config source:cwd~/.kimi-code/mcp.json<projectRoot>/.mcp.json<cwd>/.kimi-code/mcp.jsoninput.cwdis the sessionworkDir, so the fix also answers the question of whetherkimi webshould inherit the CLI's project context: yes, and MCP server spawning is the place where that inheritance must happen.Why not delay daemon startup?
The
kimi webdaemon is a singleton that can host sessions across multiple workspaces, so it cannot wait for a single project directory before starting. The correct fix is therefore to make each session supply its own project directory when configuring MCP servers, which is what this change does.Test updates
Updated
packages/agent-core/test/mcp/config-loader.test.tsto assert that user-global and project-local stdio entries receive a defaultcwdequal to the session directory.Verification
Both test suites pass.
Checklist
kimi webstarts MCP servers from the CLI installation directory, breaking workspace-relative MCP tools #982).