Fix JSON-RPC 2.0 notification handling in StreamableHttpServerWrapper#28
Merged
Fix JSON-RPC 2.0 notification handling in StreamableHttpServerWrapper#28
Conversation
According to JSON-RPC 2.0 specification section 4.1: "A Notification is a Request object without an 'id' member... The Server MUST NOT reply to a Notification." Previously, the StreamableHttpServerWrapper would pass notifications to the handler and return whatever response it produced (typically an error for unknown methods like 'notifications/initialized'). This caused MCP clients like OpenAI Codex CLI to fail during handshaking. This fix: - Detects notifications by checking for missing/null 'id' field - Returns 202 Accepted with no response body for notifications - Still calls the handler so notification processing can occur - Silently ignores any handler errors for notifications Added test_notification_handling() to verify: - notifications/initialized returns 202 with empty body - notifications/cancelled returns 202 with empty body Fixes compatibility with MCP clients that follow the JSON-RPC 2.0 spec.
9a2cae1 to
879e6f6
Compare
Adds .githooks/pre-commit that automatically formats staged C++ files before commit. This prevents formatting issues from reaching CI. To enable: git config core.hooksPath .githooks The hook: - Finds clang-format (prefers versioned like clang-format-19) - Formats only staged .cpp/.hpp/.h/.c files - Re-stages formatted files automatically
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.
Summary
This PR fixes JSON-RPC 2.0 notification handling in
StreamableHttpServerWrapperand adds a pre-commit hook for automatic formatting.1. Fix: JSON-RPC 2.0 Notification Handling
According to JSON-RPC 2.0 specification section 4.1:
Previously,
StreamableHttpServerWrapperwould pass notifications to the handler and return whatever response it produced. For unknown notification methods likenotifications/initialized, this resulted in error responses like:{"error":{"code":-32601,"message":"Method 'notifications/initialized' not found"},"id":null,"jsonrpc":"2.0"}This caused MCP clients (like OpenAI Codex CLI) to fail during handshaking.
The fix:
idfield202 Acceptedwith no response body for notifications2. Pre-commit Hook for Automatic Formatting
Added
.githooks/pre-committhat automatically formats staged C++ files with clang-format before commit.To enable:
git config core.hooksPath .githooksThis prevents formatting issues from reaching CI.
Test Plan