-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Python FastMCP stdio server doesn't initialize #395
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
Comments
This appears to be similar to #382 but the repro code here is smaller and as close as practical to the sdk docs. The repro steps here also fail both under Windows and Linux. |
Update: Was able to make a Python client that connects to a node-based server.
|
I am also having the similar issue in Mac (M2 Pro), import asyncio
from mcp import ClientSession, StdioServerParameters, types
from mcp.client.stdio import stdio_client
# Create server parameters for stdio connection
server_params = StdioServerParameters(
command="node",
args=["/Users/xxx/src/server.js",],
env=None,
)
async def run():
async with stdio_client(server_params) as (read, write):
async with ClientSession(read, write) as session:
# Initialize the connection
await session.initialize()
tools = await session.list_tools()
print(tools)
if __name__ == "__main__":
asyncio.run(run()) I create a simple client like above, and used the MCP server that really worked other MCP clients. But for some reason, |
if I keep the script on running, I get this error Error: Argument list too long (os error 7) It seems like it is failing to because of very large |
For the server, the major thing I missed, embarrassingly, was that I needed to https://github.com/modelcontextprotocol/python-sdk?tab=readme-ov-file#quickstart |
You can try to add the following codes on the file mcp_echo_server.py
|
我使用此方法运行成功 |
It previously worked, now it doesn't anymore Also all the other Python MCP Clients I tried (like the official MCP Python SDK and FastMCP MCP Client) don't work either. |
Uh oh!
There was an error while loading. Please reload this page.
Describe the bug
Python MCP client cannot successfully initialize an MCP Stdio server.
To Reproduce
I have two reproduction steps. One for windows, and one for Linux. Additional notes and details are here in my reproduction notes but I will reproduce them here as well.
Windows Reproduction Steps
Create a new empty directory and cd to it, then:
Install
mcp
and run:The output I get is this:
Note that we never see the message indicating that it finished initializing the session.
Linux Container Reproduction Steps
There is a repo with these files but I am placing the info here as well.
Make an empty directy and go to it, then:
podman
but you can usedocker
:your-src-path
with the full pathname of the root abovesrc
:pip install mcp cd src python mcp_client.py
Observed output:
Note that we do not see further output indicating a successful initialization.
Expected behavior
We expect to see the message
Session initialized successfully.
Desktop (please complete the following information):
Additional context
I have tried this in many configurations, including Python 3.10 windows, Python 3.12 windows, Python 3.12 under WSL, and running Linux in a container, using the latest main branch and also the latest releases, and various forms of UV and global Python installations. I have also tried it using asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) in various Windows configurations. Under some configurations this leads to a new NotImplementedError, but under no circumstances was I able to make it work.
I haven't been able to make a Python client work yet. I can get node client and server working without difficulties, though.
It's possible that issue 382 is similar, although its
code for the repro is much more complex. I have endeavored to strip this down to the bare minimum of what is shown
in the sdk documentation. In fact the only difference in these repros versus the sdk documentation on clients is the example there shows something about
handle_sampling_message
and indicates it is optional. I was unable to figure out what that's for either by reading the docs orstudying the source for a while, so I removed that, but it doesn't help either way.
I am able to make node clients work without difficulty, but I really need a Python client, so I'm sticking with this.
I have not yet tried an HTTP/SSE client and will do so next, but I already have a stdio-only server that works
well for my use case in Claude desktop that I am trying to get working from a Python client.
The text was updated successfully, but these errors were encountered: