Skip to content

feat(mcp): add stdio transport to mcp_client_python - #2272

Open
noron12234 wants to merge 1 commit into
TEN-framework:mainfrom
noron12234:feat/mcp-stdio-transport
Open

feat(mcp): add stdio transport to mcp_client_python#2272
noron12234 wants to merge 1 commit into
TEN-framework:mainfrom
noron12234:feat/mcp-stdio-transport

Conversation

@noron12234

Copy link
Copy Markdown
Contributor

Problem

mcp_client_python can only reach MCP servers over SSE. on_start calls sse_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 url empty, on_start skips the whole connection block and the extension registers no tools, silently.

Change

Add a command property holding the command line of a local MCP server:

{
  "command": "npx -y @modelcontextprotocol/server-filesystem /data"
}

Transport selection moves into _create_transport:

  • command set → shlex.split it and launch through stdio_client
  • otherwise url set → sse_client as before
  • neither → log an error and register no tools

shlex.split means ordinary shell quoting works for paths with spaces.

Both transports yield a two-element stream tuple, so ClientSession(*streams) and the existing on_stop teardown 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.split parses a quoted path correctly
  • stdio_client yields 2 streams, so ClientSession(*streams) is right for this transport too
  • the session initializes and list_tools() returns the server's tools

Not included

Streamable HTTP is the other transport worth having, but the SDK renamed it between major versions (streamablehttp_client in 1.x, streamable_http_client in 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 pin mcp — the current mcp>=1.2.1 has no upper bound and 2.0 is already out.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant