Skip to content

Raise an error when calling the external mcp tool in the server tool #3799

@f11st

Description

@f11st

What happened?

When calling a remote MCP server tool from within a local FastMCP server tool, I receive an httpx.HTTPStatusError: 400 Bad Request. However, calling the same remote tool directly using asyncio.run() works perfectly fine.

httpx.HTTPStatusError: Client error '400 Bad Request' for url 'http://[REMOTE_IP]:8080/mcp'
For more information check: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/400

Example Code

import asyncio
import logging

from fastmcp import Client, FastMCP
from fastmcp.client.transports import StreamableHttpTransport

# External MCP server client
transport = StreamableHttpTransport(url="http://[REMOTE_IP]:8080/mcp")
client = Client(transport)


async def remote_tool() -> str:
    """Call remote MCP server tool directly"""
    async with client:
        result = await client.call_tool("weather_tool", {})
        print(result)
        return "test remote_tool"


# Local MCP server
mcp = FastMCP(name="Local Server")


@mcp.tool()
async def local_tool() -> str:
    """Local tool that attempts to call remote tool"""
    try:
        r = await remote_tool()
        print(r)
    except Exception as e:
        logging.exception("call exception")
    return "done"


async def run_http_server():
    """Run local MCP server"""
    await mcp.run_async(
        transport="http", 
        show_banner=False, 
        host="0.0.0.0", 
        port=8300
    )


if __name__ == "__main__":
    # This works fine
    asyncio.run(remote_tool())
    
    # This fails with 400 Bad Request when local_tool is called
    asyncio.run(run_http_server())

Version Information

FastMCP version:                                                         3.2.0
MCP version:                                                            1.27.0
Python version:                                                         3.13.5
Platform:                      Linux-6.12.57+deb13-amd64-x86_64-with-glibc2.41
FastMCP root path: /home/xxx/.venv/lib/python3.13/site-packages

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working. Reports of errors, unexpected behavior, or broken functionality.clientRelated to the FastMCP client SDK or client-side functionality.httpRelated to HTTP transport, networking, or web server functionality.serverRelated to FastMCP server implementation or server-side functionality.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions