Model Context Protocol for Python

FastMCP: The Pythonic Way to Build MCP Servers and Clients

FastMCP is an open-source Python framework for building Model Context Protocol servers, clients and interactive apps. You write ordinary functions, and FastMCP turns them into tools, resources and prompts that language models can call, handling schemas, validation and transport for you.

  • Version 4.2.0
  • Python 3.11+
  • Apache-2.0 licence
Animated diagram: an AI client sends requests through a FastMCP server to tools, resources and prompts FASTMCP AI client LLM host Tools @mcp.tool Resources @mcp.resource Prompts @mcp.prompt server.py from fastmcp import FastMCPmcp = FastMCP("Demo")@mcp.tooldef greet(name: str): return f"Hi {name}" greet() → "Hi Ada"
Overview

What Is FastMCP?

The Model Context Protocol (MCP) is an open standard that lets AI applications reach external tools and data through one consistent interface. Rather than writing a separate integration for every model and every service, you expose capabilities once through an MCP server, and any compatible client can use them.

FastMCP is the Python framework for that work. It began as the high-level API that was incorporated into the official MCP Python SDK in 2024, and it continues as a standalone project maintained by the team at Prefect.

The framework reads your type hints and docstrings to generate the schemas that models need. Validation, error handling and protocol negotiation happen behind the scenes, so the code you maintain stays close to plain Python.

Because the protocol is shared, a server built once works with desktop assistants, IDE integrations and custom agents alike. The same library also includes a client for calling other MCP servers and an apps layer for returning interactive interfaces.

from fastmcp import FastMCP

mcp = FastMCP("Demo")

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

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

Tools

Functions the model can call to take an action or compute a result.

Resources

Read-only data addressed by a URI, such as files, records or settings.

Prompts

Reusable message templates that shape how a model approaches a task.

Features

Key Features of FastMCP

Each feature removes a piece of protocol work, so your effort goes into what the server actually does.

Decorator-Based Components

Add @mcp.tool, @mcp.resource or @mcp.prompt to a function and it becomes an MCP component, with no protocol boilerplate to write. Plain functions remain easy to read and to test.

Automatic Schemas and Validation

Type hints and docstrings become the JSON schemas that models read. Incoming arguments are validated before your function runs, so bad input never reaches your logic.

Flexible Transports

Run locally over STDIO for desktop hosts, or over HTTP for remote clients. Switching between them takes one argument or a single CLI flag.

Built-In Client

Connect to any MCP server from Python, including in-memory connections that make automated tests quick and dependable. It is equally useful in scripts and agents.

Authentication Options

Protect remote servers with JWT verification, token introspection or OAuth providers such as GitHub, Google and Azure, all through one auth parameter.

Interactive Apps

Let tools return forms, tables and charts that render inside the conversation, using the optional apps extra. A local preview command shows them before release.

Installation

How to Install FastMCP

Installation takes a few minutes on Windows, macOS or Linux. The four steps below take you from a clean machine to a running server.

  1. Check Python

    Run python --version and confirm it shows 3.11 or newer. Install a current release first if it does not.

  2. Install the Package

    Run uv add fastmcp in your project, or pip install fastmcp inside a virtual environment.

  3. Verify the Setup

    Run fastmcp version. The output lists the FastMCP, MCP and Python versions with your platform.

  4. Start a Server

    Define a tool in my_server.py, then launch it with fastmcp run my_server.py:mcp.

Quick install commands

Copy the commands for your preferred package manager. Both install the same package from PyPI, together with the fastmcp command-line tool.

If the command is not found after installation, the virtual environment is probably not active. Activate it, or prefix the command with uv run.

# with uv (recommended)
uv add fastmcp

# with pip
pip install fastmcp

# confirm the installation
fastmcp version
Compatibility

System Requirements

FastMCP is a pure Python package, so it runs wherever a supported interpreter runs. There is no compiler to configure and no platform-specific build.

Check the points listed here before installing. They cover the interpreter, the operating system, the package manager and the extras that some features depend on.

If you plan to deploy to production, decide on version pinning at the outset; it saves surprises when a new release arrives. A lockfile created by uv records every dependency, so colleagues and CI servers install exactly the same versions.

  • Python 3.11 or later
    Supported through 3.15, according to the package classifiers.
  • Windows, macOS or Linux
    Any system that runs a supported Python interpreter.
  • uv or pip
    uv is recommended; pip works inside a virtual environment.
  • Optional extras
    tasks, apps, openai, anthropic, gemini and azure, installed only when needed.
  • A pinned version for production
    For example fastmcp==4.2.0, or a lockfile, because minor releases may contain breaking changes.
Download

Download FastMCP Source Code

The archive contains the complete FastMCP repository from its main branch, including the source code, examples, documentation sources and test suite. It is useful for reading the code, working offline or preparing a contribution.

After extracting the archive, the examples folder is a good place to begin, as each file there is a small, runnable server.

Download FastMCP (.zip)

To build servers, pip install fastmcp or uv add fastmcp is quicker and keeps updates simple.

  • Latest release4.2.0
  • FormatZIP archive
  • SourceGitHub, main branch
  • LicenceApache-2.0
  • PlatformsWindows, macOS, Linux
Use Cases

What You Can Build with FastMCP

Most projects start with a single tool and grow from there. These are the patterns that appear most often, and each can begin as a small server of fewer than fifty lines.

Knowledge Assistants

Expose documentation, wikis and policy files as resources so an assistant can answer questions from your own material, with sources it can cite.

Safe Database Access

Offer narrow, parameterised query tools instead of raw database credentials, keeping full control over what a model can read and change.

Developer Tooling

Wrap CI pipelines, issue trackers and deployment scripts so routine engineering tasks can run from a conversation, with the same permissions as the script.

Data Analysis

Return summaries, tables and charts from analytics code, with app tools rendering the results interactively for further exploration.

Wrapping Existing APIs

Put an MCP interface in front of a REST service, or proxy another MCP server, without rewriting the underlying system or its business rules.

Automation Workflows

Combine tools for reports, notifications and file processing that an agent can run in sequence, each step small enough to test on its own.

Guide

FastMCP Guides and Tutorials

Practical, step-by-step articles that take you from installation to a server running in production. Each guide states the commands to run, explains what they do and shows the expected result.

Conclusion

Getting Started with FastMCP

FastMCP removes most of the effort involved in connecting language models to real systems. You describe capabilities as ordinary Python functions, and the framework produces the schemas, validation and transport that the Model Context Protocol requires.

A sensible path is to install the package, build a single tool, test it with the in-memory client and then decide whether it should run locally over STDIO or remotely over HTTP. Authentication and deployment can follow once the server does something useful.

Keep each tool narrow and give it a precise docstring, because that text is what a model reads when deciding whether to call it. Pin the FastMCP version once the server matters to other people, and add tests before you add features.

The guides on this site cover each of those stages in order, with working code at every step.

FAQ

Frequently Asked Questions

Short answers to the questions people ask most often about FastMCP.

FastMCP is used to build Model Context Protocol servers and clients in Python. Developers use it to give AI applications controlled access to functions, data and reusable prompts, without writing protocol code by hand. Typical projects include internal assistants, developer tools and data services.

Yes. FastMCP is open-source software released under the Apache-2.0 licence, which permits commercial and personal use. Managed hosting offered by Prefect is a separate service with its own terms.

The current release requires Python 3.11 or later. Run python --version before installing to confirm that your interpreter meets this requirement.

FastMCP 1.0 was incorporated into the official SDK in 2024. The standalone project has continued since then and adds clients, authentication, deployment tooling, apps and testing utilities. For new projects, the standalone package offers the broader feature set.

Both install the same package. The documentation recommends uv because it is fast and records a lockfile; pip works well inside a virtual environment if you already use it.

Yes. FastMCP is a pure Python package and runs on Windows, macOS and Linux. On Windows, activate your virtual environment in PowerShell before running the fastmcp command.

Desktop applications usually launch the server locally over STDIO using a command you configure. Remote clients connect over HTTP to the server's /mcp endpoint, for example http://localhost:8000/mcp during development.

Yes. Pass a verifier to the server's auth parameter. Options include JWT verification, token introspection and OAuth providers such as GitHub, Google and Azure.

Run pip install --upgrade fastmcp or uv add fastmcp --upgrade. Read the release notes first, because minor releases can include breaking changes, and pin the version in production.

The ZIP download contains the full source repository, which suits reading the code or contributing. For building servers, installing from PyPI is simpler and keeps updates straightforward.