Server

Start an example MCP server that uses the Streamable HTTP transport.

server.py
"""Start an example MCP server that uses the Streamable HTTP transport."""

from mcp.server.fastmcp import FastMCP

# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------


mcp = FastMCP("calendar_assistant")


@mcp.tool()
def get_events(day: str) -> str:
    return f"There are no events scheduled for {day}."


@mcp.tool()
def get_birthdays_this_week() -> str:
    return "It is your mom's birthday tomorrow"


# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------

if __name__ == "__main__":
    mcp.run(transport="streamable-http")

Run the Example

Set up your virtual environment

uv venv --python 3.12
source .venv/bin/activate

Install dependencies

uv pip install -U "fastmcp>=4,<5"

Adapt the server to FastMCP 4

Save the source as server.py. Replace its import with:

from fastmcp import FastMCP

Replace the call inside if __name__ == "__main__": with:

mcp.run(transport="streamable-http", port=8000)

The source import targets the older MCP SDK layout. These two tools return fixed demonstration data; they do not connect a calendar account.

Run the example

Start the adapted server.py and leave this terminal running:

python server.py

Full source: cookbook/91_tools/mcp/streamable_http_transport/server.py