FastMCP HTTP Transport: Calling MCP Servers Over HTTP
mcp
http
fastmcp
FastMCP provides an HTTP transport layer for Model Context Protocol (MCP) servers, but requires a proper MCP client to communicate. This post demonstrates the correct way to call an MCP server over HTTP using FastMCP.
What is FastMCP HTTP Transport?
FastMCP’s HTTP transport exposes MCP servers over HTTP, but maintains the MCP protocol requirements. Unlike REST APIs, you cannot use regular HTTP requests - you need an MCP-compatible client to handle the protocol properly.
Basic HTTP Server Setup
from fastmcp import FastMCP
mcp = FastMCP("Demo Server")
@mcp.tool()
def get_weather(city: str) -> str:
"""Get weather information for a city."""
return f"The weather in {city} is sunny and 72°F"
if __name__ == "__main__":
mcp.run(transport="http", port=8000)Call the MCP Server
import asyncio
from fastmcp import Client
client = Client("http://localhost:8000/mcp") # mcp is needed here
async def call_tool(city: str):
async with client:
result = await client.call_tool("get_weather", {"city": city})
print(result)
asyncio.run(call_tool("New York"))
Note
We need a FastMCP client or any LLM client that supports the MCP protocol to call the MCP server
https://gofastmcp.com/getting-started/quickstart#call-your-server
The regular POST request won’t work
import requests
# Call the tool via regular HTTP
response = requests.post(
"http://localhost:8000/mcp/",
json={"city": "New York"}
)
this will get something like `INFO: 127.0.0.1:59128 - "POST /mcp/ HTTP/1.1" 406 Not Acceptable`