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 modeFASTMCP_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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
41a7ac4dff38abfb7b695cdddf551908e54ae36f9bd761d49cb1945ccc106f61
|
|
| MD5 |
69b227fa02ec1a219ee1ccbf5f4b6aff
|
|
| BLAKE2b-256 |
df5fc8ef9277767c8f99c01ddf03ba8faa199f7e4fe2138c4bf715b61cc8a56a
|
Provenance
The following attestation bundles were made for fastmcp-0.2.0.tar.gz:
Publisher:
publish.yml on jlowin/fastmcp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastmcp-0.2.0.tar.gz -
Subject digest:
41a7ac4dff38abfb7b695cdddf551908e54ae36f9bd761d49cb1945ccc106f61 - Sigstore transparency entry: 152566372
- Sigstore integration time:
-
Permalink:
jlowin/fastmcp@627cf8a84e9ecb5ab3fc95ae1ce3955663033ec8 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/jlowin
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@627cf8a84e9ecb5ab3fc95ae1ce3955663033ec8 -
Trigger Event:
release
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ba6c53a6e5d7415992f6c0940fb5626c864ca8c2c310abf0e8f0951142aee3d9
|
|
| MD5 |
5435dae246dd27f5dc046615b5820350
|
|
| BLAKE2b-256 |
adfe663d64698289bc54860b54f65984f066e47e690acaa8d7ae88b537092f20
|
Provenance
The following attestation bundles were made for fastmcp-0.2.0-py3-none-any.whl:
Publisher:
publish.yml on jlowin/fastmcp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastmcp-0.2.0-py3-none-any.whl -
Subject digest:
ba6c53a6e5d7415992f6c0940fb5626c864ca8c2c310abf0e8f0951142aee3d9 - Sigstore transparency entry: 152566373
- Sigstore integration time:
-
Permalink:
jlowin/fastmcp@627cf8a84e9ecb5ab3fc95ae1ce3955663033ec8 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/jlowin
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@627cf8a84e9ecb5ab3fc95ae1ce3955663033ec8 -
Trigger Event:
release
-
Statement type: