Skip to main content

A more ergonomic interface for MCP servers

Project description

FastMCP

Note: This is experimental software. The Model Context Protocol itself is only a few days old and the specification is still evolving.

A fast, pythonic way to build Model Context Protocol (MCP) servers.

The Model Context Protocol is an extremely powerful way to give LLMs access to tools and resources. However, building MCP servers can be difficult and cumbersome. FastMCP provides a simple, intuitive interface for creating MCP servers in Python.

Installation

MCP servers require you to use uv as your dependency manager.

Install uv with brew:

brew install uv

(Editor's note: I was unable to get MCP servers working unless uv was installed with brew.)

Install FastMCP:

uv pip install fastmcp

Quick Start

Here's a simple example that exposes your desktop directory as a resource and provides a basic addition tool:

from pathlib import Path
from fastmcp import FastMCP

# Create server
mcp = FastMCP("Demo")

@mcp.resource("dir://desktop")
def desktop() -> list[str]:
    """List the files in the user's desktop"""
    desktop = Path.home() / "Desktop"
    return [str(f) for f in desktop.iterdir()]

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

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

Features

Resources

Resources are data sources that can be accessed by the LLM. They can be files, directories, or any other data source. Resources are defined using the @resource decorator:

@mcp.resource("file://config.json")
def get_config() -> str:
    """Read the config file"""
    return Path("config.json").read_text()

Tools

Tools are functions that can be called by the LLM. They are defined using the @tool decorator:

@mcp.tool()
def calculate(x: int, y: int) -> int:
    """Perform a calculation"""
    return x + y

Development

Running the Dev Inspector

FastMCP includes a development server with the MCP Inspector for testing your server:

# Basic usage
fastmcp dev your_server.py

# Install package in editable mode from current directory
fastmcp dev your_server.py --with-editable .

# Install additional packages
fastmcp dev your_server.py --with pandas --with numpy

# Combine both
fastmcp dev your_server.py --with-editable . --with pandas --with numpy

The --with flag automatically includes fastmcp and any additional packages you specify. The --with-editable flag installs the package from the specified directory in editable mode, which is useful during development.

Installing in Claude

To use your server with Claude Desktop:

# Basic usage
fastmcp install your_server.py --name "My Server"

# Install package in editable mode
fastmcp install your_server.py --with-editable .

# Install additional packages
fastmcp install your_server.py --with pandas --with numpy

# Combine options
fastmcp install your_server.py --with-editable . --with pandas --with numpy

Configuration

FastMCP can be configured via environment variables with the prefix FASTMCP_:

  • FASTMCP_DEBUG: Enable debug mode
  • FASTMCP_LOG_LEVEL: Set logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL)
  • FASTMCP_HOST: HTTP server host (default: 0.0.0.0)
  • FASTMCP_PORT: HTTP server port (default: 8000)

License

Apache 2.0

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fastmcp-0.2.0.tar.gz (57.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fastmcp-0.2.0-py3-none-any.whl (15.8 kB view details)

Uploaded Python 3

File details

Details for the file fastmcp-0.2.0.tar.gz.

File metadata

  • Download URL: fastmcp-0.2.0.tar.gz
  • Upload date:
  • Size: 57.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for fastmcp-0.2.0.tar.gz
Algorithm Hash digest
SHA256 41a7ac4dff38abfb7b695cdddf551908e54ae36f9bd761d49cb1945ccc106f61
MD5 69b227fa02ec1a219ee1ccbf5f4b6aff
BLAKE2b-256 df5fc8ef9277767c8f99c01ddf03ba8faa199f7e4fe2138c4bf715b61cc8a56a

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastmcp-0.2.0.tar.gz:

Publisher: publish.yml on jlowin/fastmcp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fastmcp-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: fastmcp-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 15.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for fastmcp-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ba6c53a6e5d7415992f6c0940fb5626c864ca8c2c310abf0e8f0951142aee3d9
MD5 5435dae246dd27f5dc046615b5820350
BLAKE2b-256 adfe663d64698289bc54860b54f65984f066e47e690acaa8d7ae88b537092f20

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastmcp-0.2.0-py3-none-any.whl:

Publisher: publish.yml on jlowin/fastmcp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page