# Python FastMCP()

## What is Python FastMCP ?

Python FastMCP is a high-level, Pythonic framework designed for building MCP (Model Context Protocol) servers and clients easily and efficiently. MCP is a standardized protocol that allows servers to expose data and functionality specifically tailored for interactions with large language models (LLMs). FastMCP handles the complex details of the MCP protocol and server management, letting developers focus on creating tools, resources, and prompts with minimal boilerplate code.

Key features of FastMCP include:

* Creating MCP servers that expose data ("Resources") and functionality ("Tools") to LLMs.
    
* Defining reusable interaction patterns through "Prompts."
    
* Proxying and composing servers for complex applications.
    
* Generating servers from OpenAPI specs or FastAPI objects.
    
* Enterprise authentication options (Google, GitHub, Azure, Auth0, and more).
    
* Deployment tools, client libraries, and testing utilities.
    
* High-level, Pythonic API designed to accelerate development.
    

Typical usage involves decorating Python functions with @mcp.tool to expose them as callable tools in the MCP server environment, making it intuitive for Python developers. FastMCP 2.0 is actively maintained and considered the standard framework for developing production-grade MCP applications.

*Example:*

```plaintext
from fastmcp import FastMCP

# Create an MCP instance with a name
mcp = FastMCP("Demo")

# Define a tool that adds two numbers
@mcp.tool
def add(a: int, b: int) -> int:
    """Add two numbers"""
    return a + b

# Run the MCP server
if __name__ == "__main__":
    mcp.run()
```

This framework is ideal for building servers that integrate with AI applications by providing standardized, secure, and efficient endpoints designed specifically for LLMs.

## Will I also be creating MCP Client with FastMCP?

Yes, with FastMCP, you can also create MCP clients in addition to servers. FastMCP provides a built-in Client class that lets you interact programmatically with any MCP server. This client handles all the connection management and MCP protocol details automatically, allowing deterministic and controlled operations such as calling tools, listing available resources, and sending requests. The client supports various transport mechanisms, including in-memory servers (useful for testing), HTTP servers, and local Python scripts. It is designed for explicit function calls rather than autonomous agent behavior, making it ideal for testing MCP servers and building reliable applications. Example usage of the FastMCP client:

Example:

```plaintext
import asyncio
from fastmcp import Client

async def main():
    # Connect to the MCP server
    async with Client("https://example.com/mcp") as client:
        # List available tools
        tools = await client.list_tools()
        print(f"Available tools: {tools}")

        # Call the "add" tool with arguments
        result = await client.call_tool("add", {"a": 5, "b": 3})

        # The result comes back as structured content
        print(f"Result: {result.content[0].text}")

# Run the async main function
asyncio.run(main())
```

### How it works

* `Client("`[`https://example.com/mcp`](https://example.com/mcp)`")` → Connects to your MCP server (That we created above. You need to give the MCP Server URL along with the port number on which the MCP server is running)
    
* `list_tools()` → Queries the server for all registered tools (like `add`).
    
* `call_tool("add", {"a": 5, "b": 3})` → Calls the `add` tool with arguments `a=5` and `b=3`.
    
* `result.content[0].text` → Extracts the returned text from the tool’s response.
