[DRAFT] FastMCP
Overview
FastMCP is a lightweight Python framework to build MCP (Model Context Protocol) servers quickly. It simplifies exposing functions, tools, and resources to MCP clients (e.g., Claude Desktop, Cursor with MCP support) with minimal boilerplate.
Why use FastMCP
- Minimal code to define tools/resources.
- Type hints drive argument schemas automatically.
- Async-friendly, works with any HTTP/tcp transport supported by MCP clients.
- Easy local dev: run a script and point your client at the server endpoint.
Install
pip install fastmcp
Quickstart (minimal server)
# server.py
from fastmcp import FastMCP, tool
app = FastMCP("demo-fastmcp")
@tool
def greet(name: str) -> str:
return f"Hello, {name}!"
if __name__ == "__main__":
app.run() # default: localhost:8000
Run:
python server.py
Adding a resource (example: read-only file)
from fastmcp import resource, Resource
from pathlib import Path
@resource("readme")
def readme() -> Resource:
path = Path("README.md")
return Resource.file(path, media_type="text/markdown")
Tool with dependencies / async
import httpx
from fastmcp import tool
@tool
async def fetch_status(url: str) -> int:
async with httpx.AsyncClient(timeout=10) as client:
resp = await client.get(url)
return resp.status_code
Running with custom host/port
python server.py --host 0.0.0.0 --port 8765
Wiring to Claude Desktop (example)
- Open Claude Desktop settings → Model Context Protocol → Add MCP server.
- Type: HTTP
- URL:
http://localhost:8000(or your custom port) - Save, then test the
greettool in a new chat.
Tips
- Keep secrets in environment variables; do not hardcode API keys.
- Return structured data (dict/list) instead of raw strings when possible.
- Use
@tooldocstrings to document parameters; many clients surface this as help text. - Add health checks or lightweight logging to trace calls during development.
References
- FastMCP PyPI: https://pypi.org/project/fastmcp/
- MCP spec: https://modelcontextprotocol.io/
- Claude Desktop MCP docs: https://modelcontextprotocol.io/quickstart/clients/claude