examples: Fix SSE streaming issue by moving logging from HTTP to MCP middlewarre#614
Merged
findleyr merged 2 commits intomodelcontextprotocol:mainfrom Nov 11, 2025
Merged
Conversation
… layer The previous HTTP-level logging middleware blocked SSE streaming because handler.ServeHTTP() does not return until the connection closes for GET requests (SSE streams). This prevented response headers from being sent to the client. Changes: - Replace HTTP-level logging handler with MCP middleware pattern - Implement logging at the MCP protocol layer using mcp.Middleware - Log session ID, method names, duration, and error status - Add middleware to server using AddReceivingMiddleware() - Simplify main.go by removing HTTP handler wrapping - Use standard log package with structured format for clarity This allows SSE streams to work properly while still providing detailed logging for all MCP protocol-level method calls.
Contributor
|
Thank you. I'll see if @jba wants to review, since he reviewed the original. Otherwise, I will review on Monday. |
jba
previously requested changes
Nov 9, 2025
examples/http/logging_middleware.go
Outdated
|
|
||
| // Log request details. | ||
| log.Printf("[REQUEST] %s | Session: %s | Method: %s", | ||
| start.Format(time.RFC3339), |
Contributor
There was a problem hiding this comment.
The log package already prints the time by default. I know the previous code had this, but I think it's redundant.
findleyr
approved these changes
Nov 11, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In
examples/http, previous HTTP-level logging middleware blocked SSE streaming becausehandler.ServeHTTP()does not return until the connection closes for GET requests (SSE streams).This prevented response headers from being sent to the client.
Changes:
This allows SSE streams to work properly while still providing detailed logging for all MCP protocol-level method calls.