Skip to content

Commit 9c5d303

Browse files
authored
fix CallToolResult json marshaling and unmarshaling: need structuredC… (#523)
* fix CallToolResult json marshaling and unmarshaling: need structuredContent . * golang json use float to store number type * fix unittest: use NewMetaFromMap to create Result.Meta * mcptest: add a test case to response stuctured content * move after TestServerWithTool * fix unittest: no need check meta
1 parent 9393526 commit 9c5d303

File tree

4 files changed

+666
-1
lines changed

4 files changed

+666
-1
lines changed

mcp/tools.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,11 @@ func (r CallToolResult) MarshalJSON() ([]byte, error) {
486486
}
487487
m["content"] = content
488488

489+
// Marshal StructuredContent if present
490+
if r.StructuredContent != nil {
491+
m["structuredContent"] = r.StructuredContent
492+
}
493+
489494
// Marshal IsError if true
490495
if r.IsError {
491496
m["isError"] = r.IsError
@@ -526,6 +531,11 @@ func (r *CallToolResult) UnmarshalJSON(data []byte) error {
526531
}
527532
}
528533

534+
// Unmarshal StructuredContent if present
535+
if structured, ok := raw["structuredContent"]; ok {
536+
r.StructuredContent = structured
537+
}
538+
529539
// Unmarshal IsError
530540
if isError, ok := raw["isError"]; ok {
531541
if isErrorBool, ok := isError.(bool); ok {

0 commit comments

Comments
 (0)