#5326·fastmcp

ASGIServer.http_client() resolves relative URLs under the MCP path, so custom routes are unreachable

Author: asasemahmedCreated Sep 28, 2026Updated Sep 28, 2026
Labelsbugtests

What happened?

The httpx2.AsyncClient returned by asgi_server(...).http_client() uses the MCP endpoint URL as its base. A relative request like get("/health") goes to /mcp/health and returns 404, even though the custom route is served at /health. The docstring's own example, client.get(f"{server.url}/health"), hits the same wrong path.

Example Code

python
import asyncio

from starlette.responses import PlainTextResponse

from fastmcp import FastMCP
from fastmcp.utilities.tests import asgi_server

mcp = FastMCP("demo")


@mcp.custom_route("/health", methods=["GET"])
async def health(request):
    return PlainTextResponse("OK")


async def main():
    async with asgi_server(mcp) as server:
        async with server.http_client() as http:
            for url in ["/health", f"{server.url}/health", "http://127.0.0.1/health"]:
                r = await http.get(url)
                print(url, "->", r.request.url, r.status_code)


asyncio.run(main())

Output:

/health -> http://127.0.0.1/mcp/health 404
http://127.0.0.1/mcp/health -> http://127.0.0.1/mcp/health 404
http://127.0.0.1/health -> http://127.0.0.1/health 200

Version Information

FastMCP version:                                          4.0.11.dev11+89b00b7f
MCP version:                                                              2.0.0
Python version:                                                         3.12.14
Platform:                                             Windows-11-10.0.26200-SP0