Skip to content

Add HTTP call completion logging for exceptions and non-success status codes#1501

Open
Copilot wants to merge 1 commit intomainfrom
copilot/investigate-http-logging-gaps
Open

Add HTTP call completion logging for exceptions and non-success status codes#1501
Copilot wants to merge 1 commit intomainfrom
copilot/investigate-http-logging-gaps

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 3, 2026

Summary

Ensures all HTTP calls in the client transport layer log when operations complete with either an exception or a non-success status code. This makes it much easier to diagnose connectivity and protocol issues from logs alone.

All logging follows existing patterns using the [LoggerMessage] source generator attribute. Problem conditions (exceptions, unexpected non-success status codes) use Warning level, while expected conditions (e.g., DELETE getting 405 because server support is optional) use Information level.

Changes

StreamableHttpClientSessionTransport

  • POST requests (SendHttpRequestAsync): Log exceptions (Warning) and non-success status codes (Warning)
  • GET SSE requests (SendGetSseRequestWithRetriesAsync): Log HttpRequestException on retry (Warning), server errors 5xx on retry (Warning), and non-retryable non-success status codes (Warning)
  • DELETE requests (SendDeleteRequest): Log exceptions (Warning) and non-success status codes (Information — since server support for DELETE is optional per MCP spec)

SseClientSessionTransport

  • GET SSE connection (ReceiveMessagesAsync): Log non-success status codes (Warning)
  • POST rejected (LogRejectedPost): Upgraded from Information to Warning level since a rejected POST is a problem
  • Removed unused LogAcceptedPost method (was defined but never called)

ClientOAuthProvider

  • Auth server metadata discovery (GetAuthServerMetadataAsync): Log non-success status codes when trying well-known endpoints (Warning)
  • Token refresh (RefreshTokensAsync): Log non-success status codes on silent refresh failure (Warning)
  • Token exchange (ExchangeCodeForTokenAsync): Log non-success status codes before throwing (Warning)
  • Protected resource metadata (FetchProtectedResourceMetadataAsync): Log non-success status codes (Warning)
  • Dynamic client registration (PerformDynamicClientRegistrationAsync): Log non-success status codes before throwing (Warning)

Testing

  • All existing tests pass (5,667 passed across 3 target frameworks for core tests, 996 passed for AspNetCore tests)
  • CodeQL security scan: clean, no alerts
  • Build: 0 warnings, 0 errors

…status codes

- StreamableHttpClientSessionTransport: Add logging for POST failures and non-success,
  GET SSE request failures and non-success, DELETE request failures and non-success
- SseClientSessionTransport: Add logging for GET SSE non-success status codes,
  upgrade LogRejectedPost to Warning level, remove unused LogAcceptedPost
- ClientOAuthProvider: Add logging for auth server metadata non-success,
  token refresh failure, token exchange failure, protected resource metadata
  non-success, and dynamic client registration failure

Agent-Logs-Url: https://github.com/modelcontextprotocol/csharp-sdk/sessions/d9f395f7-797a-47f1-a07f-1788d91811c4

Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
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.

2 participants