Skip to content

Commit b939d66

Browse files
committed
implement json.Unmarshaler to CreateMessageResult
1 parent 3ac4ca9 commit b939d66

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

mcp/protocol.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,23 @@ type CreateMessageResult struct {
264264
StopReason string `json:"stopReason,omitempty"`
265265
}
266266

267+
func (r *CreateMessageResult) UnmarshalJSON(data []byte) error {
268+
type result CreateMessageResult // avoid recursion
269+
var wire struct {
270+
result
271+
Content *wireContent `json:"content"`
272+
}
273+
if err := json.Unmarshal(data, &wire); err != nil {
274+
return err
275+
}
276+
var err error
277+
if wire.result.Content, err = contentFromWire(wire.Content, map[string]bool{"text": true, "image": true, "audio": true}); err != nil {
278+
return err
279+
}
280+
*r = CreateMessageResult(wire.result)
281+
return nil
282+
}
283+
267284
type GetPromptParams struct {
268285
// This property is reserved by the protocol to allow clients and servers to
269286
// attach additional metadata to their responses.

0 commit comments

Comments
 (0)