-
Notifications
You must be signed in to change notification settings - Fork 718
Open
Description
Description
When using a Java MCP client to call a Go MCP server, the client needs to read the IsError field from the returned CallToolResult.
In the latest version of the code, when IsError is false, this field is not included in the serialized object. It only appears when IsError is true.
Code Sample
// MarshalJSON implements custom JSON marshaling for CallToolResult
func (r CallToolResult) MarshalJSON() ([]byte, error) {
m := make(map[string]any)
// Marshal Meta if present
if r.Meta != nil {
m["_meta"] = r.Meta
}
// Marshal Content array
content := make([]any, len(r.Content))
for i, c := range r.Content {
content[i] = c
}
m["content"] = content
// Marshal IsError if true
if r.IsError {
m["isError"] = r.IsError
}
return json.Marshal(m)
}Logs or Error Messages
Cannot invoke "java.lang.Boolean.booleanValue()" because the return value of "io.modelcontextprotocol.spec.McpSchema$CallToolResult.isError()" is null
Environment
- Go version (see
go.mod): 1.24.3 - mcp-go version (see
go.mod): v0.37.0 - java-mcp version: 0.10.0 https://github.com/modelcontextprotocol/java-sdk
Additional Context
Add any other context about the problem here.
Possible Solution
// MarshalJSON implements custom JSON marshaling for CallToolResult
func (r CallToolResult) MarshalJSON() ([]byte, error) {
m := make(map[string]any)
// Marshal Meta if present
if r.Meta != nil {
m["_meta"] = r.Meta
}
// Marshal Content array
content := make([]any, len(r.Content))
for i, c := range r.Content {
content[i] = c
}
m["content"] = content
// *** fix this ***
m["isError"] = r.IsError
return json.Marshal(m)
}Metadata
Metadata
Assignees
Labels
No labels