liveBook · Manning

Server-sent events

As explained in AI Agents in Action, Second Edition

Server-Sent Events is an HTTP-based protocol for streaming event updates from a server to a client over a persistent connection.

Server-Sent Events (SSE) is an HTTP-based transport for streaming updates from a server to a client over a persistent connection. In MCP deployments, it connects an agent to a server outside the agent process, unlike STDIO, which uses local process pipes. section 3.1.4 section 3.2.3

Use SSE when the server needs to remain independently accessible:

  • Connect agents to MCP servers running on another machine, container, or cloud resource. section 3.3
  • Share one tool server across multiple agents instead of restricting access to the process that launched it. section 3.1.4 section 3.3.2
  • Choose local STDIO instead when low latency, simple process management, and single-machine access matter more than remote access. section 3.1.4 section 3.3

Run and connect to an SSE MCP server

Start the server externally with `mcp run -t sse 01_claude_mcp_server.py`. Then configure an MCP SSE client with the URL `http://localhost:8000/sse`, rather than a server command and arguments. The agent can keep the same tool-using logic while the transport changes from STDIO to SSE. section 3.3.2 section 3.5

Table 3.1 Differences between STDIO and SSE transports for MCP servers

Name

How it works

When you should use it

STDIO

The client launches the MCP server as a subprocess on the same host and exchanges JSON-RPC 2.0 messages over the process’s stdin/stdout pipes. No networking stack is involved, so the link is low-­latency but strictly one-to-one: only the parent process that spawned the server can talk to it.

  • Local development or quick CLI experiments where you want to keep everything in a single shell session.
  • Command-line tools or scripts that spin up a helper MCP server just for the task at hand (e.g., mcp dev my_server.py).
  • Containers that you run interactively (docker run -it …) and communicate with via stdio to avoid opening ports.
  • Simple process-to-process integrations that don’t need remote access, reverse proxies, or multiclient support.

SSE

The MCP server runs as an HTTP service. Clients post JSON-RPC requests to
/messages, while the server streams responses and notifications back over a long-lived text/event-stream connection (server-sent events), such as /sse. This makes the channel half-duplex (client > server via HTTP POST, server > client via SSE) but fully network ­addressable and capable of serving many clients concurrently.

  • Remote or cloud deployments where tools must be reachable over the network or behind a reverse proxy/load balancer.
  • Browser-based or front-end apps that need real-time streaming (token-by-token LLM output) without WebSocket complexity; SSE works through most firewalls and proxies.

Compare SSE with STDIO by protocol, network involvement, connection scope, and recommended deployment scenarios. section 3.2.3

How AI Agents in Action, Second Edition covers it

How deep it goes
Explains deployment choices and configuration examples, but stops short of detailing the SSE protocol internals.
Examples
Uses MCP server commands, a localhost SSE URL, deployment diagrams, comparison tables, and transport-switching exercises.
What it assumes
Assumes familiarity with MCP servers and agents while demonstrating the transport switch through concrete commands and configuration.
What you can do after
Operate/configure MCP servers over SSE and switch an agent from STDIO using a server URL.
How it connects
Connects HTTP, MCP, agents, remote deployment, STDIO, and client-server transport selection.

Also explained in

Compare how 2 books explain server-sent events →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of AI Agents in Action, Second Edition. The section links point to the parts of the book it draws on.