Commit c0cbc9e
committed
Add inputSchema validation to lowlevel server
- Add jsonschema dependency for schema validation
- Implement tool definition cache in Server class that gets refreshed when list_tools is called
- Add _validate_tool_arguments helper method to validate tool arguments against inputSchema
- Update call_tool handler to validate arguments before execution
- Log warning and skip validation for tools not found in cache
- Add comprehensive tests for validation scenarios
This ensures tool arguments are validated against their JSON schemas before execution,
providing better error messages and preventing invalid tool calls from reaching handlers.1 parent 4d45bb8 commit c0cbc9e
File tree
4 files changed
+499
-1
lines changed- src/mcp/server/lowlevel
- tests/server
4 files changed
+499
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| 34 | + | |
34 | 35 | | |
35 | 36 | | |
36 | 37 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
| 78 | + | |
78 | 79 | | |
79 | 80 | | |
80 | 81 | | |
| |||
143 | 144 | | |
144 | 145 | | |
145 | 146 | | |
| 147 | + | |
146 | 148 | | |
147 | 149 | | |
148 | 150 | | |
| |||
373 | 375 | | |
374 | 376 | | |
375 | 377 | | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
376 | 382 | | |
377 | 383 | | |
378 | 384 | | |
379 | 385 | | |
380 | 386 | | |
381 | 387 | | |
382 | 388 | | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
383 | 414 | | |
384 | 415 | | |
385 | 416 | | |
| |||
391 | 422 | | |
392 | 423 | | |
393 | 424 | | |
394 | | - | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
395 | 439 | | |
396 | 440 | | |
397 | 441 | | |
| |||
0 commit comments