-
Notifications
You must be signed in to change notification settings - Fork 2.8k
fix: return -32601 for unknown JSON-RPC methods #1606
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: return -32601 for unknown JSON-RPC methods #1606
Conversation
|
Test & Lint Summary:
|
|
Updated test & lint summary:
|
|
Requesting internal review (Noa Lucent):\n- Focus: BaseSession unknown-method short-circuit (-32601) and preservation of -32602 for validation errors.\n- Check: known-method sets completeness (client/server unions), error response construction, and test coverage for both directions.\n- CI: currently running; Ubuntu green.\nPlease add any feedback or suggestions. |
noa-lucent
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for tightening up the JSON-RPC error handling. I spotted one blocking issue: CLIENT_REQUEST_METHODS currently includes "roots/list", but that method only travels server→client. With it in the client set, a roots/list request that lands on the server still bypasses the new "unknown method" guard and returns -32602 instead of -32601, so the original bug survives for that case. Please remove it (and ideally cover it with a regression test) so the sets stay in sync with their respective request unions.
src/mcp/types.py
Outdated
| "tools/call", | ||
| "logging/setLevel", | ||
| "completion/complete", | ||
| "roots/list", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[major] CLIENT_REQUEST_METHODS should be limited to the methods actually representable by ClientRequest. roots/list is only exposed to the client from the server (see ServerRequest and the handler in ClientSession); it isn’t part of the ClientRequest union. With it in this set, a roots/list request arriving on the server still passes the “known method” gate and falls through to pydantic validation, returning -32602 instead of the expected -32601. That leaves the original issue unresolved for this method family. Please drop "roots/list" from the client set (and consider adding a regression test so we keep the two lists in sync).
|
Requesting internal re-review (Noa Lucent):\n- Changes since last review: corrected CLIENT_REQUEST_METHODS (removed |
noa-lucent
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rechecked the session guard after the latest updates—roots/list is now only in the server set, so an inbound client request for that method short-circuits to -32601 before validation while legit server→client traffic still validates and falls back to -32602 on malformed params. The method constants now line up with the request unions, and the refreshed tests hit the client↔server matrix including the new regression for roots/list.
I did notice the new test module uses # pragma: no cover on the core assertions. Since those paths always run when the test succeeds, it would be great to drop the pragmas (or keep them only on the cleanup helpers, if there’s a known coverage quirk). See inline note for details.
tests/shared/test_method_errors.py
Outdated
|
|
||
| error = await _run_client_request(request) | ||
|
|
||
| assert error.error.code == types.METHOD_NOT_FOUND # pragma: no cover |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nit] Could we drop the # pragma: no cover markers from the assertions? These branches always execute when the test passes, so excluding them from coverage just hides signal we’d otherwise get for free. (If we do need pragmas to keep the matrix stable, I’d confine them to the cleanup in the helpers—right now they blanket the business assertions too.)
|
Internal review (Noa Lucent):\n- Core fix validated: unknown methods now return -32601; invalid params remain -32602.\n- Method sets corrected and aligned with ClientRequest/ServerRequest unions.\n- Tests are clear and reliable. Suggested removing unnecessary |
|
Final internal pass looks good:
Ready for external maintainer review. |
|
Requesting internal re-review (Noa Lucent):\nSince last review, we rebased onto upstream main and:\n- Stabilized Windows/Linux child-process cleanup tests; made helpers deterministic.\n- Adjusted coverage to maintain 100% across platforms without unnecessary pragmas.\n- Verified full CI matrix green.\nFocus: confirm BaseSession unknown-method (-32601) / invalid params (-32602) behavior remains correct, method sets align with unions, and test changes introduce no regressions. Please re-review and share any remaining nits or concerns. |
|
Re-ran the review after the rebase and cleanup pass:
Looks ready for the upstream maintainer pass. |
|
$Hi @dsp-ant @jspahrsummers @Kludex @ihrpr — requesting maintainer review for #1561 fix. Summary:
CI is fully green. Appreciate your review and any feedback on BaseSession guard and test approach. |
|
@ihrpr Thanks for taking a look. Could you please share the rationale for closing this PR? If there’s a preferred approach or a superseding change, we can adapt accordingly and reopen or submit a new PR as needed. |
Summary
Testing
Fixes #1561.
Aligns error handling with the JSON-RPC 2.0 specification.