MOFAKH.COM
← Back to profile
MCP Servers

stdio, plainly: how a host talks to a local server

Nov 28, 202611 min readWritten

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.

Every program has three channels

When any program starts, the operating system hands it three standard channels:

ChannelShort nameNormally connected toIn C#
Standard inputstdinyour keyboardConsole.ReadLine()
Standard outputstdoutyour screenConsole.WriteLine()
Standard errorstderryour screen tooConsole.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.

The stdio transport

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:

The stdio transport
Host
e.g. VS Code
starts the server
writes requests
reads replies
stdin
Your MCP server
a program on the same machine
reads requests
runs tools
writes replies
replies come back on stdout; logs go to stderr

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:

  • Same machine only. A door slot connects two rooms in one house. The host and the server must run on the same computer.
  • The host starts the server. That is why the configuration contains a command: VS Code runs dotnet run ... itself, and stops the program when it is done.
  • One client. Only the host that started the program holds its channels. Nobody else can reach it.
  • Secrets come in through the environment. A stdio server has no sign-in step; the specification suggests it takes any credentials it needs from its environment. In VS Code's 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.

Why logs must go to stderr

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.

Talk to your server by hand

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:

bash
{
  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/null

The 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:

json
{"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:

  • The messages are JSON-RPC: each request has a 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.
  • The 500-sided die shows what your McpException becomes on the wire: a normal result with "isError": true and your message as the text. That is what the model reads.
Note to self
The greeting is changing. In the 2026-07-28 revision of the specification, the initialize handshake is removed: each request carries its protocol version itself, and a new 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.

Two different connections

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:

Two connections, two different things
Host
VS Code
1: stdio
MCP server
a program on your machine
tool code runs here
2: HTTPS
A web API
anywhere on the internet
  1. Host to server is the MCP transport. This is what "type": "stdio" and WithStdioServerTransport() describe.
  2. Server to anything else is just your code. Once a tool runs, your server is an ordinary C# program: it can call web APIs with an 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.

A preview of the other transport

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.

stdioStreamable HTTP
Where the server runsThe same machine as the hostAnywhere, such as a cloud service
Who starts itThe host, every timeNobody; it is always running
Who can connectOnly the host that started itAnyone who can reach the URL
How many usersOneMany at once
Configuration"type": "stdio" and a command"type": "http" and a url
In C#WithStdioServerTransport()WithHttpTransport() and app.MapMcp()
Good forPersonal tools on your own machineServing 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.

Common questions

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.

Sources