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
= FastMCP("Demo Server")
mcp
@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__":
="http", port=8000) mcp.run(transport
Call the MCP Server
import asyncio
from fastmcp import Client
= Client("http://localhost:8000/mcp") # mcp is needed here
client
async def call_tool(city: str):
async with client:
= await client.call_tool("get_weather", {"city": city})
result print(result)
"New York")) asyncio.run(call_tool(
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
= requests.post(
response "http://localhost:8000/mcp/",
={"city": "New York"}
json
)
127.0.0.1:59128 - "POST /mcp/ HTTP/1.1" 406 Not Acceptable` this will get something like `INFO: