feat(mcp): add stdio transport to mcp_client_python - #2272
Open
noron12234 wants to merge 1 commit into
Open
Conversation
The extension could only reach MCP servers over SSE. `on_start` called `sse_client(url=...)` directly, so a server that speaks stdio - which is how most MCP servers are distributed and run - could not be used at all. Add a `command` property holding the command line of a local MCP server. When it is set the extension splits it with `shlex.split` and launches the server through `stdio_client`, falling back to `url` for SSE. Both transports yield a two-element stream tuple, so `ClientSession(*streams)` and the existing shutdown path are unchanged. When neither `command` nor `url` is set, the extension now logs an error instead of silently registering no tools. The README was still the unedited template; fill it in with both transports and a configuration reference.
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.
Problem
mcp_client_pythoncan only reach MCP servers over SSE.on_startcallssse_client(url=...)directly, so a server that speaks stdio cannot be used at all — even though stdio is how most MCP servers are distributed and run (npx -y @modelcontextprotocol/server-filesystem /data,uvx some-mcp-server, a local script).There is also no feedback when the extension is misconfigured: with
urlempty,on_startskips the whole connection block and the extension registers no tools, silently.Change
Add a
commandproperty holding the command line of a local MCP server:{ "command": "npx -y @modelcontextprotocol/server-filesystem /data" }Transport selection moves into
_create_transport:commandset →shlex.splitit and launch throughstdio_clienturlset →sse_clientas beforeshlex.splitmeans ordinary shell quoting works for paths with spaces.Both transports yield a two-element stream tuple, so
ClientSession(*streams)and the existingon_stopteardown are unchanged. SSE behaviour is untouched.The README was still the unedited template (
- xxx feature); it now documents both transports and the two properties.Verification
Against a real MCP server launched over stdio, using the same construction as
_create_transport:shlex.splitparses a quoted path correctlystdio_clientyields 2 streams, soClientSession(*streams)is right for this transport toolist_tools()returns the server's toolsNot included
Streamable HTTP is the other transport worth having, but the SDK renamed it between major versions (
streamablehttp_clientin 1.x,streamable_http_clientin 2.0), so it needs a version compatibility decision. Happy to follow up in a separate PR once there is a preference on how this extension should pinmcp— the currentmcp>=1.2.1has no upper bound and 2.0 is already out.