Back to Agentic

Python FastMCP

docs/publishing/guides/py-fastmcp.mdx

8.4.41.7 KB
Original Source

Python's FastMCP is a popular open source MCP server framework for Python.

1. Install the fastmcp package

<Info> **Prerequisite**: Please install [Python](https://www.python.org) before proceeding. </Info> <CodeGroup>
bash
uv add fastmcp
bash
pip install fastmcp
</CodeGroup>

2. Create a FastMCP server

py
from fastmcp import FastMCP

mcp = FastMCP("Demo 🚀")

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

if __name__ == "__main__":
    mcp.run(transport="http", host="127.0.0.1", port=8000, path="/mcp")
<Note> Make sure to run your server with the `transport="http"` option to use the Streamable HTTP transport. </Note>

3. Deploy your MCP server remotely

Deploy your server publicly or use a tool like ngrok to expose it to the internet.

<Warning> Tools like `ngrok` expose your unauthenticated server to the internet. Only run this command in a safe environment if you understand the risks. </Warning>

We recommend deploying your server to a cloud provider like render, platform.sh, porter, or fly.io. Or one of the big boys AWS, GCP, or Azure.

4. Deploy your origin MCP server to Agentic

Now that you have a publicly available MCP server, you can follow the existing MCP server guide to deploy it to Agentic.