[BUG] SDK doesn't read from .mcp.json until the CLI is ran in the current working directory
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
I have a .mcp.json file in my current working directory. Upon launching the Claude Agent SDK from that directory, Claude doesn't seem to have access to any of the MCP servers defined in my .mcp.json file.
This can be verified by calling both the mcpServerStatus() callback and examining the mcp_servers field in SDKSystemMessages received while running query. Both will not have any of the servers configured in my .mcp.json file.
Both of the above methods _will_ start to return valid data after I:
- Launch
claudefrom the CLI in my current working directory - Restart the SDK
NOTE: This problem does not occur for local or user scoped MCPs. Those work just fine in the Claude Agent SDK. Only project scoped MCPs have this problem.
What Should Happen?
The Claude Agent SDK (just as the CLI) should read from the .mcp.json file in my current working directory upon startup _without_ relying on the CLI starting up in that directory.
Error Messages/Logs
Steps to Reproduce
- Create a
.mcp.jsonfile in your current working directory. - Run the
query()function with anAsyncIterableprompt in the Claude Agent SDK. - Either call the
mcpServerStatus()callback, or send a message and examine themcp_serversfield on all messages received of typeSDKSystemMessage. - Launch the Claude Code CLI from the current working directory, then run
/mcp(you'll see the server(s) defined in your.mcp.jsonappear here) - Close the existing
AsyncIterable, and launch a newquery()function using the Claude Agent SDK. - Either call
mcpServerStatus()or send a message and examine themcp_serversfield on a message of typeSDKSystemMessage. It will be populated correctly now with the value from your.mcp.jsonfile.
Claude Model
None
Is this a regression?
No, this never worked
Last Working Version
_No response_
Claude Code Version
2.0.54
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
Non-interactive/CI environment
Additional Information
_No response_
This issue has 7 comments on GitHub. Read the full discussion on GitHub ↗