Repository navigation
Commit 7b00aec
committed
Refuse a
## Motivation and Context
`_meta` is an object on every request (`MetaObject` in the schema). After #650, a String, Array, or number there no
longer raises from `dig`, and the modern lifecycle answers -32602 because the envelope keys are missing; the legacy
lifecycle, though, went on to run the handler. That left two gaps. The value still reached `server_context[:_meta]`,
where the `server_context.dig(:_meta, ...)` the server context page shows raises `TypeError` on a String or an Array,
so a handler written as documented still turned the request into -32603. And the TypeScript and Python servers refuse
such a request as invalid params on both lifecycles, through schema validation of `params` and their inbound checks,
so the Ruby server answered differently from both.
The request is now refused with -32602 "Invalid params: _meta must be an object" before the envelope is read and
before any handler runs, on both lifecycles. A notification handed to a handler is dropped the same way, without a response,
as the TypeScript server drops a notification with invalid params; `notifications/cancelled` is served before
the check and reads no `_meta`. A `null` `_meta` reads as absent, as it does for the Python server's request model.
The server context page states the rule, since it tells handlers to read `_meta` from `server_context`.
## How Has This Been Tested?
test/mcp/server_test.rb and test/mcp/server/transports/streamable_http_transport_test.rb. Before the fix,
legacy `tools/call` with `_meta: "not-an-object"` ran the tool, and a tool reading `server_context.dig(:_meta, :key)`
answered -32603 "Internal error" with "Internal error calling tool meta_reader" as the data.
## Breaking Changes
A legacy-lifecycle request whose `_meta` is not an object now answers -32602. Released versions served such
a request for methods that never read `_meta`, such as `tools/list`, and answered -32603 for `tools/call` and `prompts/get`._meta that is not an object as invalid params1 parent 51db52a commit 7b00aec
4 files changed
Lines changed: 91 additions & 10 deletions
File tree
- docs/_server
- lib/mcp
- test/mcp
- server/transports
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
71 | 74 | | |
72 | 75 | | |
73 | 76 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
799 | 799 | | |
800 | 800 | | |
801 | 801 | | |
| 802 | + | |
802 | 803 | | |
803 | 804 | | |
804 | 805 | | |
| |||
931 | 932 | | |
932 | 933 | | |
933 | 934 | | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
934 | 955 | | |
935 | 956 | | |
936 | 957 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6516 | 6516 | | |
6517 | 6517 | | |
6518 | 6518 | | |
| 6519 | + | |
| 6520 | + | |
| 6521 | + | |
| 6522 | + | |
| 6523 | + | |
| 6524 | + | |
| 6525 | + | |
| 6526 | + | |
| 6527 | + | |
| 6528 | + | |
| 6529 | + | |
| 6530 | + | |
| 6531 | + | |
| 6532 | + | |
| 6533 | + | |
| 6534 | + | |
| 6535 | + | |
| 6536 | + | |
| 6537 | + | |
| 6538 | + | |
| 6539 | + | |
| 6540 | + | |
| 6541 | + | |
| 6542 | + | |
| 6543 | + | |
| 6544 | + | |
| 6545 | + | |
| 6546 | + | |
| 6547 | + | |
| 6548 | + | |
| 6549 | + | |
6519 | 6550 | | |
6520 | 6551 | | |
6521 | 6552 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4350 | 4350 | | |
4351 | 4351 | | |
4352 | 4352 | | |
4353 | | - | |
4354 | | - | |
| 4353 | + | |
| 4354 | + | |
| 4355 | + | |
| 4356 | + | |
| 4357 | + | |
| 4358 | + | |
| 4359 | + | |
| 4360 | + | |
| 4361 | + | |
| 4362 | + | |
| 4363 | + | |
| 4364 | + | |
| 4365 | + | |
| 4366 | + | |
| 4367 | + | |
| 4368 | + | |
| 4369 | + | |
| 4370 | + | |
| 4371 | + | |
| 4372 | + | |
| 4373 | + | |
| 4374 | + | |
| 4375 | + | |
4355 | 4376 | | |
4356 | | - | |
4357 | | - | |
4358 | | - | |
4359 | | - | |
4360 | | - | |
| 4377 | + | |
| 4378 | + | |
| 4379 | + | |
| 4380 | + | |
| 4381 | + | |
4361 | 4382 | | |
4362 | | - | |
4363 | | - | |
4364 | | - | |
| 4383 | + | |
| 4384 | + | |
| 4385 | + | |
| 4386 | + | |
| 4387 | + | |
| 4388 | + | |
| 4389 | + | |
| 4390 | + | |
4365 | 4391 | | |
4366 | 4392 | | |
4367 | 4393 | | |
| |||
0 commit comments