Conversation
Comment on lines
996
to
1006
| required = set(schema.get("required", [])) | ||
|
|
||
| fields: dict[str, Any] = {} | ||
| for field_name, field_def in properties.items(): | ||
| if field_name.startswith("_") or not isinstance(field_def, dict): | ||
| continue | ||
| if not isinstance(field_def, dict): | ||
| raise ValueError( | ||
| f"Invalid property schema for '{field_name}': expected an object." | ||
| ) | ||
|
|
||
| field_type_str = field_def.get("type", "string") | ||
| python_type = JSON_TYPE_MAP.get(field_type_str, str) |
There was a problem hiding this comment.
Bug: The new _validate_response_schema function allows underscore-prefixed field names, but Pydantic's create_model later silently ignores them, leading to unexpected data loss.
Severity: MEDIUM
Suggested Fix
Update the _validate_response_schema function to iterate through the properties in the schema and explicitly raise a ValueError if any field name starts with an underscore, similar to how other schema validations are performed.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.
Location: everyrow-mcp/src/everyrow_mcp/server.py#L992-L1006
Potential issue: The new validation function `_validate_response_schema` does not
prohibit field names that start with an underscore. While the old code explicitly
skipped these fields, the new logic allows them to pass validation. However, the
downstream call to Pydantic's `create_model` in `_schema_to_model` will silently ignore
any fields prefixed with an underscore, only issuing a `RuntimeWarning`. This
discrepancy means a schema with a field like `_internal_id` will be considered valid,
but the corresponding data will not be captured, resulting in silent data loss.
Did we get this right? 👍 / 👎 to inform future reviews.
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
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.
This validates that the response schema passed to the MCP tools is valid JSON schema. It needs to look like
This is not allowed
To be clear, the second format has never been allowed. But now the MCP server will yell at you if you try to use it. Previously it would have silently turned your schema into the empty one, which meant you'd get no results.
I also updated the documentation a bit to try to clarify this.