MCP Configs2026年3月30日·1 分钟阅读

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.

Agent 就绪

这个资产会安全暂存

这个资产会先安全暂存。复制的指令会要求 Agent 读取暂存文件,并在激活脚本、MCP 配置或全局配置前先确认。

Stage only · 17/100策略:需暂存
Agent 入口
任意 MCP/CLI Agent
类型
Mcp Config
安装
Stage only
信任
信任等级:Established
入口
FastMCP — Build MCP Servers in Python, Fast
安全暂存命令
npx -y tokrepo@latest install a17a107c-c77e-4c3f-ae09-d2fd985eba93 --target codex

先暂存文件;激活前需要读取暂存 README 和安装计划。

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.

常见问题

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.

引用来源 (3)
🙏

来源与感谢

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

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产