-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Add schema validation to lowlevel server #1005
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
+1,155
−8
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50311b7
to
fff4cf9
Compare
b9cd587
to
727660f
Compare
ihrpr
previously approved these changes
Jun 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Left some comments about types and clarifying examples
- 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.
- Refactor code to extract _get_tool_definition helper and simplify validation - Update call_tool to support three return types: content only, dict only, or both - Add outputSchema validation that checks structured content matches the schema - Serialize dict-only results to JSON text content - Factor error result construction into _make_error_result helper - Add comprehensive tests for all output validation scenarios The server now validates tool outputs against their defined schemas, providing better error messages and ensuring tool responses match their contracts.
5b75167
to
193b28f
Compare
ihrpr
approved these changes
Jun 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Lowlevel server
inputSchema
@server.call_tool(validate_input=False)
can be used to disable input validationoutputSchema
, if definedMotivation and Context
Previously lowlevel server did no schema validation for tool calls.
How Has This Been Tested?
New tests added, old tests (which now run lowlevel tool calls through schema validation) succeed without change.
Breaking Changes
Possible that some tools defined in the lowlevel server "just worked" against invalid incoming arguments, these will now fail validation.
@server.call_tool(validate_input=False)
can be used in this situation.Types of changes
Checklist
Additional context
In addition to adding validation to the lowlevel server,
FastMCP
delegates to the lowlevel server and will depend on validation being performed here.