Skip to content

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

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

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

Conversation

@FengFafa97

@FengFafa97 FengFafa97 commented Sep 16, 2026 •

Copy link
Copy Markdown

Continues #950, fixes #889.

Splits the EverythingServer sample into three projects, picking up @asklar's work from #950:

  • EverythingServer.Core: all shared MCP handlers, registered through AddEverythingMcpHandlers, including the ServerInfo metadata (title, description, website, icons) and the multi-icon echo tool from current main.
  • EverythingServer.Http: ASP.NET Core host. Keeps main's SessionMode = HttpServerSessionMode.Stateful, which sampling and resource subscriptions depend on.
  • EverythingServer.Stdio: generic host using the stdio transport.

dnx and MCPB packaging are out of scope, as discussed in #950.

Changes beyond the split

  • Resource update notifications: SubscriptionMessageSender on main sent notifications/resource/updated (singular), which clients don't recognize. It now uses NotificationMethods.ResourceUpdatedNotification.
  • Subscribe handler: samples only when the client advertises sampling, and records the subscription after sampling, so a failed request no longer leaves behind a subscription that keeps receiving updates.
  • subscriptions/listen on stdio: on 2026-07-28, the SDK's built-in handler acknowledged resourceSubscriptions that never receive updates (related to Route application-sent notifications/resources/updated to matching subscriptions/listen streams #1930). As proposed by @tarekgh in this comment, the stdio host registers WithholdListenResourceSubscriptions, an incoming message filter that removes well-formed resourceSubscriptions from subscriptions/listen requests before the built-in handler sees them, so the SDK still handles the acknowledgement, list-changed grants and cancellation. server/discover still advertises resources.subscribe.
  • printEnv: returns environment variable names only, since values can contain secrets and any connected client can call the tool.
  • Stdio telemetry: the OTLP exporter is enabled only when OTEL_EXPORTER_OTLP_ENDPOINT is set, so the process exits promptly when no collector is running instead of after a ~5 s flush.
  • Rebase fixes to the original branch: SampleAsync's renamed chatOptions parameter, the MCP9005 suppression in EverythingServer.Core.csproj, the MCPEXP002 pragma around RunSessionHandler, and trailing commas in launchSettings.json.

Protocol versions

This PR preserves the existing sample behavior; native 2026-07-28 support (MRTR, subscriptions/listen) is a separate scope. Both READMEs document the limits:

Tests

New tests in tests/ModelContextProtocol.Tests/Samples/ run the sample's handlers over an in-memory stream. EverythingServer.Core targets only net9.0, so, following #1993, its sources are compiled into ModelContextProtocol.Tests (except on net472). The tests are skipped on net9.0, where the test build disables the reflection-based serialization that the sample's tools rely on.

  • EverythingServerListenFilterTests: resource grants are withheld; list-changed notifications are still delivered and notifications/cancelled ends the subscription; malformed resourceSubscriptions are still rejected; legacy resources/subscribe still receives updates.
  • EverythingServerSubscriptionTests: subscribing without sampling capability receives updates on 2024-11-05 through 2025-11-25; resources/subscribe is rejected on 2026-07-28 and records nothing; with sampling, the handler samples once and then records the subscription; when sampling fails, no subscription is left behind.

ModelContextProtocol.Tests passes on net10.0, net9.0 and net8.0.

Verification

All results are from the latest commit (a63e154). dotnet build: 0 warnings, 0 errors. Manual checks with a throwaway client built against this branch (its sampling handler returns a canned reply):

Check stdio, 2025-11-25 stdio, 2026-07-28 HTTP, 2025-11-25¹
serverInfo + icons, echo tool icons ✅ ✅ ✅
Sampling (sampleLLM tool) ✅ ✅ ✅
printEnv lists a probe variable's name but not its value ✅ ✅ ✅
resources/subscribe → notifications/resources/updated ✅ rejected (legacy method) ✅
Subscribe from a client without sampling succeeds and gets updates² ✅ n/a —
Subscribe whose sampling fails leaves no subscription behind² ✅ n/a —
logging/setLevel → notifications/message ✅ rejected (legacy method) ✅
subscriptions/listen with resourceSubscriptions n/a ✅ acknowledged without resourceSubscriptions n/a¹
Clean shutdown ✅ ~45 ms ✅ ~70 ms ✅ DELETE, old session id → 404
No errors in server logs ✅ ✅ ✅

¹ The stateful HTTP server negotiates up to 2025-11-25. A client requesting 2026-07-28 fails at initialize, and the error lists the supported versions (2024-11-05 to 2025-11-25).
² Each case starts its own stdio server process, so the run is stdio-only.

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.

Comment thread samples/EverythingServer.Http/README.md Resolved
@halter73

halter73 commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

I agree with keeping the protocol update separate. Can we avoid acknowledging resource subscriptions that won't receive updates? #1930 tracks the related SDK gap.

@FengFafa97

FengFafa97 commented Dec 2, 2026 •

Copy link
Copy Markdown
Author

Thanks, @halter73. I agree with your assessment. I will ensure that this PR does not alter existing behavior, document the protocol limitations in the README files for each example, and address the other pending review items.

Regarding the issue where confirmation responses are received for resource subscriptions that fail to actually deliver updates: I have investigated this and reproduced the behavior in the latest commit (HEAD) of this PR. This confirmation response originates from the SDK’s built-in subscriptions/listen handler—not from the example code itself—and the issue occurs specifically when using the stdio transport:

  • stdio, version 2026-07-28: WithSubscribeToResourcesHandler sets Resources.Subscribe to true. As long as this flag is enabled, the built-in handler automatically grants all requested resourceSubscriptions. For a subscriptions/listen request targeting test://direct/text/resource, the following confirmation response is received:
{"notifications":{"resourceSubscriptions":["test://direct/text/resource"]},"_meta":{"io.modelcontextprotocol/subscriptionId":8}}

Subsequently, no notifications/resources/updated notifications are received within 12 seconds (even though the sender in the example triggers an update every 5 seconds).

  • HTTP: This is unaffected. In SessionMode = Stateful mode, the server rejects the 2026-07-28 version (the client's error reports that the server supports versions only up to 2025-11-25), meaning the subscriptions/listen request never reaches the server. This will be noted in the README for the HTTP version.

The reason no messages are received over the stdio stream is twofold:

  1. The fan-out mechanism only handles */list_changed (i.e., GrantsListChanged), which prevents resources/updated notifications from reaching the listener stream. This is a missing feature, as noted in Route application-sent notifications/resources/updated to matching subscriptions/listen streams #1930.
  2. In the example, SubscriptionMessageSender only iterates over URIs added by the legacy resources/subscribe handler; since that method is rejected on 2026-07-28, this set of URIs is always empty.

Consequently, the example cannot, on its own, prevent the inclusion of these subscriptions in the acknowledgement—unless the entire listen handler is replaced via WithSubscriptionsListenHandler. However, doing so would require re-implementing the acknowledgement mechanism, filtering logic, list_changed event dispatching, and unsubscription logic. Furthermore, this is not an issue unique to this example: currently, any server that registers a subscription handler on a stateful transport will include this same content in its acknowledgement response.

I see two potential approaches:

  1. Make a minor adjustment to the SDK in this PR: Before Route application-sent notifications/resources/updated to matching subscriptions/listen streams #1930 is merged, modify the built-in handler so that it no longer returns any resourceSubscriptions (adding a comment that points to Route application-sent notifications/resources/updated to matching subscriptions/listen streams #1930), and include a test case to verify that these are indeed absent from the acknowledgement response. server/discover will still advertise resources.subscribe; I can remove it from the modern path as well, if you would like.
  2. Leave the src/ directory as is: Add a note to the README for the stdio example explaining that, for clients based on the 2026-07-28 version, resource subscription acknowledgements will contain this information—though no subsequent updates will follow—and defer the fix to Route application-sent notifications/resources/updated to matching subscriptions/listen streams #1930.

I lean toward the first option, as the changes required are minimal; however, I do not want to expand the scope of this PR—which is focused on the example—without prior confirmation. Which approach do you prefer?

- Subscribe handler: only sample when the client advertises sampling,
  and record the subscription after sampling, so a failed request no
  longer leaves behind a subscription that keeps receiving updates.
- printEnv: return environment variable names only, since values can
  contain secrets and any connected client can call the tool.
- Stdio: enable the OTLP exporter only when OTEL_EXPORTER_OTLP_ENDPOINT
  is set, avoiding a ~5 s flush delay on exit without a collector.
- HTTP README: fix the project path and default ports, and document
  that the stateful server negotiates up to 2025-11-25.
- Stdio README: document the 2026-07-28 limitations for resource
  subscriptions and logging/setLevel, and the OTLP opt-in.
@FengFafa97

Copy link
Copy Markdown
Author

Continues #950, fixes #889.

Splits the EverythingServer sample into three projects, picking up @asklar's work from #950:

  • EverythingServer.Core: all shared MCP handlers, registered through AddEverythingMcpHandlers, including the ServerInfo metadata (title, description, website, icons) and the multi-icon echo tool from current main.
  • EverythingServer.Http: ASP.NET Core host. Keeps main's SessionMode = HttpServerSessionMode.Stateful, which sampling and resource subscriptions depend on.
  • EverythingServer.Stdio: generic host using the stdio transport.

dnx and MCPB packaging are out of scope, as discussed in #950.

Changes beyond the split

  • Resource update notifications: SubscriptionMessageSender on main sent notifications/resource/updated (singular), which clients don't recognize. It now uses NotificationMethods.ResourceUpdatedNotification.
  • Subscribe handler: samples only when the client advertises sampling, and records the subscription after sampling, so a failed request no longer leaves behind a subscription that keeps receiving updates.
  • printEnv: returns environment variable names only, since values can contain secrets and any connected client can call the tool.
  • Stdio telemetry: the OTLP exporter is enabled only when OTEL_EXPORTER_OTLP_ENDPOINT is set, so the process exits promptly when no collector is running instead of after a ~5 s flush.
  • Rebase fixes to the original branch: SampleAsync's renamed chatOptions parameter, the MCP9005 suppression in EverythingServer.Core.csproj, the MCPEXP002 pragma around RunSessionHandler, and trailing commas in launchSettings.json.

Protocol versions

This PR preserves the existing sample behavior; native 2026-07-28 support (MRTR, subscriptions/listen) is a separate scope. Both READMEs document the limits:

  • HTTP: with stateful sessions, the server negotiates up to 2025-11-25 and rejects 2026-07-28.
  • stdio: negotiates 2026-07-28, but resources/subscribe, resources/unsubscribe and logging/setLevel are rejected there, so those demonstrations need 2025-11-25 or earlier.

Open question: on stdio with 2026-07-28, the SDK's built-in subscriptions/listen handler acknowledges resourceSubscriptions that never receive updates (related to #1930). The options are in this comment.

Verification

dotnet build: 0 warnings, 0 errors. Manual checks with a throwaway client built against this branch (its sampling handler returns a canned reply):

Check stdio, 2025-11-25 stdio, 2026-07-28 HTTP, 2025-11-25¹
serverInfo + icons, echo tool icons ✅ ✅ ✅
Sampling (sampleLLM tool) ✅ ✅ ✅
printEnv lists a probe variable's name but not its value ✅ ✅ —
resources/subscribe → notifications/resources/updated ✅ rejected (legacy method) ✅
Subscribe from a client without sampling succeeds and gets updates² ✅ n/a —
Subscribe whose sampling fails leaves no subscription behind² ✅ n/a —
logging/setLevel → notifications/message ✅ rejected (legacy method) ✅
Clean shutdown ✅ ~60 ms ✅ ~90 ms ✅ DELETE, old session id → 404

¹ HTTP results are from the run before the latest commit (35694a2); a re-run is pending.
² Each case starts its own stdio server process, so the run is stdio-only.

Automated coverage for the sampling and subscription flows is not included yet; I'll add it to this PR next.

Co-Authored-By: Claude Sonnet 5

Copilot AI left a comment

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.

🟢 Approval recommended

There are no active review issues blocking approval.

No open issues 🎉

What changed in this PR

Splits the EverythingServer sample into shared handlers and separate HTTP and stdio hosts, addressing #889 and continuing #950.

Changes:

  • Shares tools, prompts, resources, and handlers between both transports.
  • Adds stdio hosting with stderr logging and optional telemetry export, while retaining stateful HTTP hosting.
  • Documents transport compatibility, fixes launch settings, and limits environment output to variable names.
File Description
samples/​EverythingServer/​Tools/​PrintEnvTool.cs Removes the original environment tool.
samples/​EverythingServer/​Program.cs Removes the monolithic host.
samples/​EverythingServer.Stdio/​README.md Documents stdio setup and protocol compatibility.
samples/​EverythingServer.Stdio/​Program.cs Adds stdio hosting and background services.
samples/​EverythingServer.Stdio/​EverythingServer.Stdio.csproj Defines the stdio executable.
samples/​EverythingServer.Http/​README.md Documents HTTP setup and session requirements.
samples/​EverythingServer.Http/​Properties/​launchSettings.json Removes invalid trailing commas.
samples/​EverythingServer.Http/​Program.cs Hosts shared handlers with stateful HTTP sessions.
samples/​EverythingServer.Http/​EverythingServer.Http.csproj References the shared core project.
samples/​EverythingServer.Http/​EverythingServer.http Provides HTTP request examples.
samples/​EverythingServer.Http/​appsettings.json Configures logging and allowed hosts.
samples/​EverythingServer.Http/​appsettings.Development.json Provides development logging settings.
samples/​EverythingServer.Core/​Tools/​TinyImageTool.cs Moves the image tool into the shared namespace.
samples/​EverythingServer.Core/​Tools/​SampleLlmTool.cs Moves the sampling tool into the shared namespace.
samples/​EverythingServer.Core/​Tools/​PrintEnvTool.cs Returns environment names without values.
samples/​EverythingServer.Core/​Tools/​LongRunningTool.cs Shares the progress-reporting tool.
samples/​EverythingServer.Core/​Tools/​EchoTool.cs Shares the echo tool.
samples/​EverythingServer.Core/​Tools/​AnnotatedMessageTool.cs Shares the annotated-message tool.
samples/​EverythingServer.Core/​Tools/​AddTool.cs Shares the addition tool.
samples/​EverythingServer.Core/​SubscriptionMessageSender.cs Shares subscription updates and corrects the notification method.
samples/​EverythingServer.Core/​Resources/​SimpleResourceType.cs Moves resources into the shared namespace.
samples/​EverythingServer.Core/​ResourceGenerator.cs Moves resource generation into the shared namespace.
samples/​EverythingServer.Core/​README.md Documents shared components and registration.
samples/​EverythingServer.Core/​Prompts/​SimplePromptType.cs Shares the simple prompt.
samples/​EverythingServer.Core/​Prompts/​ComplexPromptType.cs Shares the complex prompt and updates imports.
samples/​EverythingServer.Core/​LoggingUpdateMessageSender.cs Shares periodic logging notifications.
samples/​EverythingServer.Core/​EverythingServerExtensions.cs Centralizes metadata, primitives, and request handlers.
samples/​EverythingServer.Core/​EverythingServer.Core.csproj Defines the shared library and sampling-warning suppression.
ModelContextProtocol.slnx Registers the three replacement projects.

Review effort: Balanced

@tarekgh

tarekgh commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Could you add a stdio-only incoming-message filter that removes well-formed notifications.resourceSubscriptions from subscriptions/listen requests before they reach the SDK’s built-in handler? That would let the SDK continue handling acknowledgements, list-change grants, and cancellation, while preventing it from acknowledging resource subscriptions this sample cannot update. Leave malformed requests untouched so normal validation still rejects them. This would avoid changing SDK behavior or affecting the HTTP and legacy resources/subscribe paths.

Please add focused tests to confirm resource grants are withheld, list-change notifications and cancellation still work, malformed requests are rejected, and legacy subscriptions still receive updates. The README should explain the limitation and link to #1930. This approach withholds the grant in the acknowledgement but does not change the server capability. Would you be able to implement this sample-scoped fix?

@tarekgh

tarekgh commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Could you add automated tests for the sampling and subscription flows? In particular, please cover subscribing without sampling capability, a sampling failure leaving no stale subscription, and the expected notification delivery for the supported protocol versions.

Could you also rerun the HTTP validation on the latest commit and update the PR description and verification summary to reflect the current split, protocol limitations, and latest test results? The current PR description still describes the earlier state.

@FengFafa97

Copy link
Copy Markdown
Author

Thanks @tarekgh, this is cleaner than either option in my earlier comment, so yes, I'll implement the stdio-only filter. @halter73, since you raised the acknowledgement issue: this would replace options 1 and 2. Let me know if you'd prefer something else.

How the filter will work:

  • The filter lives in EverythingServer.Core so it can be tested, but only the stdio host registers it (via AddIncomingFilter). The HTTP host and the legacy resources/subscribe path are unaffected.
  • For a subscriptions/listen request whose notifications.resourceSubscriptions is an array of strings, it removes that property and passes the request on. The built-in handler then acknowledges and grants the remaining list-changed notifications as usual, and cancellation stays with the SDK.
  • Any other shape of resourceSubscriptions is passed through unchanged, so the SDK's normal validation still rejects it.
  • server/discover still advertises resources.subscribe. The stdio README will explain that resource subscriptions are not granted on 2026-07-28 and link to Route application-sent notifications/resources/updated to matching subscriptions/listen streams #1930.

Tests:

  • Listen filter: resource grants are withheld from the acknowledgement; list-change notifications are still delivered and cancellation still ends the subscription; malformed requests are still rejected; subscriptions made through legacy resources/subscribe still receive notifications/resources/updated.
  • Sampling and subscriptions: subscribing from a client without sampling capability; a sampling failure leaves no stale subscription; expected notification delivery for each supported protocol version.

There's no test coverage for the C# EverythingServer sample yet (the everything server in ClientIntegrationTestFixture is the Node one), so I'm planning to add these to tests/ModelContextProtocol.Tests with a ProjectReference to EverythingServer.Core, the way TestServerWithHosting is referenced. Does that work, or would you prefer a separate test project?

On the PR description: I posted the updated text as a comment instead of editing the description, sorry about that. I'll move it into the description, rerun the HTTP validation on the latest commit, and add the current verification results there.

FengFafa97 and others added 2 commits December 3, 2026 08:12
On 2026-07-28 the SDK's built-in subscriptions/listen handler acknowledges
every requested resourceSubscriptions URI, but the sample can't deliver
notifications/resources/updated on a listen stream yet (modelcontextprotocol#1930).

- Core: add WithholdListenResourceSubscriptions, an incoming message
  filter that removes well-formed resourceSubscriptions from
  subscriptions/listen requests before the built-in handler runs, so the
  SDK still handles the acknowledgement, list-changed grants and
  cancellation. Malformed values are left for the SDK to reject.
- Stdio: register the filter; HTTP and legacy resources/subscribe are
  unaffected.
- Stdio README: document the limitation and link to modelcontextprotocol#1930.
- Tests: compile EverythingServer.Core into ModelContextProtocol.Tests,
  as modelcontextprotocol#1993 does for SkillsServer, and cover withheld resource grants,
  list-changed delivery and cancellation, malformed requests, and legacy
  subscriptions still receiving updates. The tests are skipped where
  reflection-based serialization is disabled (net9.0), which the
  sample's tools rely on.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Cover the shared resources/subscribe handler with the subscription
tracking the stdio host uses:

- Without sampling capability, subscribing succeeds and the subscription
  receives notifications/resources/updated on every initialize-handshake
  protocol version (2024-11-05 through 2025-11-25).
- On 2026-07-28, resources/subscribe is rejected with MethodNotFound and
  nothing is recorded.
- With sampling, the handler samples once, then records the subscription.
- When sampling fails, the request fails and no subscription is left
  behind.

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

Copy link
Copy Markdown
Author

@tarekgh I've pushed two commits for your two comments and updated the PR description and verification results.

A few things differ from what I described earlier:

  • Test location: I said I'd use a ProjectReference to EverythingServer.Core, but that project only targets net9.0, while ModelContextProtocol.Tests also builds for net8.0 and net472. I followed Align Skills with server primitives and typed request handlers #1993 instead: the Core sources are compiled into ModelContextProtocol.Tests (except on net472), and the tests are under tests/ModelContextProtocol.Tests/Samples/. Happy to move them if you'd prefer a separate project.
  • net9.0: the test build disables reflection-based serialization on that target, and the sample's tools depend on it, so these tests are skipped there. They run on net8.0 and net10.0.
  • HTTP: the HTTP host differs only in how it starts the per-session sender (RunSessionHandler in its top-level Program.cs), so the tests cover the shared handlers and I didn't add an ASP.NET Core test. I reran the HTTP validation manually on the latest commit.

I also checked that each test fails when the behavior it covers is broken, for example without the filter, with the subscription recorded before sampling, or with the old singular notifications/resource/updated method.

Side note, not changed here: the SDK returns -32603 ("An error occurred.") for malformed subscriptions/listen params rather than -32602, because the JsonException from deserializing them isn't mapped to an MCP error. The malformed-request tests only assert that the request is rejected.

Copilot AI left a comment

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.

🟢 Approval recommended

No active review issues were identified for the shared-handler and transport-host split.

No open issues 🎉

Review effort: Balanced

if (context.JsonRpcMessage is JsonRpcRequest { Method: RequestMethods.SubscriptionsListen, Params: JsonObject listenParams } &&
listenParams["notifications"] is JsonObject notifications &&
notifications["resourceSubscriptions"] is JsonArray uris &&
uris.All(uri => uri?.GetValueKind() == JsonValueKind.String))

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.

Thanks for addressing the earlier feedback on telemetry, subscription handling, tests, and documentation. I found one remaining edge case in this filter: with resourceSubscriptions: [null, "test://direct/text/resource"], the null entry makes uri?.GetValueKind() == JsonValueKind.String false, so the filter leaves the entire property in place. The SDK currently accepts and acknowledges the valid URI in that array, even though the sample cannot deliver its updates. I reproduced this against the latest head; the focused regression test fails. Please explicitly reject null entries here, rather than relying on SDK validation, and add a test for a mixed null/string array.

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

6 participants