AI Hints
Home›MCP Tutorial›Clients Quiz and stdio
MCP · Lesson 65 of 120

stdio in Depth

Stdin, stdout, stderr.

⏱ 2 min read▶ Video at 57:45🎓 Free
Watch this lesson in the MCP courseWatch on YouTube ↗Full MCP course

With standard IO, the client starts the server program, and they share three streams. The server reads requests from standard input, writes replies to standard output, and can write anything else to standard error.

stdio in Depth
From the video: stdio in Depth
  • stdin: requests
  • stdout: replies
  • stderr: everything else

The three streams

Standard input carries JSON requests from the client. Standard output carries JSON replies, and nothing else. Standard error is free for logs. Each message is one line of JSON.

  1. stdin: JSON requests in
  2. stdout: JSON replies only
  3. stderr: your logs
  4. One message per line

Lifecycle

The host starts the server when it needs it. The server runs as long as the connection is open. When the host closes the connection, the server should exit. Each host starts its own copy.

keyvalue
Startedby the host
Runswhile connected
Exitswhen closed
Copiesone per host

Summary

Standard input and output carry MCP messages, and standard error is for logs. Next, logging safely.

Key takeaways
  • stdin
  • stdout
  • stderr
Next up: Logging Safely — never print to stdout