Skip to main content
Glama
kshitijkumrawat20

FastAPI MCP Streamable HTTP Starter

FastAPI MCP Streamable HTTP Starter ๐Ÿš€

MCP Spec Python FastAPI License: MIT

A minimal, production-ready starter template for building Model Context Protocol (MCP) servers in Python with FastAPI over Streamable HTTP.

Implements the official MCP Specification version 2025-11-25, handling standard JSON-RPC 2.0 requests:

  • initialize (protocol handshake and capability negotiation)

  • tools/list (dynamic tool discovery)

  • tools/call (tool execution)


โšก Quickstart

1. Clone the repository

git clone https://github.com/kshitijkumrawat20/fastapi-mcp-streamable-http-starter.git
cd fastapi-mcp-streamable-http-starter

2. Install dependencies

Using uv:

uv pip install -r requirements.txt

Or standard pip:

pip install -r requirements.txt

3. Run the MCP server

uvicorn main:app --host 127.0.0.1 --port 8000 --reload

Related MCP server: MCP Server Scaffold

๐Ÿงช Testing with cURL

1. Protocol Handshake (initialize)

curl -X POST http://127.0.0.1:8000/mcp \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "initialize",
    "params": {
      "protocolVersion": "2025-11-25",
      "capabilities": {},
      "clientInfo": {"name": "curl-client", "version": "1.0.0"}
    }
  }'

2. Discover Tools (tools/list)

curl -X POST http://127.0.0.1:8000/mcp \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "id": 2,
    "method": "tools/list"
  }'

3. Execute a Tool (tools/call)

curl -X POST http://127.0.0.1:8000/mcp \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "id": 3,
    "method": "tools/call",
    "params": {
      "name": "echo",
      "arguments": {
        "message": "Hello from MCP Streamable HTTP!"
      }
    }
  }'

๐Ÿ›  Adding Custom Tools

Subclass MCPTool and register it in mcp_server.py:

from mcp_server import MCPTool

class WeatherTool(MCPTool):
    @property
    def name(self) -> str:
        return "get_weather"

    @property
    def description(self) -> str:
        return "Returns current weather for a city."

    @property
    def input_schema(self) -> dict:
        return {
            "type": "object",
            "properties": {
                "city": {"type": "string", "description": "City name"}
            },
            "required": ["city"]
        }

    async def execute(self, arguments: dict) -> dict:
        city = arguments["city"]
        return {"city": city, "temperature": "72ยฐF", "condition": "Sunny"}

# Register in ToolRegistry:
server.registry.register(WeatherTool())

๐Ÿ“„ License

MIT License. Feel free to use this template for your hackathons and production MCP servers!

Related MCP Connectors

Related MCP Servers

  • A
    license
    Not graded
    quality
    D
    maintenance
    A Python template for building Model Context Protocol (MCP) servers that expose tools via JSON-RPC, enabling secure and scalable context and tool invocation for language models.
    MIT
  • A
    license
    B
    quality
    D
    maintenance
    A basic starter project for building Model Context Protocol (MCP) servers that enables standardized interactions between AI systems and various data sources through secure, controlled tool implementations.
    2
    MIT
  • A
    license
    B
    quality
    D
    maintenance
    A template repository for building Model Context Protocol (MCP) servers that enable LLM clients to interact with custom tools and services through standardized JSON-RPC communication.
    3
    MIT
  • A
    license
    Not graded
    quality
    D
    maintenance
    A bare-bones FastMCP server template designed to serve as a starting point for building custom Model Context Protocol servers. It provides a foundational structure for implementing tools over HTTP and includes a built-in health check utility.
    GPL 3.0