#1007·mcp-go

bug: decoded tool schemas drop top-level keywords like $schema and oneOf

Author: po-etCreated Sep 26, 2026Updated Sep 26, 2026

Description

ToolArgumentsSchema, and with it ToolInputSchema and ToolOutputSchema, has fields for type, properties, required, additionalProperties and $defs. Its UnmarshalJSON drops every other top-level keyword, so a tool decoded from tools/list and encoded again loses $schema, $id, title, description, oneOf/anyOf/allOf, if/then/else, vendor extensions and so on.

That hits gateways and proxies built on mcp-go, which list tools from one server and pass them on. Since 2025-11-25 (SEP-1613) the spec has clients and servers validate a schema according to its declared or default dialect. A copy without $schema no longer declares its dialect, and a copy without its top-level oneOf accepts arguments the original rejects. The official conformance client scenario json-schema-2020-12-preservation fails its $schema check for this reason.

I'd suggest an AdditionalFields map[string]any with the json:"-" tag, named like Meta.AdditionalFields: UnmarshalJSON stores the keywords that have no field of their own, MarshalJSON writes them back, and the existing fields win over entries with the same name. Schemas built from Go types or with NewTool wouldn't set it, so their output wouldn't change. I have a PR for it.

Code Sample

go
var tool mcp.Tool
_ = json.Unmarshal([]byte(`{"name": "place_order", "inputSchema": {
	"$schema": "https://json-schema.org/draft/2020-12/schema",
	"title": "Order",
	"type": "object",
	"properties": {"sku": {"type": "string"}, "quantity": {"type": "integer"}},
	"oneOf": [{"required": ["sku"]}, {"required": ["quantity"]}]
}}`), &tool)
out, _ := json.Marshal(tool.InputSchema)
fmt.Println(string(out))

Logs or Error Messages

{"properties":{"sku":{"type":"string"},"quantity":{"type":"integer"}},"required":[],"type":"object"}

Environment

  • mcp-go main (d74db509)