|
11 | 11 | import pytest |
12 | 12 | from dirty_equals import IsPartialDict |
13 | 13 | from mcp_types import CallToolResult, InputRequiredResult |
14 | | -from pydantic import BaseModel, Field |
| 14 | +from pydantic import BaseModel, Field, ValidationError |
15 | 15 |
|
16 | 16 | from mcp.server.mcpserver.exceptions import InvalidSignature |
17 | 17 | from mcp.server.mcpserver.utilities.func_metadata import func_metadata |
@@ -275,6 +275,7 @@ async def test_lambda_function(): |
275 | 275 |
|
276 | 276 | # Test schema |
277 | 277 | assert meta.arg_model.model_json_schema() == { |
| 278 | + "additionalProperties": False, |
278 | 279 | "properties": { |
279 | 280 | "x": {"title": "x", "type": "string"}, |
280 | 281 | "y": {"default": 5, "title": "y", "type": "string"}, |
@@ -464,6 +465,7 @@ def test_complex_function_json_schema(): |
464 | 465 | "my_model_a_forward_ref", |
465 | 466 | "my_model_b", |
466 | 467 | ], |
| 468 | + "additionalProperties": False, |
467 | 469 | "title": "complex_arguments_fnArguments", |
468 | 470 | "type": "object", |
469 | 471 | } |
@@ -1297,6 +1299,17 @@ def fn() -> CallToolResult | str | InputRequiredResult: ... # pragma: no branch |
1297 | 1299 | func_metadata(fn) |
1298 | 1300 |
|
1299 | 1301 |
|
| 1302 | +def test_unknown_argument_raises_validation_error(): |
| 1303 | + """SDK-defined: a tools/call argument name not on the tool schema fails validation.""" |
| 1304 | + |
| 1305 | + def read_doc(topic: str = "") -> str: |
| 1306 | + return topic |
| 1307 | + |
| 1308 | + meta = func_metadata(read_doc) |
| 1309 | + with pytest.raises(ValidationError): |
| 1310 | + meta.arg_model.model_validate({"path": "something"}) |
| 1311 | + |
| 1312 | + |
1300 | 1313 | def test_union_of_only_input_required_subclasses_yields_no_output_schema(): |
1301 | 1314 | class StepA(InputRequiredResult): |
1302 | 1315 | pass |
|
0 commit comments