MCP ConfigsMar 30, 2026·2 min read

FastMCP — Build MCP Servers in Python, Fast

The fast, Pythonic way to build MCP servers and clients. Clean decorator API, automatic type validation, built-in testing, and OpenAPI integration. 24K+ GitHub stars.

TL;DR
FastMCP provides a clean Python decorator API for building MCP servers with automatic type validation and built-in testing.
§01

What it is

FastMCP is a Python framework for building MCP (Model Context Protocol) servers quickly. It provides a decorator-based API similar to FastAPI: you define functions with type hints, decorate them with @mcp.tool(), and FastMCP handles protocol compliance, input validation, and server lifecycle. It also includes a client library for testing and connecting to other MCP servers.

FastMCP targets Python developers who want to expose their code as MCP tools for AI assistants like Claude Code, Cursor, or any MCP-compatible client.

§02

How it saves time or tokens

Building an MCP server from scratch requires implementing the JSON-RPC protocol, handling tool listing, input validation, and error formatting. FastMCP abstracts all of this. You write a Python function, add a decorator, and get a compliant MCP server. The automatic type validation from Python type hints means fewer runtime errors. Built-in testing tools let you verify your server without connecting a real client.

§03

How to use

  1. Install FastMCP:
pip install fastmcp
  1. Create a server:
from fastmcp import FastMCP

mcp = FastMCP('My Server')

@mcp.tool()
def add(a: int, b: int) -> int:
    '''Add two numbers.'''
    return a + b

mcp.run()
  1. Connect your MCP client to the server.
§04

Example

from fastmcp import FastMCP
import httpx

mcp = FastMCP('Web Scraper')

@mcp.tool()
async def fetch_page(url: str) -> str:
    '''Fetch a web page and return its text content.'''
    async with httpx.AsyncClient() as client:
        response = await client.get(url)
        return response.text

@mcp.tool()
def count_words(text: str) -> int:
    '''Count words in a text string.'''
    return len(text.split())

@mcp.resource('config://app')
def get_config() -> dict:
    '''Return application configuration.'''
    return {'version': '1.0', 'max_pages': 100}

mcp.run()

This creates an MCP server with two tools and one resource, ready for any MCP client.

§05

Related on TokRepo

§06

Common pitfalls

  • FastMCP uses Python type hints for input validation. Missing or incorrect type hints produce unhelpful errors for the calling AI agent. Always annotate parameters and return types.
  • Async tools require an async event loop. If your MCP client connects via stdio, FastMCP handles this. But embedding in an existing async application requires careful loop management.
  • Tool descriptions become the documentation AI agents read. Write clear, specific docstrings because the agent uses them to decide when and how to call your tool.

Frequently Asked Questions

How does FastMCP compare to the official MCP SDK?+

The official MCP Python SDK provides low-level protocol primitives. FastMCP adds a high-level decorator API, automatic validation, and testing utilities on top. Think of it as FastAPI vs raw ASGI -- same protocol, better developer experience.

Does FastMCP support resources and prompts?+

Yes. FastMCP supports all three MCP primitives: tools (functions agents call), resources (data agents read), and prompts (templates agents use). Each has its own decorator.

Can I test FastMCP servers without an AI client?+

Yes. FastMCP includes a built-in test client. You can call tools programmatically in unit tests without connecting Claude or Cursor.

Does FastMCP support OpenAPI integration?+

Yes. FastMCP can import OpenAPI specifications and automatically generate MCP tools from API endpoints. This lets you expose existing REST APIs as MCP tools without writing wrapper code.

What transport protocols does FastMCP support?+

FastMCP supports stdio (standard for local MCP servers) and SSE (Server-Sent Events) for remote connections. The transport is configurable at startup.

Citations (3)
🙏

Source & Thanks

Created by PrefectHQ. Licensed under Apache 2.0. PrefectHQ/fastmcp — 24,000+ GitHub stars

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.