Fix isZodRawShape
return false on empty object and add test
#448
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.
Fix
isZodRawShape
implementation to properly handle the empty object and add the test.Close #453
Motivation and Context
The
isZodRawShape
type guard function was incorrectly returning false for the empty object. This caused issues when trying to register tools with empty parameters. The fix ensures that empty objects are correctly identified as valid ZodRawShape instances, which allows for proper tool registration with empty parameter schemas.How Has This Been Tested?
Added a new test case in
mcp.test.ts
that specifically tests registering a tool with an empty parameters object. The test verifies that the tool is correctly registered with an empty object schema and that the proper annotations are applied.Additionally, manual testing regarding types accept by
ZodRawShape
was done with a simple test snippet:Breaking Changes
None. This is a bug fix that maintains backward compatibility.
Types of changes
Checklist
Additional context
The fix modifies the
isZodRawShape
type guard to explicitly handle empty objects as valid ZodRawShape instances. This is done by using Zod's own validation to check if the object is an empty object. If it is, we consider it a valid ZodRawShape. Otherwise, we fall back to the original check which verifies if any property is a ZodType instance.The issue was particularly important for tools that don't require any parameters but still need to be properly registered with the MCP server.