Skip to content

mcp: expose streamable HTTP request summaries - #1101

Open
CaliLuke wants to merge 3 commits into
modelcontextprotocol:mainfrom
CaliLuke:issue-1076-request-summary
Open

mcp: expose streamable HTTP request summaries#1101
CaliLuke wants to merge 3 commits into
modelcontextprotocol:mainfrom
CaliLuke:issue-1076-request-summary

Conversation

@CaliLuke

@CaliLuke CaliLuke commented Jul 17, 2026

Copy link
Copy Markdown

Streamable HTTP middleware can observe HTTP lifecycle information, but it cannot safely obtain JSON-RPC message metadata from the SDK-authoritative parse without reading and parsing the request body again. That duplicates buffering and risks retaining sensitive parameters.

This change adds a redacted StreamableHTTPRequestSummary and an OnRequestSummary callback to StreamableHTTPOptions. The callback runs synchronously after the session transport decodes a POST body containing a single JSON-RPC message and before validation or dispatch. It is not invoked for deprecated JSON-RPC batches. The summary exposes only the method, a call request ID, and notification/response classification. It adds no request-body reads, replacements, or buffering.

The callback receives the HTTP request context for middleware correlation. Its documentation describes concurrency, early HTTP/session/connection rejection gaps, attacker-controlled method strings, panic behavior, and its relationship to Server.AddReceivingMiddleware.

Verification:

  • gofmt -l .
  • go vet ./...
  • staticcheck v0.6.1 and v0.7.0
  • go test ./... with Go 1.25 and Go 1.26.5
  • go test -race ./...
  • go generate ./...
  • pinned stateful, stateless, and client MCP conformance suites
  • govulncheck with Go 1.26.5

Fixes #1076

Comment thread mcp/streamable.go Outdated
Comment on lines +86 to +90
// Calls, Notifications, and Responses count the decoded JSON-RPC message
// kinds in the body.
Calls int
Notifications int
Responses int

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.

Batching is a deprecated feature, I would not add the support for it in the newly added StreamableHTTPRequestSummary

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Addressed in 4ffd153: the public summary now represents one JSON-RPC message with singular fields, and the callback is not invoked for deprecated batch bodies.

Comment thread mcp/streamable.go Outdated
Comment on lines +1810 to +1812
func isSingleStreamableMessage(incoming []jsonrpc.Message, isBatch bool) bool {
return !isBatch && len(incoming) == 1
}

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.

i don't think it's worth the helper

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Addressed in 4ffd153: removed the helper and inlined the single-message condition at its two call sites.

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.

mcp: expose parsed streamable HTTP request summary hook

2 participants