Skip to content

MCP python server doesn't work in claude desktop app #406

@DanieleMorotti

Description

@DanieleMorotti

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 closed

It 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions