mcp: handle bad or missing params (#210)
Audit all cases where params must not be null, and enforce this using methodInfo via a new methodFlags bitfield that parameterizes method requirements. Write extensive conformance tests catching all the (server-side) crashes that were possible. We should go further and validate schema against the spec, but that is more indirect, more complicated, and potentially slower. For now we adopt this more explicit approach. Still TODO in a subsequent CL: verify the client side of this with client conformance tests. Additionally, improve some error messages that were redundant or leaked internal implementation details. Fixes #195
This commit is contained in:
parent
a9a503f74a
commit
b34ba2149d
1 changed files with 170 additions and 52 deletions
21
mcp/testdata/conformance/server/resources.txtar
vendored
21
mcp/testdata/conformance/server/resources.txtar
vendored
|
|
@ -2,6 +2,9 @@ Check behavior of a server with just resources.
|
|||
|
||||
Fixed bugs:
|
||||
- A resource result holds a slice of contents, not just one.
|
||||
- No params in 'resource/read' should not panic.
|
||||
- No params in 'resources/subscribe' should not panic.
|
||||
- No params in 'resources/unsubscribe' should not panic.
|
||||
|
||||
-- resources --
|
||||
info
|
||||
|
|
@ -39,6 +42,8 @@ info.txt
|
|||
"roots": []
|
||||
}
|
||||
}
|
||||
{ "jsonrpc": "2.0", "id": 4, "method": "resources/read" }
|
||||
{ "jsonrpc": "2.0", "id": 5, "method": "resources/subscribe" }
|
||||
-- server --
|
||||
{
|
||||
"jsonrpc": "2.0",
|
||||
|
|
@ -107,3 +112,19 @@ info.txt
|
|||
]
|
||||
}
|
||||
}
|
||||
{
|
||||
"jsonrpc": "2.0",
|
||||
"id": 4,
|
||||
"error": {
|
||||
"code": -32600,
|
||||
"message": "invalid request: missing required \"params\""
|
||||
}
|
||||
}
|
||||
{
|
||||
"jsonrpc": "2.0",
|
||||
"id": 5,
|
||||
"error": {
|
||||
"code": -32600,
|
||||
"message": "invalid request: missing required \"params\""
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue