File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -103,6 +103,39 @@ func (t Tool) MarshalJSON() ([]byte, error) {
103103 return json .Marshal (m )
104104}
105105
106+
107+ // UnmarshalJSON implements the json.Unmarshaler interface for Tool.
108+ // It handles unmarshaling InputSchema while supporting raw schema formats.
109+ func (t * Tool ) UnmarshalJSON (b []byte ) error {
110+ // Temporary structure for decoding
111+ var raw struct {
112+ Name string `json:"name"`
113+ Description string `json:"description"`
114+ InputSchema json.RawMessage `json:"inputSchema"`
115+ }
116+
117+ // Unmarshal into the temporary structure
118+ if err := json .Unmarshal (b , & raw ); err != nil {
119+ return err
120+ }
121+
122+ // Assign name and description
123+ t .Name = raw .Name
124+ t .Description = raw .Description
125+
126+ // Try to unmarshal InputSchema into structured format
127+ var schema ToolInputSchema
128+ if err := json .Unmarshal (raw .InputSchema , & schema ); err == nil {
129+ // Successfully parsed structured schema
130+ t .InputSchema = schema
131+ t .RawInputSchema = nil
132+ } else {
133+ return err
134+ }
135+
136+ return nil
137+ }
138+
106139type ToolInputSchema struct {
107140 Type string `json:"type"`
108141 Properties map [string ]interface {} `json:"properties,omitempty"`
You can’t perform that action at this time.
0 commit comments