FastMCP class is the central piece of every FastMCP application. It acts as the container for your tools, resources, and prompts, managing communication with MCP clients and orchestrating the entire server lifecycle.
Creating a Server
Instantiate a server by providing a name that identifies it in client applications and logs. You can also provide instructions that help clients understand the server’s purpose.FastMCP constructor accepts several configuration options. The most commonly used parameters control server identity, authentication, and component behavior.
FastMCP Constructor Parameters
A human-readable name for your server
Description of how to interact with this server. These instructions help clients understand the server’s purpose and available functionality
Version string for your server. If not provided, defaults to the FastMCP library version
New in version
2.13.0URL to a website with more information about your server. Displayed in client applicationsNew in version
2.13.0List of icon representations for your server. Icons help users visually identify your server in client applications. See Icons for detailed examplesAuthentication provider for securing HTTP-based transports. See Authentication for configuration options
Server-level setup and teardown logic. See Lifespans for composable lifespans
A list of tools (or functions to convert to tools) to add to the server. In some cases, providing tools programmatically may be more convenient than using the
@mcp.tool decoratorOnly expose components with at least one matching tag
Hide components with any matching tag
How to handle duplicate tool registrations
How to handle duplicate resource registrations
How to handle duplicate prompt registrations
New in version
2.13.0Controls how tool input parameters are validated. When False (default), FastMCP uses Pydantic’s flexible validation that coerces compatible inputs (e.g., "10" to 10 for int parameters). When True, uses the MCP SDK’s JSON Schema validation to validate inputs against the exact schema before passing them to your function, rejecting any type mismatches. The default mode improves compatibility with LLM clients while maintaining type safety. See Input Validation Modes for detailsNew in version
3.0.0Maximum number of items per page for list operations (tools/list, resources/list, etc.). When None (default), all results are returned in a single response. When set, responses are paginated and include a nextCursor for fetching additional pages. See Pagination for detailsComponents
FastMCP servers expose three types of components to clients. Each type serves a distinct purpose in the MCP protocol.Tools
Tools are functions that clients can invoke to perform actions or access external systems. They’re the primary way clients interact with your server’s capabilities.Resources
Resources expose data that clients can read. Unlike tools, resources are passive data sources that clients pull from rather than invoke.Resource Templates
Resource templates are parameterized resources. The client provides values for template parameters in the URI, and the server returns data specific to those parameters.Prompts
Prompts are reusable message templates that guide LLM interactions. They help establish consistent patterns for how clients should frame requests.Tag-Based Filtering
New in version2.8.0
Tags let you categorize components and selectively expose them based on configurable include/exclude sets. This is useful for creating different views of your server for different environments or user types.
Components can be tagged when defined using the tags parameter. A component can have multiple tags, and filtering operates on tag membership.
- Include tags: If specified, only components with at least one matching tag are exposed
- Exclude tags: Components with any matching tag are filtered out
- Precedence: Exclude tags always take priority over include tags
Running the Server
FastMCP servers communicate with clients through transport mechanisms. Start your server by callingmcp.run(), typically within an if __name__ == "__main__": block. This pattern ensures compatibility with various MCP clients.
- STDIO (default): For local integrations and CLI tools
- HTTP: For web services using the Streamable HTTP protocol
- SSE: Legacy web transport (deprecated)
Custom Routes
When running with HTTP transport, you can add custom web routes alongside your MCP endpoint using the@custom_route decorator. This is useful for auxiliary endpoints like health checks.
- Health check endpoints for monitoring
- Simple status or info endpoints
- Basic webhooks or callbacks

