[BUG] Cant get the server communicating to Claude correctly
Describe the bug I have setup the server example and followed the instructions to setup mcp-proxy via UV. This appears to be working and the client connects to the server as it lists the tool that is available.
However, when the client attempts to call the endpoint it fails with this error message
Error calling new_endpoint
Traceback (most recent call last):
File "/Users/PythonProject/test-fastapi-mcp-server/.venv/lib/python3.11/site-packages/httpx/_transports/default.py", line 101, in map_httpcore_exceptions
yield
File "/Users/PythonProject/test-fastapi-mcp-server/.venv/lib/python3.11/site-packages/httpx/_transports/default.py", line 394, in handle_async_request
resp = await self._pool.handle_async_request(req)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/PythonProject/test-fastapi-mcp-server/.venv/lib/python3.11/site-packages/httpcore/_async/connection_pool.py", line 256, in handle_async_request
raise exc from None
File "/Users/PythonProject/test-fastapi-mcp-server/.venv/lib/python3.11/site-packages/httpcore/_async/connection_pool.py", line 236, in handle_async_request
response = await connection.handle_async_request(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/PythonProject/test-fastapi-mcp-server/.venv/lib/python3.11/site-packages/httpcore/_async/connection.py", line 101, in handle_async_request
raise exc
File "/Users/PythonProject/test-fastapi-mcp-server/.venv/lib/python3.11/site-packages/httpcore/_async/connection.py", line 78, in handle_async_request
stream = await self._connect(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/PythonProject/test-fastapi-mcp-server/.venv/lib/python3.11/site-packages/httpcore/_async/connection.py", line 124, in _connect
stream = await self._network_backend.connect_tcp(**kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/PythonProject/test-fastapi-mcp-server/.venv/lib/python3.11/site-packages/httpcore/_backends/auto.py", line 31, in connect_tcp
return await self._backend.connect_tcp(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/PythonProject/test-fastapi-mcp-server/.venv/lib/python3.11/site-packages/httpcore/_backends/anyio.py", line 113, in connect_tcp
with map_exceptions(exc_map):
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/contextlib.py", line 155, in __exit__
self.gen.throw(typ, value, traceback)
File "/Users/PythonProject/test-fastapi-mcp-server/.venv/lib/python3.11/site-packages/httpcore/_exceptions.py", line 14, in map_exceptions
raise to_exc(exc) from exc
httpcore.ConnectError: All connection attempts failed
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/Users/PythonProject/test-fastapi-mcp-server/.venv/lib/python3.11/site-packages/fastapi_mcp/server.py", line 257, in _execute_api_tool
response = await self._request(client, method, url, query, headers, body)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/PythonProject/test-fastapi-mcp-server/.venv/lib/python3.11/site-packages/fastapi_mcp/server.py", line 296, in _request
return await client.get(url, params=query, headers=headers)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/PythonProject/test-fastapi-mcp-server/.venv/lib/python3.11/site-packages/httpx/_client.py", line 1768, in get
return await self.request(
^^^^^^^^^^^^^^^^^^^
File "/Users/PythonProject/test-fastapi-mcp-server/.venv/lib/python3.11/site-packages/httpx/_client.py", line 1540, in request
return await self.send(request, auth=auth, follow_redirects=follow_redirects)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/PythonProject/test-fastapi-mcp-server/.venv/lib/python3.11/site-packages/httpx/_client.py", line 1629, in send
response = await self._send_handling_auth(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/PythonProject/test-fastapi-mcp-server/.venv/lib/python3.11/site-packages/httpx/_client.py", line 1657, in _send_handling_auth
response = await self._send_handling_redirects(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/PythonProject/test-fastapi-mcp-server/.venv/lib/python3.11/site-packages/httpx/_client.py", line 1694, in _send_handling_redirects
response = await self._send_single_request(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/PythonProject/test-fastapi-mcp-server/.venv/lib/python3.11/site-packages/httpx/_client.py", line 1730, in _send_single_request
response = await transport.handle_async_request(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/PythonProject/test-fastapi-mcp-server/.venv/lib/python3.11/site-packages/httpx/_transports/default.py", line 393, in handle_async_request
with map_httpcore_exceptions():
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/contextlib.py", line 155, in __exit__
self.gen.throw(typ, value, traceback)
File "/Users/PythonProject/test-fastapi-mcp-server/.venv/lib/python3.11/site-packages/httpx/_transports/default.py", line 118, in map_httpcore_exceptions
raise mapped_exc(message) from exc
httpx.ConnectError: All connection attempts failed
To Reproduce
claude_desktop_config.json
{
"mcpServers": {
"test-fastapi-mcp-server": {
"command": "/Users/xyz/.local/bin/mcp-proxy",
"args": ["http://127.0.0.1:8007/mcp"]
}
}
}
main.py
from fastapi import FastAPI
from fastapi_mcp import FastApiMCP
app = FastAPI()
@app.get("/new/endpoint/", operation_id="new_endpoint")
async def hello_world():
return {"message": "Hello, world!"}
mcp = FastApiMCP(
app,
)
# Mount the MCP server directly to your FastAPI app
mcp.mount()
System Info Mac M1 Max
ps using uvicorn main:mcp --reload --port 8007 to run the server. throughout the README there is not an explanation of how to actually run a fastapi_mcp server.
I encountered the same problem. I modified the parameters in FastApiMCP. Example:
from fastapi import FastAPI
from fastapi_mcp import FastApiMCP
app = FastAPI()
@app.get("/caculate_add", operation_id="caculate_add")
async def caculate_add(param1: float, param2: float):
"""
add two numbers
"""
return f"Result is {param1 + param2}"
mcp = FastApiMCP(
app,
# Optional parameters
name="caculate_add",
description="add two numbers",
base_url="http://localhost:5120",
)
# mcp = FastApiMCP(app)
if __name__ == "__main__":
# Mount the MCP server directly to your FastAPI app
mcp.mount()
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=5120)
You can give it a try.
Hi @aevo98765 , Can you try bridging the communication to Claude Desktop using mcp-remote, like our updated docs: https://github.com/tadata-org/fastapi_mcp/blob/main/docs/02_connecting_to_the_mcp_server.md Let me know that it works for you
@shira-ayal 404 for me. Permissions?
Ps thanks so much for your reply 😄
@aevo98765 yes, we changed the docs. see https://fastapi-mcp.tadata.com/getting-started/quickstart#connecting-to-the-mcp-server-using-mcp-remote