Skip to content

chore(mcp): document stateless transport posture and remove SseKeepAliveMiddleware#3501

Merged
Mpdreamz merged 4 commits into
mainfrom
feature/mcp-1.4-transport
Jun 15, 2026
Merged

chore(mcp): document stateless transport posture and remove SseKeepAliveMiddleware#3501
Mpdreamz merged 4 commits into
mainfrom
feature/mcp-1.4-transport

Conversation

@Mpdreamz

Copy link
Copy Markdown
Member

Why

The SseKeepAliveMiddleware was added as a workaround for a Cursor SSE-fallback bug, and the
stateless-mode comment blamed that same bug. Both are now wrong: in SDK 1.4+, stateless mode and
legacy SSE are mutually exclusive (enabling both throws at startup), and the Cursor bug is an
unfixed client-side regression that server config cannot address.

The keepalive middleware allocated an SseKeepAliveStream + SemaphoreSlim on every MCP
request even though no text/event-stream response is ever produced in stateless mode — the timer
never started, but the allocations always happened.

What

  • Rewrites the stateless-mode comment to explain the actual architectural justification: pure
    request/response tools with no server push, running behind a load balancer with no session
    affinity. Adds a one-line pointer to the mcp-remote stdio bridge for SSE-only clients.
  • Removes SseKeepAliveMiddleware and its SseKeepAliveStream inner class (~285 lines).
  • Updates the ConfigureHttpJsonOptions comment to reflect its real purpose (not legacy SSE).

How

In ModelContextProtocol.AspNetCore 1.4.0, WithHttpTransport(o => o.Stateless = true) + MapMcp("")
mounts exactly one route: POST / (Streamable HTTP request/response). Legacy SSE (/sse +
/message) is opt-in via EnableLegacySse (default false) and throws InvalidOperationException
at startup if combined with Stateless = true. The SDK emits no SSE heartbeat, but in stateless
mode there is no SSE stream to keep alive.

@Mpdreamz Mpdreamz added the chore label Jun 15, 2026
@Mpdreamz Mpdreamz requested a review from a team as a code owner June 15, 2026 08:08
@Mpdreamz Mpdreamz requested a review from technige June 15, 2026 08:08
@Mpdreamz Mpdreamz temporarily deployed to integration-tests June 15, 2026 08:08 — with GitHub Actions Inactive
@coderabbitai

coderabbitai Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@Mpdreamz, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 14 minutes and 47 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 538cdbc2-3313-4a78-b316-870532877787

📥 Commits

Reviewing files that changed from the base of the PR and between 378d9d1 and c0aeb23.

📒 Files selected for processing (3)
  • src/Elastic.Documentation.ServiceDefaults/AppDefaultsExtensions.cs
  • src/api/Elastic.Documentation.Mcp.Remote/Program.cs
  • src/api/Elastic.Documentation.Mcp.Remote/SseKeepAliveMiddleware.cs
📝 Walkthrough

Walkthrough

The PR consolidates OpenTelemetry registration by replacing Extensions.cs, EuidEnrichmentExtensions.cs, and per-service OTel helpers with a single AddDocumentationOpenTelemetry extension accepting an OtelRegistration parameter. A new VersionHelper parses assembly version metadata for resource attributes. MCP Remote gains McpSpanRenameProcessor and expanded McpToolTelemetry metrics (counter and duration histogram), and drops SseKeepAliveMiddleware in favor of stateless HTTP transport. AppDefaultsExtensions gains HTTP resilience defaults and a self/live health check extension. All entry points (docs-api, docs-mcp, docs-builder) are re-wired to the new fluent API. NuGet packages are bumped across the board.

Possibly Related PRs

  • elastic/docs-builder#3333: Directly related — also reworks EUID enrichment and documentation OpenTelemetry wiring in src/Elastic.Documentation.ServiceDefaults/Telemetry, removing/replacing the same EuidEnrichmentExtensions-style helpers that this PR finalizes.
  • elastic/docs-builder#3356: Connected — updates ApiWebApplicationFactory and OTel test wiring to require OTEL_EXPORTER_OTLP_ENDPOINT, which aligns with this PR's conditional no-op behavior in AddDocumentationOpenTelemetry.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 21.05% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed Title clearly references the main changes: documenting stateless transport and removing SseKeepAliveMiddleware.
Description check ✅ Passed Description thoroughly explains the rationale, scope, and implementation details of the changeset.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch feature/mcp-1.4-transport

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@aspire/Properties/launchSettings.json`:
- Around line 10-11: The launchSettings.json file has misaligned environment
variable values: ASPNETCORE_ENVIRONMENT is set to "dev" while DOTNET_ENVIRONMENT
is set to "Development". Although DOTNET_ENVIRONMENT takes precedence in .NET
10's WebApplicationBuilder, the mismatch creates confusion and should be
resolved for clarity. Change ASPNETCORE_ENVIRONMENT from "dev" to "Development"
to align both variables to the same value, matching the DOTNET_ENVIRONMENT
setting and following Microsoft's recommendations.

In `@src/Elastic.Documentation.ServiceDefaults/AppDefaultsExtensions.cs`:
- Around line 37-40: The AddStandardResilienceHandler() call in
ConfigureHttpClientDefaults applies global resilience policies that retry all
HTTP methods by default, including unsafe operations like POST, PUT, PATCH, and
DELETE which can cause data duplication when retried. Configure the
AddStandardResilienceHandler() method to exclude non-idempotent HTTP methods
from retry logic by passing appropriate configuration options to disable retries
for unsafe methods. Additionally, add the required using statement for
Microsoft.Extensions.Http.Resilience at the top of the AppDefaultsExtensions.cs
file to support the resilience configuration APIs.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 49a9b082-7eda-498a-b6c3-1f75398d0c5f

📥 Commits

Reviewing files that changed from the base of the PR and between d68e69d and 378d9d1.

📒 Files selected for processing (17)
  • Directory.Packages.props
  • aspire/Properties/launchSettings.json
  • src/Elastic.Documentation.ServiceDefaults/AppDefaultsExtensions.cs
  • src/Elastic.Documentation.ServiceDefaults/Extensions.cs
  • src/Elastic.Documentation.ServiceDefaults/Telemetry/EuidEnrichmentExtensions.cs
  • src/Elastic.Documentation.ServiceDefaults/Telemetry/OpenTelemetryRegistrationExtensions.cs
  • src/Elastic.Documentation.ServiceDefaults/Telemetry/VersionHelper.cs
  • src/api/Elastic.Documentation.Api/OpenTelemetry/OpenTelemetryExtensions.cs
  • src/api/Elastic.Documentation.Api/Program.cs
  • src/api/Elastic.Documentation.Mcp.Remote/Program.cs
  • src/api/Elastic.Documentation.Mcp.Remote/SseKeepAliveMiddleware.cs
  • src/api/Elastic.Documentation.Mcp.Remote/Telemetry/McpSpanRenameProcessor.cs
  • src/api/Elastic.Documentation.Mcp.Remote/Telemetry/McpToolTelemetry.cs
  • src/tooling/docs-builder/DocumentationTooling.cs
  • src/tooling/docs-builder/Program.cs
  • tests-integration/Elastic.Documentation.IntegrationTests/Search/SearchBootstrapFixture.cs
  • tests/Elastic.Documentation.Api.Tests/Fixtures/ApiWebApplicationFactory.cs
💤 Files with no reviewable changes (4)
  • src/api/Elastic.Documentation.Mcp.Remote/SseKeepAliveMiddleware.cs
  • src/Elastic.Documentation.ServiceDefaults/Extensions.cs
  • src/Elastic.Documentation.ServiceDefaults/Telemetry/EuidEnrichmentExtensions.cs
  • src/tooling/docs-builder/DocumentationTooling.cs

Comment thread aspire/Properties/launchSettings.json Outdated
Comment thread src/Elastic.Documentation.ServiceDefaults/AppDefaultsExtensions.cs
Mpdreamz and others added 3 commits June 15, 2026 10:37
Each MCP tool call now appears as its own transaction in Elastic
Observability instead of collapsing under POST /docs/_mcp/.

- McpSpanRenameProcessor renames the ASP.NET Core server span to
  "tools/call {tool}" in OnEnd, after the route-based name is set
- mcp.method.name and mcp.tool.name semconv tags added to server span
- Meter added with mcp.tool.calls counter and mcp.tool.duration
  histogram, both dimensioned by tool name, method, profile, outcome
- OTel registration consolidated into AddDocumentationOpenTelemetry
  (replaces Extensions.cs and EuidEnrichmentExtensions.cs)
- Aspire bumped to 13.4.3; fixes ExecuteCommandContext.Arguments
  required member in integration test bootstrap

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…iveMiddleware

In SDK 1.4+, stateless mode and legacy SSE are mutually exclusive — enabling
both throws at startup. The only mounted route under Stateless=true is POST /
(Streamable HTTP); there is no SSE stream to keep alive.

Updates the misleading comment that blamed a Cursor bug for the stateless
choice: the real reasons are architectural (pure request/response tools, no
session affinity at the load balancer). Adds a one-line pointer to mcp-remote
for SSE-only clients.

Removes SseKeepAliveMiddleware, which allocated an SseKeepAliveStream +
SemaphoreSlim on every MCP request despite the keepalive timer never firing in
stateless mode.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
POST/PUT/DELETE are not idempotent; retrying them can cause duplicate
mutations. DisableForUnsafeHttpMethods() restricts the standard
resilience retry handler to safe methods only (GET, HEAD, OPTIONS).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@Mpdreamz Mpdreamz force-pushed the feature/mcp-1.4-transport branch from 378d9d1 to b05d62a Compare June 15, 2026 08:45
@Mpdreamz Mpdreamz temporarily deployed to integration-tests June 15, 2026 08:45 — with GitHub Actions Inactive
Comment thread aspire/Properties/launchSettings.json Outdated
Co-authored-by: Martijn Laarman <Mpdreamz@gmail.com>
@Mpdreamz Mpdreamz temporarily deployed to integration-tests June 15, 2026 08:54 — with GitHub Actions Inactive
@Mpdreamz Mpdreamz enabled auto-merge (squash) June 15, 2026 08:55
@Mpdreamz Mpdreamz merged commit 68918e2 into main Jun 15, 2026
25 checks passed
@Mpdreamz Mpdreamz deleted the feature/mcp-1.4-transport branch June 15, 2026 09:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants