A step-by-step guide to making any REST API with an OpenAPI spec available to LLMs using FastMCP.
https://jsonplaceholder.typicode.com
FastMCP.from_openapi
. This method takes an httpx.AsyncClient
configured for your API and its OpenAPI specification, and automatically converts every endpoint into a callable MCP Tool
.
api_server.py
:
fastmcp.Client
to connect to it and inspect its tools.
api_client.py
:
get_users
, get_user_by_id
) and the result of calling the get_user_by_id
tool, which fetches data from the live JSONPlaceholder API.
Tool
. This ensures maximum compatibility with contemporary LLM clients, many of which only support the tools
part of the MCP specification.
However, for clients that support the full MCP spec, representing GET
requests as Resources
can be more semantically correct and efficient.
FastMCP allows users to customize this behavior using the concept of “route maps”. A RouteMap
is a mapping of an API route to an MCP type. FastMCP checks each API route against your custom maps in order. If a route matches a map, it’s converted to the specified mcp_type
. Any route that doesn’t match your custom maps will fall back to the default behavior (becoming a Tool
).
GET
requests into Resources
and ResourceTemplates
(if they have path parameters):
GET /users/{id}
becomes a ResourceTemplate
.GET /users
becomes a Resource
.POST
, PUT
, etc. endpoints would still become Tools
by default.