Skip to content

Add stdio support for EverythingServer sample (continues #950) - #1880

Open
FengFafa97 wants to merge 13 commits into
modelcontextprotocol:mainfrom
FengFafa97:fix-889-stdio
Open

FengFafa97 wants to merge 13 commits into
modelcontextprotocol:mainfrom
FengFafa97:fix-889-stdio

Conversation

@FengFafa97

@FengFafa97 FengFafa97 commented Sep 16, 2026 •

Copy link
Copy Markdown

Continues #950, fixes #889.

This picks up @asklar's branch splitting EverythingServer into
EverythingServer.Core / EverythingServer.Http / EverythingServer.Stdio,
rebases it onto current main, and fixes the build breaks that surfaced
from the rebase:

  • EverythingServerExtensions.cs: SampleAsync's named parameter was
    renamed to chatOptions upstream; updated the call site.
  • EverythingServer.Core.csproj: added the MCP9005 suppression
    (Sampling deprecated per SEP-2577) that EverythingServer.Http.csproj
    already had — it doesn't propagate across the project reference.
  • EverythingServer.Http/Program.cs: restored the MCPEXP002 pragma
    around the experimental RunSessionHandler assignment, matching the
    original Program.cs and docs/experimental.md.
  • launchSettings.json: removed trailing commas that broke JSON parsing
    and silently disabled both launch profiles.

Verification:

  • dotnet build: 0 warnings, 0 errors.
  • Manually ran both samples and completed a live MCP initialize
    handshake against each (stdio via piped JSON-RPC, HTTP via a direct
    POST to the Streamable HTTP endpoint).

Out of scope for this PR: main's Program.cs also gained new
sample content since @asklar's branch was cut (icon/ServerInfo metadata
showcase, explicit stateful SessionMode). Not ported here to keep this
PR focused on restoring a green build; happy to follow up separately.

Co-Authored-By: Claude Sonnet 5

Copilot AI and others added 6 commits November 7, 2025 18:26
Co-authored-by: asklar <22989529+asklar@users.noreply.github.com>
Co-authored-by: asklar <22989529+asklar@users.noreply.github.com>
- EverythingServerExtensions.cs: SampleAsync's named parameter was
  renamed to chatOptions upstream; update the call site.
- EverythingServer.Core.csproj: suppress MCP9005 (Sampling deprecated
  per SEP-2577), matching the sibling EverythingServer.Http.csproj.
- EverythingServer.Http/Program.cs: suppress MCPEXP002 around the
  experimental RunSessionHandler assignment, matching the original
  Program.cs and docs/experimental.md.
- launchSettings.json: remove trailing commas that broke JSON parsing
  and silently disabled both launch profiles.

Verified: dotnet build succeeds with 0 warnings/errors, and both
transports complete a live MCP initialize handshake (stdio and
Streamable HTTP).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@FengFafa97

Copy link
Copy Markdown
Author

Hi @jeffhandley — an update on #950: This PR has been rebased onto the current main branch, conflicts have been resolved, and local builds are passing (both stdio and HTTP examples successfully complete the initial handshake). The PR's CI workflow is currently awaiting maintainer approval—could someone please take a look when convenient? I am happy to adjust the scope of work or hand it over if the team prefers to take it from here.

@FengFafa97

Copy link
Copy Markdown
Author

Hi @halter73 and @jeffhandley — this part is ready for review. This is the version @asklar split off from #950 and rebased onto the current main branch; my own changes are included in commit 5a080c1 (affecting 4 files, +8/−3), primarily fixing build failures caused by the rebase. The branch is synced with main, dotnet build succeeds, the local test suite passes, and both stdio and HTTP samples complete the initial handshake successfully. The associated workflows are currently awaiting approval. I am happy to adjust the scope as needed, or to hand over the work if you would prefer to take it from here.

@FengFafa97

Copy link
Copy Markdown
Author

@tarekgh — apologies for the extra ping. Since #950 mentioned the team might take this forward, could you let me know whether this PR is still wanted, or whether #889 is planned differently? Happy to rework it or close it either way.

@tarekgh

tarekgh commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

Thanks for checking in and following up, @FengFafa97, and for picking up this work and resolving the rebase issues.

The Core/HTTP/Stdio split matches the previously discussed direction, and I recommend keeping this PR moving forward. Specifically:

  • Keep shared handlers in Core and transport-specific setup in the HTTP and Stdio projects. Keep dnx and MCPB packaging out of scope.
  • Carry forward the existing server identity/icons and Echo tool icons from current main, rather than dropping those demonstrations during the restructuring.
  • Make the HTTP protocol behavior explicit. If this remains a behavior-preserving restructuring, retain the current stateful configuration and document that its session-dependent demonstrations use older protocol revisions. If native 2026-07-28 support is included, adapt the relevant handlers to MRTR and subscriptions/listen; changing the HTTP session mode alone is not sufficient.
  • Validate both transports beyond the initialization handshake, especially sampling, resource subscriptions, notification delivery, and clean shutdown, covering the protocol versions the sample intends to support.

Since the protocol has evolved since the original proposal, @jeffhandley and @halter73, please confirm whether this PR should preserve the existing sample behavior only, or also update the HTTP sample for native 2026-07-28 support. Either approach is reasonable, but we should agree on the scope before asking for further changes.

Once this PR is completed and merged, we can close #950 as superseded.

FengFafa97 and others added 5 commits November 22, 2026 03:31
…om main

- Core: move the ServerInfo (name/title/description/website/icons) and the
  multi-icon EchoTool registration from main's Program.cs into
  AddEverythingMcpHandlers so both the HTTP and stdio hosts expose them.
- Http: restore SessionMode = Stateful (and its explanatory comment). The
  default is now Stateless, so without it sampling, resource subscriptions
  and RunSessionHandler silently lost their session.
- Core: SubscriptionMessageSender sent "notifications/resource/updated";
  the spec method is "notifications/resources/updated", so clients never
  received resource update notifications. Use
  NotificationMethods.ResourceUpdatedNotification.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@FengFafa97

FengFafa97 commented Nov 22, 2026 •

Copy link
Copy Markdown
Author

Thanks @tarekgh for the detailed review. I've pushed 91d1b4c (plus a merge of current main) addressing points 1, 2 and 4:

  • Point 1 — unchanged: shared handlers stay in Core, transport-specific setup in Http/Stdio; dnx and MCPB packaging remain out of scope.
  • Point 2 — the ServerInfo (title/description/website/icons) and the multi-icon EchoTool registration from main now live in Core's AddEverythingMcpHandlers, so both the HTTP and stdio hosts expose them.
  • Point 4 — validated both transports beyond the handshake with a throwaway client built against this branch's SDK (sampling handler returns a canned reply):
Check stdio, 2025-11-25 stdio, 2026-07-28 (client default) HTTP, 2025-11-25 HTTP, client default (negotiates 2025-11-25)
serverInfo + icons, echo tool icons ✅ ✅ ✅ ✅
Sampling (sampleLLM tool) ✅ ✅ ✅ ✅
resources/subscribe → notifications/resources/updated (+ sampling from the subscribe handler) ✅ ❌ rejected¹ ✅ ✅
logging/setLevel → notifications/message ✅ ❌ rejected¹ ✅ ✅
Clean shutdown² ✅ ✅ ✅ ✅

¹ The server rejects resources/subscribe ("use subscriptions/listen with resourceSubscriptions") and logging/setLevel ("use the per-request _meta/io.modelcontextprotocol/logLevel field") on 2026-07-28.
² stdio: the server process exits within ~100 ms of stdin closing. HTTP: client dispose sends DELETE, and a later request with the old Mcp-Session-Id gets 404. (With the OTLP exporter enabled and no collector listening, stdio shutdown waits ~5 s for the exporter flush; that's the same UseOtlpExporter setup as main, so I left it alone.)

Two fixes came out of the validation:

  • The split had dropped SessionMode = HttpServerSessionMode.Stateful from the HTTP host. Since the default is now Stateless, sampling, subscriptions and RunSessionHandler lost their session. I restored main's setting and comment as-is; this only preserves current behavior and doesn't decide point 3.
  • SubscriptionMessageSender sent notifications/resource/updated (singular, also on main), so clients never received resource updates. It now uses NotificationMethods.ResourceUpdatedNotification.

On point 3, @jeffhandley @halter73: should this PR only preserve the existing behavior (stateful HTTP, with a note that the session-dependent demonstrations target 2025-11-25 and earlier), or also add native 2026-07-28 support (MRTR + subscriptions/listen)? The stdio column above shows the second option would touch the stdio host as well. I'm happy to go either way once you've decided.

Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com

@tarekgh

tarekgh commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

A few remaining items before this is ready:

  • I recommend keeping this PR behavior-preserving and documenting the protocol versions and limitations in both sample READMEs. The reported validation shows the legacy subscription and logging methods are rejected by a 2026-07-28 stdio client. Native support should be a separate scope unless this PR also implements the required MRTR, subscriptions/listen, and logging changes.
  • Please add automated coverage for the key behaviors currently checked manually, especially sampling and subscription notification flows. This will make the transport split less likely to regress.
  • Please update the PR description. It still says the ServerInfo/icons and stateful HTTP configuration were not ported, although the latest commit includes them. The verification section also describes only initialization handshakes, while the latest validation comment reports additional checks and protocol limitations.

.WithTracing(b => b.AddSource("*").AddHttpClientInstrumentation().SetResourceBuilder(resource))
.WithMetrics(b => b.AddMeter("*").AddHttpClientInstrumentation().SetResourceBuilder(resource))
.WithLogging(b => b.SetResourceBuilder(resource))
.UseOtlpExporter();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could the OTLP exporter be opt-in, or could the README explain that a collector is expected? The PR author reports that stdio shutdown takes about five seconds when no collector is listening, while the exporter flushes. That can be surprising for a stdio server whose host expects prompt process termination.

{
sessionSubscriptions.TryAdd(uri, 0);

await ctx.Server.SampleAsync([

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could the subscription remain valid when the client does not advertise sampling, or could this code roll back the URI if SampleAsync fails? The URI is added before SampleAsync, which throws when sampling is unsupported. The request then fails, but the subscription remains and the background sender continues notifying it. Since sampling is optional and separate from subscribing, please consider guarding the sample or rolling back on failure.

## Running the Server

```bash
dotnet run --project samples/EverythingServer.Http/EverythingServer.csproj

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This command references EverythingServer.csproj, but the renamed project is EverythingServer.Http.csproj, so it will not run as written. The default-port statement below is stale too: the launch profiles use http://localhost:3001 and https://localhost:7133. Could we update the project paths and port guidance?

@@ -2,7 +2,7 @@
using System.ComponentModel;
using System.Text.Json;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we avoid returning the entire process environment from this sample tool? It can expose secrets such as access tokens, connection strings, or cloud credentials to any MCP client that can invoke it. This tool predates the split, but the new stdio server makes it available over that transport too. Please consider safe allowlisted or redacted output, or clearly making this tool unsafe and opt-in.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make EverythingServer capable of running either stdio or http

4 participants