Repository navigation
MCP python server doesn't work in claude desktop app #406
Copy link
Copy link
Closed
Description
Hi,
I didn't find any similar issues, but please let me know if there are any existing ones.
I implemented a Python server as follows:
from mcp.server.fastmcp import FastMCP
# Create server
fast_mcp = FastMCP("MN API")
@fast_mcp.tool()
async def fetch_api_info(...):
...
@fast_mcp.tool()
async def get_user_info(...):
...
if __name__ == "__main__":
fast_mcp.run(transport="sse")When I run this file directly with python, it works without any issues. However, when I load it in the Claude desktop app using the following configuration:
{
"mcpServers": {
"Custom Server": {
"command": "/path/to/.local/bin/uv",
"args": [
"--directory",
"/path/to/mcp_test",
"run",
"server.py"
]
}
}
}I receive the following error log:
2025-04-01T16:09:59.795Z [MN API Server] [info] Initializing server...
2025-04-01T16:09:59.804Z [MN API Server] [info] Server started and connected successfully
2025-04-01T16:09:59.805Z [MN API Server] [info] Message from client: {"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"claude-ai","version":"0.1.0"}},"jsonrpc":"2.0","id":0}
2025-04-01T16:10:01.152Z [MN API Server] [info] Initializing server...
2025-04-01T16:10:01.161Z [MN API Server] [info] Server started and connected successfully
2025-04-01T16:10:01.164Z [MN API Server] [info] Message from client: {"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"claude-ai","version":"0.1.0"}},"jsonrpc":"2.0","id":0}
INFO: Started server process [43926]
INFO: Waiting for application startup.
INFO: Started server process [43940]
INFO: Application startup complete.
INFO: Waiting for application startup.
INFO: Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)
INFO: Application startup complete.
ERROR: [Errno 48] error while attempting to bind on address ('0.0.0.0', 8000): address already in use
INFO: Waiting for application shutdown.
INFO: Application shutdown complete.
2025-04-01T16:10:05.018Z [MN API Server] [info] Server transport closed
2025-04-01T16:10:05.018Z [MN API Server] [info] Client transport closed
2025-04-01T16:10:05.018Z [MN API Server] [info] Server transport closed unexpectedly, this is likely due to the process exiting early. If you are developing this MCP server you can add output to stderr (i.e. `console.error('...')` in JavaScript, `print('...', file=sys.stderr)` in python) and it will appear in this log.
2025-04-01T16:10:05.019Z [MN API Server] [error] Server disconnected. For troubleshooting guidance, please visit our [debugging documentation](https://modelcontextprotocol.io/docs/tools/debugging) {"context":"connection"}
2025-04-01T16:10:05.019Z [MN API Server] [info] Client transport closed
2025-04-01T16:10:59.807Z [MN API Server] [info] Message from client: {"jsonrpc":"2.0","method":"notifications/cancelled","params":{"requestId":0,"reason":"Error: MCP error -32001: Request timed out"}}
2025-04-01T16:10:59.808Z [MN API Server] [info] Client transport closed
2025-04-01T16:10:59.809Z [MN API Server] [info] Server transport closed
2025-04-01T16:10:59.809Z [MN API Server] [info] Client transport closed
2025-04-01T16:10:59.809Z [MN API Server] [info] Server transport closed unexpectedly, this is likely due to the process exiting early. If you are developing this MCP server you can add output to stderr (i.e. `console.error('...')` in JavaScript, `print('...', file=sys.stderr)` in python) and it will appear in this log.
2025-04-01T16:10:59.809Z [MN API Server] [error] Server disconnected. For troubleshooting guidance, please visit our [debugging documentation](https://modelcontextprotocol.io/docs/tools/debugging) {"context":"connection"}
INFO: Shutting down
INFO: Waiting for application shutdown.
INFO: Application shutdown complete.
INFO: Finished server process [43926]
2025-04-01T16:10:59.946Z [MN API Server] [info] Server transport closed
2025-04-01T16:10:59.946Z [MN API Server] [info] Client transport closedIt appears that the server is started correctly, but then a parallel instance is launched, causing an address already in use error . This error doesn't occur when running the server.py file directly with Python.
Am I doing something wrong, or should it work as expected?
Thank you
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Activity
ishswar commentedon Apr 1, 2025
You are starting the server with SSE but in Client config you are not using that - so either change
ssefrom code tostdioand try or use https://www.npmjs.com/package/mcp-remote - and then use that to connect to SSE server in ClaudDanieleMorotti commentedon Apr 2, 2025
Okay, it works with
stdio, thank youNilayYadav commentedon Apr 2, 2025
I'm getting
Error: MCP error -32001: Request timed outeven though I'm usingserver.run("stdio")and in my claude config its
ishswar commentedon Apr 2, 2025
@NilayYadav Config does not look correct -
/path/to/sever//server.pylooks like place holder you need to replace that with the correct path - and it is just adirname the actual python file also needs to be replaced that isserver.pyin the above exampleNilayYadav commentedon Apr 2, 2025