Skip to content

Commit 5b75167

Browse files
committed
add validate_input flag to @server.call_tool
1 parent 93bd16f commit 5b75167

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/mcp/server/lowlevel/server.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -417,10 +417,13 @@ async def _get_cached_tool_definition(self, tool_name: str) -> types.Tool | None
417417

418418
return tool
419419

420-
def call_tool(self):
420+
def call_tool(self, *, validate_input: bool = True):
421421
"""Register a tool call handler.
422422
423-
The handler validates input against inputSchema, calls the tool function,
423+
Args:
424+
validate_input: If True, validates input against inputSchema. Default is True.
425+
426+
The handler validates input against inputSchema (if validate_input=True), calls the tool function,
424427
and builds a CallToolResult with the results:
425428
- Unstructured content (iterable of ContentBlock): returned in content
426429
- Structured content (dict): returned in structuredContent, serialized JSON text returned in content
@@ -444,7 +447,7 @@ async def handler(req: types.CallToolRequest):
444447
tool = await self._get_cached_tool_definition(tool_name)
445448

446449
# input validation
447-
if tool:
450+
if validate_input and tool:
448451
try:
449452
jsonschema.validate(instance=arguments, schema=tool.inputSchema)
450453
except jsonschema.ValidationError as e:

0 commit comments

Comments
 (0)