Stateless MCP transport

Give each MCP request its own transport without retaining MCP sessions.

Give each MCP request its own transport without retaining MCP sessions.

"""
Serve AgentOS over MCP without session state
============================================

``MCPConfig(stateless=True)`` gives every request its own transport and keeps
nothing between requests, so any replica can answer any request and a
multi-instance deployment needs no session affinity.

The trade is whatever needs a retained session: server-initiated notifications
and SSE resumability. Tool calls do not, so a tool server loses nothing.

Run: python cookbook/05_agent_os/14_mcp/stateless.py
Connect an MCP client to http://localhost:7777/mcp; the responses carry no
     mcp-session-id header
"""

from agno.agent import Agent
from agno.db.sqlite import SqliteDb
from agno.models.openai import OpenAIResponses
from agno.os import AgentOS, MCPConfig

# ---------------------------------------------------------------------------
# Create a stateless MCP-enabled AgentOS
# ---------------------------------------------------------------------------

db = SqliteDb(
    id="mcp-stateless-db",
    db_file="tmp/mcp_stateless.db",
)

stateless_agent = Agent(
    id="stateless-agent",
    name="Stateless Agent",
    model=OpenAIResponses(id="gpt-5.5"),
    db=db,
    instructions="Answer questions clearly and concisely.",
)

agent_os = AgentOS(
    id="mcp-stateless-os",
    description="AgentOS exposed over MCP with no session between requests.",
    db=db,
    agents=[stateless_agent],
    # Leave this off (the default) when the server has to push notifications to a
    # client or resume an interrupted stream, since both need a retained session.
    mcp=MCPConfig(stateless=True),
)
app = agent_os.get_app()

# ---------------------------------------------------------------------------
# Run Stateless AgentOS
# ---------------------------------------------------------------------------

if __name__ == "__main__":
    agent_os.serve(app=app)

Run the example

From a clone of the reviewed Agno source, activate a separate environment and install the runtime and MCP dependencies:

uv venv .venv-mcp
source .venv-mcp/bin/activate
uv pip install -e 'libs/agno[os,mcp,openai]'
export OPENAI_API_KEY="your-openai-api-key"
mkdir -p tmp
python cookbook/05_agent_os/14_mcp/stateless.py

Connect a Streamable HTTP MCP client to http://localhost:7777/mcp. Responses do not establish an mcp-session-id. This configures transport state only: the agent still persists sessions in SQLite. For replicas, use shared application storage and cancellation delivery as needed. Stateless transport does not retain the session needed for resumable SSE or server-initiated notifications.

View the source.