FastMCP

Active
GitHub Python Apache-2.0

Description

FastMCP is a fast, Pythonic library for building MCP servers and clients with over 1 million daily downloads, making it easy to create Model Context Protocol tools.

Key Features

  • Decorator-Based Tools — Create MCP tools with Python functions and @mcp.tool decorator, auto-generating schema and docs
  • MCP Client — Connect to any MCP server (local or remote) with full protocol handshake and session management
  • Interactive Apps — Generate interactive UIs for tools that render directly in conversations
  • Auto Transport Negotiation — Automatically handles connection and auth for SSE, stdio, and other transports
  • Type-Safe Validation — Auto-generates parameter validation and error handling from Python type annotations
  • Production-Grade Deployment — Integrates with Prefect Horizon for SSO, RBAC, audit logs, and observability

Use Cases

💡 Quickly wrapping Python functions as MCP tools for LLMs to call
💡 Building MCP servers exposing database queries, file operations to AI agents
💡 Connecting to existing tool servers via MCP client to add AI capabilities to applications
💡 Creating interactive MCP apps with Web UIs for internal toolchains
💡 Securely deploying and managing multiple MCP servers in production environments

Categories

Quick Start

uv pip install fastmcp

from fastmcp import FastMCP

mcp = FastMCP("Demo")

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

@mcp.tool
def search_files(query: str) -> str:
    """Search for files matching a query"""
    import subprocess
    result = subprocess.run(["find", ".", "-name", query], capture_output=True, text=True)
    return result.stdout

if __name__ == "__main__":
    mcp.run()

Related Projects

Related Articles