Concept beginner · 3 min read

What is stdio transport in MCP

Quick answer
stdio transport in MCP (Model Context Protocol) is a communication method that uses standard input/output streams to connect AI agents to external tools or resources. It enables seamless, low-latency interaction by exchanging messages via the process's stdin and stdout, without network overhead.
stdio transport is a communication method in MCP that connects AI agents to tools by exchanging messages through standard input and output streams.

How it works

stdio transport operates by sending and receiving JSON-formatted messages through the standard input (stdin) and standard output (stdout) of a process. This is analogous to two programs talking through a pipe: one writes messages to stdout, and the other reads them from stdin. This direct stream communication avoids network latency and simplifies integration, making it ideal for local or embedded AI agent setups.

Concrete example

Below is a minimal Python example demonstrating an stdio transport server that reads JSON messages from stdin and writes responses to stdout, following the MCP protocol pattern.

python
import sys
import json

for line in sys.stdin:
    try:
        message = json.loads(line)
        # Process the message (echo back here)
        response = {"response": f"Received: {message.get('input', '')}"}
        print(json.dumps(response), flush=True)
    except json.JSONDecodeError:
        continue

When to use it

Use stdio transport in MCP when you need a lightweight, fast, and reliable communication channel between an AI agent and local tools or subprocesses. It is best suited for local deployments, embedded systems, or when network communication is unnecessary or unavailable. Avoid it when you require distributed or remote communication, where network protocols like HTTP or WebSocket are more appropriate.

Key Takeaways

  • stdio transport uses standard input/output streams for direct, low-latency communication in MCP.
  • It is ideal for local AI agent integrations without network overhead.
  • Use stdio transport when embedding AI agents with tools on the same machine or process.
  • Avoid stdio transport for remote or distributed AI tool communication.
Verified 2026-04
Verify ↗