Skip to content

bug: Tool struct missing UnmarshalJSON method prevents clients from receiving outputSchema #563

@JoeyLearnsToCode

Description

@JoeyLearnsToCode

Problem Description

The Tool struct implements a custom MarshalJSON method that correctly serializes the RawOutputSchema field as outputSchema in JSON tools.go:569-600 . However, it lacks a corresponding UnmarshalJSON method, preventing clients from deserializing the server's outputSchema field back into RawOutputSchema during response unmarshaling.
Tool 结构体实现了自定义的 MarshalJSON 方法 tools.go:571-600 ,能够正确将 RawOutputSchema 字段序列化为 JSON 中的 outputSchema 字段 tools.go:593-595 。但是缺少对应的 UnmarshalJSON 方法,导致客户端在反序列化服务端响应时无法将 outputSchema 字段保存到 RawOutputSchema 中。

Steps to Reproduce

  1. Server creates a tool with WithOutputSchemaT tools.go:707-734
  2. Client calls Client.ListTools() to retrieve tool list
  3. Server correctly returns JSON containing outputSchema field
  4. Client unmarshals response, but RawOutputSchema marked as json:"-" causes outputSchema field to be ignored tools.go:559

Expected Behavior

Clients should be able to receive and store the server's returned outputSchema information in the Tool.RawOutputSchema field.

Suggested Solution

Implement an UnmarshalJSON method for the Tool struct, following the pattern used in CallToolResult.UnmarshalJSON tools.go:497-537 :

Parse the outputSchema field from JSON
Store it in the RawOutputSchema field
Handle inputSchema deserialization logic
Process other fields normally

Impact

Clients cannot access tool output schema information
Affects structured output functionality completeness
Creates serialization/deserialization asymmetry

Notes

This issue wasn't caught in testing because existing tests focus on serialization behavior tools_test.go:532-562 , while TestUnmarshalToolWithRawSchema only covers inputSchema deserialization tools_test.go:78-119 . Test cases for outputSchema deserialization should be added.

The issue stems from the asymmetric implementation where Tool has custom marshaling logic but lacks corresponding unmarshaling logic, creating a one-way data flow that prevents clients from accessing output schema information sent by servers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions