Sub topic 2
Moving Messages: stdio, Streamable HTTP, and MCP Capabilities
Assume you know basic Python, JSON, client-server communication, and LLM tool calling. MCP uses JSON-RPC messages, but the transport determines how those messages move between a client and server.
stdio and Streamable HTTP
stdio connects a client to a local server subprocess through standard input and output. It is simple and isolates each server process. The server must write protocol messages to stdout and diagnostics to stderr.
Streamable HTTP connects clients to a server through HTTP. It fits remote, shared, or deployed services and supports streaming responses. It also requires HTTP authentication, authorization, and deployment management.
Tools, resources, and prompts
A tool is an operation the model may request, such as searching an issue tracker or adding two numbers. The server performs the operation and returns structured content.
A resource is read-only context that the application can retrieve, such as a file, schema, or database record. The application usually decides when to read it.
A prompt is a reusable message template that the user or application selects. The server supplies the template, but the user controls when to use it.
| Capability | Main controller | Typical use |
|---|---|---|
| Tool | Model through the client | Perform an action |
| Resource | Application or user | Read context |
| Prompt | User or application | Start a guided request |
Minimal server and client
The official Python SDK maps Python functions to MCP capabilities. This server exposes one tool and communicates over stdio:
# server.py
from mcp.server.fastmcp import FastMCP
mcp = FastMCP("demo")
@mcp.tool()
def add(a: int, b: int) -> int:
"""Add two numbers."""
return a + b
if __name__ == "__main__":
mcp.run(transport="stdio")A client launches the server, initializes the session, then calls the tool:
# client.py
import asyncio
from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client
async def main():
params = StdioServerParameters(command="python", args=["server.py"])
async with stdio_client(params) as (read, write):
async with ClientSession(read, write) as session:
await session.initialize()
result = await session.call_tool("add", {"a": 2, "b": 3})
print(result.content)
asyncio.run(main())The client and server exchange JSON-RPC messages over the subprocess streams. The same MCP capabilities can instead be exposed through Streamable HTTP.
Exercise
Which transport is usually the better default for a local server launched by one desktop host?
Show answer
stdio, because the host can manage the server subprocess without deploying an HTTP service.