fastmcp-patterns
FastMCP server patterns for building MCP servers. Use when implementing MCP tools, resources, or server configuration.
npx skills add majiayu000/claude-skill-registry --skill fastmcp-patterns --agent claude-code
Same command for any agent — swap --agent for codex, cursor, copilot.
Weekly change comes from our own snapshots, not the repository page — it measures attention, not adoption.
# FastMCP Patterns ## Server Setup with Lifespan ```python from contextlib import asynccontextmanager from mcp.server.fastmcp import FastMCP @asynccontextmanager async def lifespan(server: FastMCP): """Initialize resources on startup, cleanup on shutdown.""" driver = create_neo4j_driver(config) driver.verify_connectivity() try: yield {"driver": driver, "config": config} finally: driver.close() mcp = FastMCP( "requirements-graphrag-mcp", lifespan=lifespan, ) ``` ## Tool Registration ### Basic Tool with Pydantic Validation ```python from pydantic import BaseModel, Field class SearchInput(BaseModel): query: str = Field(..., description="Search query text") limit: int = Field(default=10, ge=1, le=100, description="Max results") @mcp.tool() async def semantic_search(input: SearchInput) -> list[dict]: """Search articles using semantic similarity.""" driver = mcp.state["driver"] return await execute_vector_search(driver, input.query, input.limit) ``` ### Tool with Annotations ```python from mcp.server.fastmcp import Context @mcp.tool( annotations={ "readOnlyHint": True, "openWorldHint": False, } ) async def get_schema(ctx: Context) -> dict: """Get database schema. Read-only operation."""
- Server Setup with Lifespan
- Tool Registration
- Basic Tool with Pydantic Validation
- Tool with Annotations
- Resource Registration
- Error Handling Pattern
- Configuration Pattern
- Entry Point
- pyproject.toml Script
What does the fastmcp-patterns skill do?
FastMCP server patterns for building MCP servers. Use when implementing MCP tools, resources, or server configuration.
How do I install it?
Run `npx skills add majiayu000/claude-skill-registry --skill fastmcp-patterns --agent claude-code` — it drops the skill into your project so the agent can pick it up. Swap the --agent value for codex, cursor or copilot if you use one of those.
Where does this skill come from?
From majiayu000/claude-skill-registry, a repository with 534 stars. We read it straight from the repository tree rather than a submitted listing, so what you see here is what is actually published.
Is a popular skill a good skill?
Not necessarily. Stars measure attention, not adoption — a repository can trend for a week and be abandoned. That is why we show the weekly change from our own snapshots next to the total, instead of a single flattering number.
