SKILL.md--- name: fastmcp-server description: Complete guide for building MCP servers with FastMCP 3.0 - tools, resources, authentication, providers, middleware, and deployment. Use when creating Python MCP servers or integrating AI models with external tools and data. version: 1.0.0 author: FastMCP Community license: MIT tags: [FastMCP, MCP, Python, AI, Tools, Server, Authentication, Providers] dependencies: [] --- # FastMCP 3.0 Server Development Complete reference for building production-ready MCP (Model Context Protocol) servers with FastMCP 3.0 - the fast, Pythonic framework for connecting LLMs to tools and data. ## When to use this skill **Use FastMCP Server when:** - Creating a new MCP server in Python - Adding tools, resources, or prompts to an MCP server - Implementing authentication (OAuth, OIDC, token verification) - Setting up middleware for logging, rate limiting, or authorization - Configuring providers (local, filesystem, skills, custom) - Building production MCP servers with telemetry and storage - Upgrading from FastMCP 2.x to 3.0 **Key areas covered:** - **Tools & Resources** (CORE): Decorators, validation, return types, templates - **Context & DI** (CORE): MCP context, dependency injection, background tasks - **Authentication** (SECURITY): OAuth, OIDC, token verification, proxy patterns - **Authorization** (SECURITY): Scope-based and role-based access control - **Middleware** (ADVANCED): Request/response pipeline, built-in middleware - **Providers** (ADVANCED): Local, filesystem, skills, and custom providers - **Features** (ADVANCED): Pagination, sampling, storage, OpenTelemetry, versioning ## Quick reference ### Core patterns **Create a server with tools:** ```python from fastmcp import FastMCP mcp = FastMCP("MyServer") @mcp.tool def add(a: int, b: int) -> int: """Add two numbers""" return a + b ``` **Create a resource:** ```python @mcp.resource("data://config") def get_config() -> dict: """Return server configuration""" return {"version": "1.0", "debug": False} ``` **Create a resource template:** ```python @mcp.resource("users://{user_id}/profile") def get_user_profile(user_id: str) -> dict: """Get a user's profile by ID""" return fetch_user(user_id) ``` **Create a prompt:** ```python @mcp.prompt def review_code(code: str, language: str = "python") -> str: """Review code for best practices""" return f"Review this {language} code:\n\n{code}" ``` **Run the server:** ```python if __name__ == "__main__": mcp.run() # Or with transport options: # mcp.run(transport="sse", host="0.0.0.0", port=8000) ``` ### Using context in tools ```python from fastmcp import FastMCP, Context mcp = FastMCP("MyServer") @mcp.tool def process_data(uri: str, ctx: Context) -> str: """Process data with logging and progress""" ctx.info(f"Processing {uri}") ctx.report_progress(0, 100) data = ctx.read_resource(uri) ctx.report_progress(100, 100) return f"Processed: {dat