MCP · Lesson 65 of 120
stdio in Depth
Stdin, stdout, stderr.
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.

- 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.
- stdin: JSON requests in
- stdout: JSON replies only
- stderr: your logs
- 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.
| key | value |
|---|---|
| Started | by the host |
| Runs | while connected |
| Exits | when closed |
| Copies | one 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