Home / MCP / FastMCP MCP Server
Provides a production-ready framework to build MCP servers and clients with tools, resources, prompts, and enterprise authentication.
Configuration
View docs{
"mcpServers": {
"example_http_server": {
"url": "https://mcp.example.com/mcp"
}
}
}FastMCP is a production-ready framework for building MCP servers and clients. It provides a Pythonic interface to expose data (Resources), actions (Tools), and templates (Prompts) to large language models, with enterprise authentication, deployment options, and testing utilities to take you from idea to production.
You build an MCP server by creating a FastMCP instance and decorating Python functions as Tools, Resources, or Prompts. Run the server locally to expose its endpoints to your MCP client. Use the client to discover available tools, call them, and read resources. Tools perform actions or computations, Resources provide read-only data, and Prompts guide LLM interactions. You can also compose multiple servers, proxy calls, or generate API bindings from OpenAPI or FastAPI apps.
Prerequisites: you should have Python 3.10 or newer installed on your system.
Install FastMCP using the production-ready method provided in the setup notes.
uv pip install fastmcpThis server framework centers on the FastMCP core concepts: the FastMCP server object, Tools, Resources, Prompts, and Context. You define tools with @mcp.tool, resources with @mcp.resource(...), and prompts with @mcp.prompt. The server can be run with different transports, including STDIO, HTTP, and SSE. OpenAPI and FastAPI generation enable a rapid connection between your existing web APIs and the MCP ecosystem. Enterprise authentication is supported out of the box, including Google, GitHub, Azure, Auth0, WorkOS, and more.
Running the server is done by calling the serverโs run method or by using the provided CLI. For development, you typically run the server script directly; for production, you can deploy to a cloud host or self-host using HTTP or SSE transports.
from fastmcp import FastMCP
mcp = FastMCP("Demo MCP Server")
@mcp.tool
def add(a: int, b: int) -> int:
"""Add two numbers"""
return a + b
if __name__ == "__main__":
mcp.run()FastMCP supports three transport protocols. STDIO is the default for local tools and scripts. Streamable HTTP is ideal for web deployments. SSE is compatible with existing SSE clients. To run with STDIO, you can rely on the default setup. For HTTP, you can specify host, port, and path. For SSE, you can enable server-sent events transport.
Example startup flow from development to production involves running the server locally first, then deploying to a cloud or self-hosted environment as needed.
Interact with an MCP server from a client by connecting through a suitable transport (stdio, SSE, or in-memory). List available tools, call specific tools with parameters, and access resources through the client.Create a client instance, connect to your server, and perform operations just like you would with any APIโonly adapted for MCP patterns.
Adds two integers and returns the sum. Uses type hints to define input and output types.
Multiplies two numbers and returns the product. Demonstrates a simple arithmetic Tool.