Skip to content

mcp: keep request log levels scoped to each request - #1168

Open
jstar0 wants to merge 1 commit into
modelcontextprotocol:mainfrom
jstar0:audit/server-request-meta
Open

mcp: keep request log levels scoped to each request#1168
jstar0 wants to merge 1 commit into
modelcontextprotocol:mainfrom
jstar0:audit/server-request-meta

Conversation

@jstar0

@jstar0 jstar0 commented Aug 13, 2026

Copy link
Copy Markdown

Fixes a request-scoping bug in the new-protocol logging path. ServerSession.handle decoded _meta[io.modelcontextprotocol/logLevel], but stored it in ServerSessionState.LogLevel. Concurrent new-protocol requests on the same session could therefore clear or inherit another request's log threshold before the original handler emitted logs.

This keeps the new-protocol log level on the handler context instead. ServerSession.Log and LoggingHandler.Enabled read that context value first, while legacy logging/setLevel behavior still uses session state.

Tests:

  • go test ./mcp -run TestServerLogLevelDoesNotLeakBetweenNewProtocolRequests -count=1
  • go test -race ./mcp -run TestServerLogLevelDoesNotLeakBetweenNewProtocolRequests -count=1
  • go test ./mcp -run TestEndToEnd -count=1
  • go test ./mcp -run TestValidateRequestMeta -count=1
  • go test ./mcp -run TestStreamableStateless_NewProtocolSession_NoFakeInit -count=1
  • go test ./... -skip TestSSELocalhostProtection|TestStreamableLocalhostProtection

A full go test ./... run in my local environment still fails the two localhost protection cases for 0.0.0.0 via localhost rejects evil.com; those same two tests also fail when run directly and are unrelated to this logging change.

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.

1 participant