File tree Expand file tree Collapse file tree 1 file changed +7
-5
lines changed Expand file tree Collapse file tree 1 file changed +7
-5
lines changed Original file line number Diff line number Diff line change @@ -423,11 +423,12 @@ async def _get_cached_tool_definition(self, tool_name: str) -> types.Tool | None
423
423
424
424
return tool
425
425
426
- def call_tool (self , * , validate_input : bool = True ):
426
+ def call_tool (self , * , validate_input : bool = True , validate_output : bool = True ):
427
427
"""Register a tool call handler.
428
428
429
429
Args:
430
430
validate_input: If True, validates input against inputSchema. Default is True.
431
+ validate_output: If True, validates output against outputSchema. Default is True.
431
432
432
433
The handler validates input against inputSchema (if validate_input=True), calls the tool function,
433
434
and builds a CallToolResult with the results:
@@ -486,10 +487,11 @@ async def handler(req: types.CallToolRequest):
486
487
"Output validation error: outputSchema defined but no structured output returned"
487
488
)
488
489
else :
489
- try :
490
- jsonschema .validate (instance = maybe_structured_content , schema = tool .outputSchema )
491
- except jsonschema .ValidationError as e :
492
- return self ._make_error_result (f"Output validation error: { e .message } " )
490
+ if validate_output :
491
+ try :
492
+ jsonschema .validate (instance = maybe_structured_content , schema = tool .outputSchema )
493
+ except jsonschema .ValidationError as e :
494
+ return self ._make_error_result (f"Output validation error: { e .message } " )
493
495
494
496
# result
495
497
return types .ServerResult (
You can’t perform that action at this time.
0 commit comments