Skip to content

Commit 65c9d54

Browse files
committed
feat: add support for disabling output validation for tools
1 parent 6a84a2f commit 65c9d54

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/mcp/server/lowlevel/server.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -423,11 +423,12 @@ async def _get_cached_tool_definition(self, tool_name: str) -> types.Tool | None
423423

424424
return tool
425425

426-
def call_tool(self, *, validate_input: bool = True):
426+
def call_tool(self, *, validate_input: bool = True, validate_output: bool = True):
427427
"""Register a tool call handler.
428428
429429
Args:
430430
validate_input: If True, validates input against inputSchema. Default is True.
431+
validate_output: If True, validates output against outputSchema. Default is True.
431432
432433
The handler validates input against inputSchema (if validate_input=True), calls the tool function,
433434
and builds a CallToolResult with the results:
@@ -486,10 +487,11 @@ async def handler(req: types.CallToolRequest):
486487
"Output validation error: outputSchema defined but no structured output returned"
487488
)
488489
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}")
493495

494496
# result
495497
return types.ServerResult(

0 commit comments

Comments
 (0)