Skip to content

fix(protocol): JSON Schema type union for remote tool schemas (#198)#199

Merged
jesse-engineer merged 4 commits into
ThinkInAIXYZ:mainfrom
jesse-engineer:fix/issue-198-json-schema-union-type
Apr 16, 2026
Merged

fix(protocol): JSON Schema type union for remote tool schemas (#198)#199
jesse-engineer merged 4 commits into
ThinkInAIXYZ:mainfrom
jesse-engineer:fix/issue-198-json-schema-union-type

Conversation

@jesse-engineer
Copy link
Copy Markdown
Collaborator

Summary

Remote MCP servers may emit JSON Schema where the type keyword is an array (e.g. ["string","number"]). The previous Property model used a single DataType, so ListTools responses failed to unmarshal with:

cannot unmarshal array into ... type protocol.DataType

Changes

  • Introduce PropertyType ([]DataType) with MarshalJSON / UnmarshalJSON accepting either a string or an array of strings.
  • Extend validate so multiple declared types are treated as a union (OR).
  • Update tests and add TestInputSchema_JSON_unionType / Test_validate_unionType.

Related

Fixes #198

Made with Cursor

Property.Type is now PropertyType ([]DataType) with custom JSON
marshal/unmarshal so remote tool schemas like type: ["string","number"]
decode correctly (e.g. MCP ListTools). Validation treats multiple types as a union.

Adds regression tests for unmarshaling and union validation.

Fixes ThinkInAIXYZ#198

Made-with: Cursor
…schema-union-type

Resolve test conflicts: PropertyType + []any enums; fix middleware example Property literals.

Made-with: Cursor
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 16, 2026

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 56.00000% with 22 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
protocol/schema_generate.go 47.36% 16 Missing and 4 partials ⚠️
protocol/schema_validate.go 83.33% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

…SON decode

Cover union type arrays on nested properties and schemas containing $ref
so ListToolsResult unmarshaling stays compatible with remote servers.

Made-with: Cursor
Replace slices.Equal with a small equalPropertyType helper; std slices
requires Go 1.21+.

Made-with: Cursor
@jesse-engineer jesse-engineer merged commit 1e331d3 into ThinkInAIXYZ:main Apr 16, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] not support umarshal ref type

2 participants