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
10
mcp/testdata/conformance/server/tools.txtar
vendored
10
mcp/testdata/conformance/server/tools.txtar
vendored
|
|
@ -4,6 +4,7 @@ Fixed bugs:
|
|||
- "tools/list" can have missing params
|
||||
- "_meta" should not be nil
|
||||
- empty resource or prompts should not be returned as 'null'
|
||||
- the server should not crash when params are passed to tools/call
|
||||
|
||||
-- tools --
|
||||
greet
|
||||
|
|
@ -22,6 +23,7 @@ greet
|
|||
{ "jsonrpc": "2.0", "id": 2, "method": "tools/list" }
|
||||
{ "jsonrpc": "2.0", "id": 3, "method": "resources/list" }
|
||||
{ "jsonrpc": "2.0", "id": 4, "method": "prompts/list" }
|
||||
{ "jsonrpc": "2.0", "id": 5, "method": "tools/call" }
|
||||
-- server --
|
||||
{
|
||||
"jsonrpc": "2.0",
|
||||
|
|
@ -81,3 +83,11 @@ greet
|
|||
"prompts": []
|
||||
}
|
||||
}
|
||||
{
|
||||
"jsonrpc": "2.0",
|
||||
"id": 5,
|
||||
"error": {
|
||||
"code": -32600,
|
||||
"message": "invalid request: missing required \"params\""
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue