-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat: Add MCP server configuration parsing (e.g.: mcp.json) to the SDK
#968
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Add the ability to parse a multi-word command and extract the command and args into `effective_command` and `effective_args` attributes.
More realistic
This reverts commit 38eff49.
instead of str.split, which breaks when there are quoted arguments with spaces in them.
|
The failing tests appears to not be from my changes. From GitHub Copilot Explain Error: Issue AnalysisThe failing job ( ProblemThe test
SolutionTo address this:
Code SuggestionsModify the TestIncrease the threshold to accommodate system variability: assert duration < 10 * _sleep_time_seconds # Adjust multiplierOptimize Resource Handling in
|
mcp.json) to the SDKmcp.json) to the SDK
I found these in a 5ire `mcp.json` config file
because I was seeing tests failing on Windows in GitHub Actions and GitHub Copilot [said](modelcontextprotocol#968 (comment))
It seemed weird doing it in `from_file`, because the caller has to call
`from_file` to find out what the required inputs are and then has to
call `from_file` against to provide the input values.
Now, the caller calls config.get(server, input_values={...})
to provide the input values
|
Letting @ihrpr chime in here, but I believe it would be better if this is an external package that people can use. Since mcp.json is not part of the MCP standard, I don't think we want to include it for now. |
Goals
Add features to the Python SDK that enable Python MCP client applications to support common functionality for configuration and reduce annoying differences between applications
Hopefully, once the ideas are discussed and settled on, this can be ported to the TypeScript SDK, so that client applications in that ecosystem can benefit as well.
Add
MCPServersConfigclass for parsing MCP server configuration (e.g.:mcp.json) to the SDKSupport feature that user can specify full command in
commandand it will automatically be parsed intocommandandargs(Cursor has this feature but I don't know if any other apps do)Support the standard
mcpServerskey or theserverskey, which VS Code usesSupport VS Code
inputskey and associated string interpolationSupport stripping out
//comments (JSONC) because a lot of VS Code examples online have theseOptionally support YAML for MCP server configuration (while still preserving support for the JSON format)
Added docs for all the above at https://github.com/msabramo/python-sdk/blob/config/docs/client-configuration.md
Related issues/discussions
cwdtoStdioServerParameters#292)Motivation and Context
Config API
Claude Desktop introduced the
mcp.jsonfile and then a lot of other applications copied the idea pretty closely, but some applications made little tweaks to their parsing code to support extensions. Examples:commandfor a stdio server which saves the user from having to split a shell command into acommandstring andargslist, which is tedious.serverskey instead ofmcpServersand supports aninputskey and allows associated interpolation of these inputs in other server fields (e.g.: https://github.com/Azure-Samples/remote-mcp-functions-python/blob/main/.vscode/mcp.json)AFAIK, there is no standard for the
mcp.jsonso various applications have been evolving it very informally and so applications have differing abilities and their config files aren't necessarily compatible with each other.This PR aims to create a simple API that standardizes config parsing so applications don't need to worry about implementing it and users benefit from more consistency between its handling by applications.
Assuming that
~/.cursor/mcp.jsonhas this:{ "mcpServers": { "time": { "command": "uvx mcp-server-time" }, ... }(Note the above syntax of stuffing the entire command in
commandworks in Cursor but I don't think it works in Claude Desktop)then the output of this code is:
Note that even though just
commandwas specified, the code went ahead and parsed the command and split it into separatecommandandargsso that the user doesn't have to.Problems with JSON
The JSON format has some drawbacks:
YAML MCP server config
Because of these problems with JSON, I have added an optional YAML variant of the server configuration. It provides a very nice, clean syntax for configuration for those who want to use it:
If I have the above YAML in
mcp.yamland this Python code:then the output is:
However, YAML is optional, and I have tried to ensure that existing
mcp.jsonfiles work as expected with no changes.This PR seeks to add parsing of the MCP servers configuration to the MCP SDK, so:
How Has This Been Tested?
Pretty extensive unit tests
Breaking Changes
No. There are lots of tests that use
mcp.jsonfiles to ensure they are parsed correctly.Types of changes
https://github.com/msabramo/python-sdk/blob/config/docs/client-configuration.md
Checklist
https://github.com/msabramo/python-sdk/blob/config/docs/client-configuration.md
Additional context