fix(interceptors): avoid marshalling non-serializable request internals#360
Open
Pnkcaht wants to merge 2 commits intodocker:mainfrom
Open
fix(interceptors): avoid marshalling non-serializable request internals#360Pnkcaht wants to merge 2 commits intodocker:mainfrom
Pnkcaht wants to merge 2 commits intodocker:mainfrom
Conversation
Signed-off-by: pnkcaht <samzoovsk19@gmail.com>
Signed-off-by: pnkcaht <samzoovsk19@gmail.com>
cutecatfann
approved these changes
Jan 26, 2026
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.
What I did
Hardened the interceptor execution flow to prevent before-interceptors from attempting to marshal non-serializable request internals on streaming and SSE transports.
This change limits the payload sent to before interceptors to a minimal, explicitly serializable tool-call shape, instead of the full
mcp.Requestobject. By doing so, it avoids leaking internal callback functions into JSON marshaling and restores correct interceptor behavior across streaming transports.The implementation preserves existing interceptor semantics while ensuring compatibility with documented interceptor usage patterns (for example,
jq -r ".params.arguments").Related issue
Fixed #358
What was the problem ?
When running
docker mcp gateway runwith a before interceptor on streaming or SSE transports, the gateway could fail with:json: unsupported type: func(mcp.CloseSSEStreamArgs)In these cases:
mcp.RequestThis resulted in interceptors appearing broken, even though the failure was caused by internal, non-JSON-safe fields unrelated to interceptor intent.
Diagram
Before Interceptor Execution Flow (Streaming / SSE)
flowchart TD A[Tool call received] --> B[Extract serializable tool-call payload] B --> C[Marshal minimal JSON payload] C --> D[Run before interceptor] D --> E{Interceptor returns output?} E -->|Yes| F[Use interceptor result] E -->|No| G[Continue normal execution]Explanation
The diagram illustrates the updated execution flow for before interceptors:
Payload Extraction
Instead of serializing the full
mcp.Request, the middleware extracts only the tool-call payload (methodandparams) that is safe and relevant for interceptors.Safe Marshaling
The extracted payload contains no internal callbacks or transport-specific fields, ensuring JSON marshaling succeeds on all transports, including streaming and SSE.
Interceptor Compatibility
This preserves compatibility with existing interceptors that expect fields like
.params.arguments.Normal Flow Preservation
If the interceptor returns no output, the request proceeds unchanged through the normal execution path.
Before
mcp.Requestwas marshaled for before interceptorsAfter
Testing
This change was validated through local builds and manual testing using streaming transports with before interceptors enabled.
No new automated tests were added as part of this PR, as the issue is transport-specific and tied to streaming/SSE runtime behavior. Follow-up work may introduce targeted integration tests once streaming interceptor coverage is expanded in CI.