Repository navigation
Emit conformant JSON-RPC on authz denial responses - #5955
stantheman0128 wants to merge 1 commit into
Conversation
Fixes stacklok#5950 Co-authored-by: Cursor <[email protected]>
|
Thanks for taking a crack at this, and for the clear write-up plus the up-front note about AI assistance. I'm closing this one on process grounds rather than technical ones. Our contributing guide asks that you comment on an issue and wait for a maintainer to assign it before starting work: https://github.com/stacklok/toolhive/blob/main/CONTRIBUTING.md#claiming-an-issue. #5950 had no comments and no assignee when this PR showed up. That step is there specifically to avoid duplicated effort, and that's what happened here — the fix was already scoped on our side, with a wider blast radius than this PR covers (the same direct-marshal bug exists in the validating and mutating webhook middlewares, and their tests currently assert the capitalized keys, so those two sites would have stayed broken behind a closed issue). One other thing for next time: commits need a For what it's worth, driving the assertion through ParsingMiddleware + Middleware with the real If you'd like to pick something else up, drop a comment on an issue that interests you and we'll get you assigned. |
Summary
Authz denial responses were not valid JSON-RPC 2.0.
handleUnauthorizedencoded a*jsonrpc2.Responsewithencoding/jsondirectly. That struct has no json tags / MarshalJSON, so the wire body used capitalized keys (Result/Error/ID) and omitted the mandatory"jsonrpc":"2.0"field. Spec-strict MCP clients cannot readerror/idon a 403.What changed
map[string]anywith"jsonrpc":"2.0","id", and"error"(same pattern asclassificationErrorBody/filteredToolCallErrorBody)writeErrorResponse/filteringErrorBody), which had the same direct-marshal bugserver/discover403Fixes #5950
Type of change
Test plan
go test ./pkg/authz/ ...)task test-e2e)task lint-fix)Evidence
Before (issue report,
POST /mcpserver/discoverwith authz enabled):{"Result":null,"Error":{"code":403,"message":"unknown MCP method: server/discover (not configured for authorization)"},"ID":{}}After fix, HTTP product-path wire bytes from
TestHandleUnauthorizedHTTPWireBytes:Targeted tests (Windows):
Full package:
What was not tested
server/discovermethod.task lint-fix/ e2e suite (targeted package tests only).Does this introduce a user-facing change?
Yes. Authorization-denied MCP responses now use a JSON-RPC 2.0 envelope (
jsonrpc,id,errorlowercase). Clients that already accepted the capitalized keys via case-insensitive unmarshal remain compatible; spec-strict clients can now parse the denial.Special notes for reviewers
AI disclosure
This change was developed with AI assistance (Cursor/Grok). The author reviewed the diff, ran the Evidence commands above, and takes responsibility for the patch.