# fastmcp a high-level python framework for building mcp servers. it aims to simplify development by abstracting protocol details, emphasizing developer experience and type safety. ## philosophy fastmcp is designed to be a fast, simple, and complete solution for mcp development. unlike a low-level sdk, it provides a "pythonic" and declarative way to define mcp servers, handling complex protocol intricacies automatically. it leverages python's type hints and docstrings to generate mcp schemas (for tools, resources, and prompts) automatically. ## basic usage define your mcp server and expose functionality using decorators: ```python from fastmcp import FastMCP, Context # Initialize the MCP server mcp = FastMCP("my-awesome-server", description="A server for managing awesome things.") @mcp.tool() def add_numbers(a: int, b: int) -> int: """Adds two numbers together. :param a: The first number. :param b: The second number. :returns: The sum of the two numbers. """ return a + b @mcp.resource("config://app/settings") def get_app_settings() -> dict: """Retrieves the current application settings.""" return {"debug_mode": True, "log_level": "INFO"} @mcp.prompt def create_summary_prompt(text: str) -> str: """Generates a prompt to summarize the given text.""" return f"please summarize the following document:\n\n{text}" @mcp.tool() async def fetch_external_data(ctx: Context, url: str) -> str: """Fetches data from an external URL. :param ctx: The MCP context for logging. :param url: The URL to fetch. :returns: The content of the URL as a string. """ ctx.info(f"fetching data from {url}") # In a real scenario, this would use an async http client return f"content from {url}" # Run the server if __name__ == "__main__": mcp.run() # Automatically detects and uses STDIO or HTTP transport ``` ## key features & patterns ### decorator-based definitions tools, resources, and prompts are defined using simple python functions decorated with `@mcp.tool`, `@mcp.resource`, and `@mcp.prompt`. fastmcp infers schemas from type hints and docstrings. ### context injection the `Context` object can be injected into tools, resources, or prompts, providing access to mcp session capabilities like logging (`ctx.info()`), sending progress updates (`ctx.session.send_progress()`), and making llm sampling requests (`ctx.session.sample()`) ### flexible transports fastmcp abstracts the underlying transport. servers can run over stdio (for local integration) or streamable http (for remote deployments) with minimal code changes. ### server composition & proxying fastmcp supports advanced patterns like combining multiple mcp servers into a single endpoint or proxying requests to other mcp servers. ### authentication built-in support for various authentication mechanisms, including oauth providers and custom api keys. ### client library provides a `fastmcp.Client` for programmatic interaction with any mcp server, supporting diverse transports and server-initiated llm sampling. ## sources - [github.com/jlowin/fastmcp](https://github.com/jlowin/fastmcp) - fastmcp source code and documentation - [pypi.org/project/fastmcp](https://pypi.org/project/fastmcp/) - fastmcp package on pypi