$ show PrefectHQ/fastmcp
FastMCP is a production-oriented Python framework for the Model Context Protocol (MCP). Rather than being a single application, it is a multi-package library stack: `fastmcp_slim` provides the core server/client framework, `fastmcp_remote` bridges remote MCP servers to local stdio, and `fastmcp_tasks` implements SEP-2663 background task execution. The core architecture centers on the `FastMCP` server class, a `Client` class with transport abstraction (stdio, SSE, Streamable HTTP, in-memory), provider-based component registration (local, filesystem, OpenAPI, proxy, skills), composable middleware, transforms, OAuth/OIDC authentication, OpenTelemetry instrumentation, and a CLI for running, installing, deploying, and inspecting servers. Entry points include the `fastmcp` CLI and the Python APIs `FastMCP`, `Client`, `ClientGroup`, `FastMCPApp`, and `TasksExtension`. This is an application framework, not a data/research repository, though it contains information-retrieval components (BM25 and regex tool search), OpenAPI schema conversion machinery, and telemetry utilities that approach data-engineering utility. The codebase demonstrates strong engineering discipline: extensive unit and integration tests, conformance testing against the MCP spec, lazy imports to preserve startup performance, upgrade-guide tests that verify documentation claims, and a transform/middleware system that keeps extensions decoupled from core server logic. External dependencies include the MCP Python SDK, Pydantic, Starlette/ASGI, OpenTelemetry, optional authlib, optional prefab-ui for interactive apps, and an internal `httpx2` fork, which is the most notable maintenance risk in an otherwise current codebase.
The LLM identified 5 files worth highlighting for reuse:
Implements VersionKey, VersionSpec, and dedupe_with_versions for robust semantic-version comparison, intersection, and fallback selection. It is self-contained and directly reusable in any project needing PEP 440-aware version constraints with deterministic tie-breaking.
A TTL-based in-memory token cache with SHA-256 hashing, defensive deep copies, FIFO eviction, and periodic cleanup. It solves a recurring auth/token-caching problem and can be extracted with minimal changes into another Python service.
A BM25 ranking implementation used to search MCP tools by relevance. The algorithm is self-contained and demonstrates non-obvious information-retrieval skill; it can be reused in any tool/procedure discovery layer, not just MCP servers.
A typed middleware base class with dispatch phases and per-method hooks for MCP request handling. It encodes a clean responsibility-chain pattern that is generalizable to any request-processing pipeline requiring ordered, composable middleware.
Provides AuthCheck, require_scopes, require_roles, and restrict_tag helpers plus shortfall aggregation for insufficient-scope challenges. The component is decoupled from MCP internals and reusable for role/scope-based authorization in any Python service.