The same two tools, given a URL instead of a door slot. This part turns HelloMcp into a small web app, calls it by hand with plain HTTP requests, connects VS Code to it by address, and explains the biggest idea the move uncovers: what the initialize greeting is, the difference between a stateful and a stateless server, and why the newest version of MCP chose stateless.
Part 4 described two transports: stdio, a note slot between two rooms of one house, and Streamable HTTP, a phone number anyone can call. HelloMcp so far uses the note slot. This part gives it a phone number.
Almost nothing about the tools changes. What changes is how the server is started, how it is reached, and one deeper idea that only shows up once requests travel over HTTP: whether the server remembers the caller between requests.
Rather than editing HelloMcp, a second project, HelloMcpHttp, is created next to it, so the two can be compared directly:
| HelloMcp (stdio) | HelloMcpHttp | |
|---|---|---|
| Project type | Console app | Web app |
| Packages | ModelContextProtocol and Microsoft.Extensions.Hosting | ModelContextProtocol.AspNetCore only |
| Transport setup | WithStdioServerTransport() | WithHttpTransport() and app.MapMcp(...) |
| Who starts it | The host, every time | You, once; it keeps running and waits at a URL |
HelloTools.cs | the original | copied without a single change |
Two package changes are worth understanding:
Microsoft.Extensions.Hosting for its host. A web app does not: WebApplication.CreateBuilder already is a host, with dependency injection, logging and configuration built in, plus a web server.ModelContextProtocol.AspNetCore depends on ModelContextProtocol, which depends on ModelContextProtocol.Core. NuGet pulls the whole chain in, as transitive dependencies.From the playground folder:
cd C:\projects\mcp-playground
dotnet new web -n HelloMcpHttp
cd HelloMcpHttp
dotnet add package ModelContextProtocol.AspNetCore --version 2.2.0
Copy-Item ..\HelloMcp\HelloTools.cs .Then Program.cs becomes:
var builder = WebApplication.CreateBuilder(args);
builder.Services
.AddMcpServer() // same as before
.WithHttpTransport() // reachable over HTTP instead of stdin/stdout
.WithToolsFromAssembly(); // same as before: finds HelloTools
var app = builder.Build();
app.MapMcp("/mcp"); // the MCP endpoint lives at /mcp
app.Run("http://localhost:3001"); // listen at this addressCompared with the stdio version, three lines are new:
WithHttpTransport() swaps the door: requests arrive over HTTP rather than standard input.app.MapMcp("/mcp") is ordinary ASP.NET Core routing, the same idea as MapGet or a controller route. It says that MCP requests arrive at the path /mcp.app.Run("http://localhost:3001") starts the web server on port 3001 of this machine.And one line is gone: the logging line that sent everything to standard error. That rule existed because, with stdio, standard output is the message channel. Over HTTP, messages travel in HTTP requests and responses, so writing to the console is harmless again.
Start it:
dotnet runA line like Now listening on: http://localhost:3001 appears, and then the program simply waits. That is the biggest practical difference from stdio: nobody else starts this server. It is already running, like a website, and callers come to it.
Opening http://localhost:3001/mcp in a browser gives 405 Method Not Allowed, with a response header saying Allow: POST. That is expected. A browser sends a GET, and this server only accepts POST: every MCP message is a POST request with a JSON body. (The specification also allows a GET, for a server that wants to push messages to a client on its own, but a server in the default mode of this SDK version does not offer it, for reasons that become clear below.)
As with stdio, the clearest way to see what is happening is to play the host yourself, this time by sending HTTP requests from a second PowerShell window:
$headers = @{ Accept = "application/json, text/event-stream" }
$body = '{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{}}'
(Invoke-WebRequest -Uri http://localhost:3001/mcp -Method Post -ContentType "application/json" -Headers $headers -Body $body -UseBasicParsing).ContentAnd to call a tool:
$body = '{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"say_hello","arguments":{"name":"Sam"}}}'
(Invoke-WebRequest -Uri http://localhost:3001/mcp -Method Post -ContentType "application/json" -Headers $headers -Body $body -UseBasicParsing).ContentThe reply:
event: message
data: {"result":{"content":[{"type":"text","text":"Hello, Sam! This answer came from your own MCP server."}]},"id":2,"jsonrpc":"2.0"}
Three things are worth noticing.
The message is identical to stdio. The data: line is exactly the JSON-RPC from Part 4: a result matched to the request's id. The delivery changed from a door slot to a phone call; the message did not. That is precisely what "transport" means.
The reply has a small wrapper. event: message followed by data: ... is a format called Server-Sent Events (SSE). Streamable HTTP is allowed to send several messages back on one response, for example progress updates followed by a result, so replies can come as a stream of events. The Accept header tells the server that the caller can read either a plain JSON response or such a stream; the specification requires clients to send it.
There was no greeting. In Part 4, the very first message was initialize. Here, the first message went straight to tools/list, and the server answered anyway. That small difference is the most important idea in this part.
initialize is a handshake: the first message of a conversation, in which both sides introduce themselves. In the stdio exercise it went like this:
Client: "I am a client called by-hand, and I speak MCP version 2025-06-18." Server: "I am HelloMcp 1.0. I also speak 2025-06-18, and I offer tools."
After the greeting, both sides remember what was agreed: which protocol version, which capabilities. Every later message in that conversation relies on it. VS Code does the same when it starts a stdio server: its log shows initialize first, then tools/list.
A server that greets once and then remembers the caller for the rest of the conversation is called stateful: it keeps state, a memory of the caller, between requests.
Going "straight to" tools/list, without a greeting, only works with a server that does not need that memory: a stateless server. Each request stands on its own and contains everything needed to answer it; once the reply is sent, the server forgets the request entirely.
A restaurant makes the difference concrete.
Stateful is table service. You sit down, and the waiter learns your name, your table and your allergies once, then remembers them for the whole meal. Every later order relies on that memory. If your waiter goes home halfway through, the next waiter knows nothing about you, and you start over.
Stateless is a takeaway counter. Each order slip says everything needed: what you want, how you want it. Any cashier can serve any slip, and none of them needs to remember you.
| Stateful | Stateless | |
|---|---|---|
| How a conversation starts | initialize first | No greeting needed |
| What the server keeps | A memory of each caller (a session) | Nothing between requests |
| What each request carries | Just the request; the session supplies the rest | Everything needed to answer it |
| Over HTTP | The server issues a session id in a header, and the client must send it on every later request | No session id |
| If that server restarts | The session is lost, and the client must greet again | Nothing is lost |
"The server does not need to remember anything" is the cause. The benefit is what follows from it: any copy of the server can answer any request.
A server that serves many people does not run as a single copy. It runs as several identical copies behind a load balancer, which spreads incoming requests across them, so that it can handle more traffic and survive one copy failing.
Now follow one caller through each design:
That is why the 2026-07-28 revision of the MCP specification removed protocol sessions and the initialize handshake from Streamable HTTP: the information the greeting used to carry, such as the protocol version, now travels inside each request instead, and a new server/discover method lets a client ask a server what it offers. Version 2 of the C# SDK follows suit: an HTTP server built with it is stateless by default, which is why HelloMcpHttp needed no greeting.
Two reasons. First, the messages in Part 4 were written by hand using the older protocol version, 2025-06-18, in which the greeting is required; the SDK supports both and played along. Second, a stdio server is naturally one long conversation with exactly one client, so remembering things costs nothing there. Statelessness matters when there are many callers and many copies, which only happens over HTTP.
A server that forgets the caller after each reply cannot start a conversation on its own. Under the older, stateful design, a tool could pause halfway through and send the client a request of its own, for example asking the user a question, or asking the client's model to generate some text. In stateless mode, the SDK's older methods for this throw an error. The 2026-07-28 revision replaces them with a different pattern, in which the tool returns early saying more input is needed and the client calls again with the answer. For a tool that simply looks data up and returns it, nothing is lost.
With stdio, the VS Code configuration held a command: how to start the server. With HTTP, it holds an address: where to call it.
{
"servers": {
"hello-mcp": {
"type": "stdio",
"command": "dotnet",
"args": ["run", "--project", "${workspaceFolder}/HelloMcp/HelloMcp.csproj", "--verbosity", "quiet"]
},
"hello-mcp-http": {
"type": "http",
"url": "http://localhost:3001/mcp"
}
}
}That one difference, command against url, is the whole stdio-versus-HTTP story in configuration form. VS Code no longer starts anything; it just dials the number. So the server must already be running before VS Code can connect.
Before trying it, stop the stdio server. Both servers offer a tool called say_hello, and with both running the model may call either, which makes it impossible to tell which one answered. Duplicate tool names across servers are worth avoiding in general, for the same reason.
Then, in a new chat in Agent mode, "Say hello to Sam" and "Roll a 20-sided die" behave exactly as they did over stdio. The tools did not change; only the door did.
By default, a new web app logs ASP.NET Core's own messages only at warning level, so incoming requests are silent. In appsettings.Development.json, raising that level makes each request visible:
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Information"
}
}
}After restarting the server, every message from VS Code appears in its terminal as a line beginning Request starting HTTP/1.1 POST http://localhost:3001/mcp. That is the host dialling the number. And the simplest proof that the HTTP server is the one answering: stop it with Ctrl+C, ask again in a new chat, and the tool is gone.
Right now, anything that can reach localhost:3001 can call these tools: PowerShell, a script, any AI host. No sign-in, no token, no check of any kind.
For a server on your own machine, two things limit the damage. app.Run("http://localhost:3001") listens only on localhost, so other machines cannot reach it at all; the specification recommends exactly this for servers running locally. And the specification requires servers to check the Origin header of incoming requests, which protects a local server from being called by a malicious web page open in your browser.
On the internet, neither helps: the whole point of a public server is that others can reach it. It must know who is calling and what they are allowed to see, before any tool runs. That is the subject of the next part.
What is initialize? The greeting at the start of a conversation: the client and server say which protocol version they speak and what they can do. A stateful server remembers that agreement for the rest of the conversation.
What does it mean that the HTTP server went "straight to" tools/list? That the first request skipped the greeting, and the server answered anyway. It could, because it is stateless: each request stands on its own, so there is no conversation to set up first.
What is the difference between stateful and stateless? A stateful server remembers each caller between requests, in a session started by the greeting. A stateless server remembers nothing; each request carries everything needed to answer it.
Why is stateless better? Because the server does not need to remember anything, any copy of it can answer any request. A public server runs as several copies behind a load balancer; stateless copies can be added, restarted or replaced freely, while stateful ones tie each caller to one copy and lose sessions when it restarts.
Why did the stdio exercise use initialize, then? Its messages used an older protocol version that requires the greeting, and a stdio server only ever has one client, so remembering costs nothing there.
Why does the browser show 405? A browser sends a GET; the server accepts only POST, because every MCP message is a POST with a JSON body.
Why doesn't VS Code start the HTTP server? Its configuration holds only an address. An HTTP server is started once, by whoever runs it, and keeps running for any caller.
Can the HTTP server write logs to the console? Yes. The stdout rule applied only to stdio, where standard output carries the messages. Over HTTP, messages travel in HTTP requests and responses.