-
Notifications
You must be signed in to change notification settings - Fork 733
fix: marshal ToolInputSchema.Properties
to {} when len=0
#225
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
Conversation
""" WalkthroughA custom Changes
Assessment against linked issues
Possibly related PRs
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 0
🧹 Nitpick comments (1)
mcp/tools.go (1)
116-131
: Implementation meets the PR objective, but has a few minor issues.The added
MarshalJSON
method properly ensures thatProperties
is serialized as{}
rather thannull
when empty, which solves the stated issue in the PR objectives. The implementation appropriately includes custom logic for all fields, correctly maintaining the behavior of theomitempty
tag for theRequired
field.However, there are a couple of minor issues to address:
- There's a typo in the comment on line 121: "euqals" should be "equals"
- The indentation is inconsistent - lines 118-120 use spaces while the rest of the method uses tabs
// MarshalJSON implements the json.Marshaler interface for ToolInputSchema. func (tis ToolInputSchema) MarshalJSON() ([]byte, error) { - m := make(map[string]interface{}) - m["type"] = tis.Type - - // Marshal Properties to '{}' rather than `nil` when its length euqals zero + m := make(map[string]interface{}) + m["type"] = tis.Type + + // Marshal Properties to '{}' rather than `nil` when its length equals zero if tis.Properties != nil { m["properties"] = tis.Properties } if len(tis.Required) > 0 { m["required"] = tis.Required } return json.Marshal(m) }
Fix: #224
Related: #116
This PR customize function
MarshalJSON()
forToolInputSchema
which ensures that we could marshalProperties
to{}
rather thannull
when a Tool's input argument is emptyHow about deleting the
omitempty
field ?From #116, I think
omitempty
is necessary so that clients such as claude-desktop could work.Summary by CodeRabbit