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:

fastmcp dev your_server.py

Installing in Claude

To use your server with Claude Desktop:

fastmcp install your_server.py --name "My Server"

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.1.0.tar.gz (55.0 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.1.0-py3-none-any.whl (14.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for fastmcp-0.1.0.tar.gz
Algorithm Hash digest
SHA256 5c18220961e717eb8cec30e12c5ebd9f240d4c830dc53a8404752bee777d064b
MD5 fa233c803cdc873fe3dc27325a787004
BLAKE2b-256 71ef351d0f953de706adb89c21f0fac150955eda2eb240196f5dca1c569a5053

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastmcp-0.1.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.1.0-py3-none-any.whl.

File metadata

  • Download URL: fastmcp-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 14.1 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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 55d4af4dcbd6543fd4df45ac6c82b148126f1883772ba66c2d25616ad0305db2
MD5 7771a18566ce9ac3d91287959f60b167
BLAKE2b-256 f507bc69e65b45d638822190bce0defb497a50d240291b8467cb79078d0064b7

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastmcp-0.1.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