Skip to content

fix: workaround missing empty properties when tool handler input is a…#62

Merged
cgrinds merged 2 commits intomainfrom
cbg-schema
Mar 20, 2026
Merged

fix: workaround missing empty properties when tool handler input is a…#62
cgrinds merged 2 commits intomainfrom
cbg-schema

Conversation

@cgrinds
Copy link
Copy Markdown
Collaborator

@cgrinds cgrinds commented Mar 18, 2026

…n empty struct

See also modelcontextprotocol/go-sdk#693

Comment thread server/server.go
// Check if the tool handlers in param has any fields. If it doesn't, create a schema with an empty properties
// Workaround for https://github.com/modelcontextprotocol/go-sdk/issues/693
typeFor := reflect.TypeFor[In]()
if typeFor.Kind() == reflect.Struct && typeFor.NumField() == 0 {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of NumField, shouldn’t it check VisibleFields? For example: len(reflect.VisibleFields(typeFor)) == 0?

When there is no schema, we currently also include "additionalProperties": false. Does that need to be added as well?

Can typeFor.Kind() be a pointer? If so, that needs to be handled too.

@cgrinds cgrinds merged commit 42b2ce6 into main Mar 20, 2026
18 checks passed
@cgrinds cgrinds deleted the cbg-schema branch March 20, 2026 12:55
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.

2 participants