Every program has an input and an output. The stdio transport is nothing more than a host starting your server as a program and taking over those two channels. This part explains what that means, why one stray Console.WriteLine can break a server, how to talk to your server by hand without any AI at all, and the difference between how a host reaches your server and what your server reaches.
In Part 3 the server's configuration said "type": "stdio", and its code said WithStdioServerTransport(). It is easy to use both without understanding either. This part opens that box. It is short on new code and long on one idea that turns out to explain several gotchas at once.
When any program starts, the operating system hands it three standard channels:
| Channel | Short name | Normally connected to | In C# |
|---|---|---|---|
| Standard input | stdin | your keyboard | Console.ReadLine() |
| Standard output | stdout | your screen | Console.WriteLine() |
| Standard error | stderr | your screen too | Console.Error.WriteLine() |
"Normally" is the important word. Whoever starts a program can connect these channels to something else: a file, or another program. That is what the | pipe in a terminal does, and it is all the stdio transport is. stdio is simply short for standard input and output.
With the stdio transport, the host starts your server as a program and connects its channels to itself instead of to a keyboard and a screen:
Picture two rooms in the same house, passing notes through a slot in the door. The host pushes a request through stdin; your server pushes the reply back through stdout. The messages are lines of JSON, one message per line.
Everything about stdio follows from that picture:
command: VS Code runs dotnet run ... itself, and stops the program when it is done.mcp.json, an env section sets environment variables for the server, and an inputs section can prompt you for values such as passwords and keep them in VS Code's secret storage rather than in the file.Now the two gotchas from Part 3 make sense.
stdout is the note slot. Every line your server writes there is read by the host as an MCP message. A Console.WriteLine("starting up..."), a default logger, or dotnet run printing "Building..." all push junk through the slot, and the host fails to parse it. Depending on the host, the server shows an error, hangs, or silently loses messages.
stderr is a separate channel that the host does not parse as protocol. It is the right place for logs, which is exactly why HelloMcp's Program.cs sends every log level there, and why the VS Code configuration adds --verbosity quiet to dotnet run. VS Code still collects stderr and shows it in the server's Output channel, which is how you could read the server's log in Part 3.
Rule for every stdio server: only MCP messages on stdout. Everything else, from logs to debug prints, goes to stderr.
Because stdio is just text in and text out, you do not need an AI, or even VS Code, to talk to your server. You can type the messages yourself. It is the clearest way to see the protocol with nothing in between.
In a bash shell (Git Bash works on Windows), from the HelloMcp folder after a dotnet build:
{
printf '%s\n' \
'{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18","capabilities":{},"clientInfo":{"name":"by-hand","version":"1.0"}}}' \
'{"jsonrpc":"2.0","method":"notifications/initialized"}' \
'{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"roll_dice","arguments":{"sides":20}}}' \
'{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"roll_dice","arguments":{"sides":500}}}'
sleep 5
} | dotnet bin/Debug/net10.0/HelloMcp.dll 2>/dev/nullThe printf writes four lines into the server's stdin. The sleep 5 keeps stdin open for a few seconds so the server has time to answer before its input closes. And 2>/dev/null throws away stderr, so only the protocol is left on screen. Adjust net10.0 to your project's target framework.
The server replies with one line per request:
{"result":{"protocolVersion":"2025-06-18","capabilities":{"logging":{},"tools":{"listChanged":true}},"serverInfo":{"name":"HelloMcp","version":"1.0.0.0"}},"id":1,"jsonrpc":"2.0"}
{"result":{"content":[{"type":"text","text":"3"}]},"id":2,"jsonrpc":"2.0"}
{"result":{"content":[{"type":"text","text":"An error occurred invoking 'roll_dice': sides must be between 2 and 100."}],"isError":true},"id":3,"jsonrpc":"2.0"}Reading it:
method (what to do), params (its arguments) and an id. The reply carries the same id, so the caller can match answers to questions.notifications/initialized has no id, and gets no reply. In JSON-RPC, a message without an id is a notification: information, not a question.initialize is the greeting: the caller says which protocol version it speaks, and the server answers with its own version, name and capabilities (here, that it has tools).tools/call is step 3 of the agent loop from Part 2, with you playing the host. The 20-sided die landed on 3.McpException becomes on the wire: a normal result with "isError": true and your message as the text. That is what the model reads.server/discover method replaces the greeting. Hosts and SDKs negotiate the version for you, which is why HelloMcp still answered a client that asked for the older version. Writing messages by hand is the one place you see this directly.If you prefer a visual tool to a shell, the official MCP Inspector connects to a server, lists its tools and lets you call them from a web page. It runs with npx and needs a recent Node.js version; its documentation is in this topic's links.
One question clears up the last of the confusion. Imagine a stdio server whose tools call a web API, for example a developer tool that lets an assistant test an API by sending it requests. If the server talks to a web API over HTTPS, how is it a stdio server?
Because there are two separate connections, and "stdio" describes only the first:
"type": "stdio" and WithStdioServerTransport() describe.HttpClient, read and write files, query a database, or anything else a program can do. None of that is MCP.The transport only decides the door the host knocks on. What happens behind the door is entirely up to you.
stdio is a door slot between two rooms in one house. The other standard transport, Streamable HTTP, is a phone number: the server runs as a web server at a URL, and anyone who knows the number can call, from anywhere, at the same time.
| stdio | Streamable HTTP | |
|---|---|---|
| Where the server runs | The same machine as the host | Anywhere, such as a cloud service |
| Who starts it | The host, every time | Nobody; it is always running |
| Who can connect | Only the host that started it | Anyone who can reach the URL |
| How many users | One | Many at once |
| Configuration | "type": "stdio" and a command | "type": "http" and a url |
| In C# | WithStdioServerTransport() | WithHttpTransport() and app.MapMcp() |
| Good for | Personal tools on your own machine | Serving other people |
"Anyone who can reach the URL" is the line that changes everything. A server on the internet needs to know who is calling and what they are allowed to see, which is where the next parts are heading.
One thing does not change: the tools. SayHello and RollDice stay exactly as they are. Moving to HTTP swaps the door, not what is behind it.
The specification also mentions an older "HTTP+SSE" transport. It is deprecated, replaced by Streamable HTTP; if a tutorial uses it, the tutorial is out of date.
What does "stdio" actually mean? Standard input and output: the input and output channels every program has. The stdio transport means the host starts your server and talks to it through those channels instead of a keyboard and screen.
Why can a single Console.WriteLine break a stdio server? Because stdout is the channel the MCP messages travel on. Anything else written there arrives at the host as a broken message. Logs belong on stderr.
A server's tools call a web API over HTTPS. Isn't it an HTTP server then? No. "stdio" describes only how the host reaches your server. What your tools do after that, including calling web APIs, is ordinary code and has nothing to do with the transport.
Can someone else use a stdio server? Not over the network. Only the host that started the program can talk to it. To serve other people, a server needs a transport they can reach, which is Streamable HTTP.
Where do a stdio server's credentials go?
Into its environment, set by the host when it starts the program. VS Code's mcp.json can prompt for secret values and pass them in as environment variables, so they never sit in the file itself.
Does switching to HTTP mean rewriting the tools?
No. The tools stay the same; only the transport setup in Program.cs and the host's configuration change.