Skip to content

Commit a1eb2d9

Browse files
authored
fix: marshal ToolInputSchema.Properties to {} when len=0 (#225)
1 parent 995569d commit a1eb2d9

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

mcp/tools.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,23 @@ type ToolInputSchema struct {
113113
Required []string `json:"required,omitempty"`
114114
}
115115

116+
// MarshalJSON implements the json.Marshaler interface for ToolInputSchema.
117+
func (tis ToolInputSchema) MarshalJSON() ([]byte, error) {
118+
m := make(map[string]interface{})
119+
m["type"] = tis.Type
120+
121+
// Marshal Properties to '{}' rather than `nil` when its length equals zero
122+
if tis.Properties != nil {
123+
m["properties"] = tis.Properties
124+
}
125+
126+
if len(tis.Required) > 0 {
127+
m["required"] = tis.Required
128+
}
129+
130+
return json.Marshal(m)
131+
}
132+
116133
type ToolAnnotation struct {
117134
// Human-readable title for the tool
118135
Title string `json:"title,omitempty"`

0 commit comments

Comments
 (0)