Server
Start an example MCP server that uses the SSE transport.
"""Start an example MCP server that uses the SSE 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="sse")Run the Example
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activateInstall 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 FastMCPReplace the call inside if __name__ == "__main__": with:
mcp.run(transport="sse", 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.pyFull source: cookbook/91_tools/mcp/sse_transport/server.py