Skip to content

Conversation

@markus-kusano
Copy link
Contributor

We also set the defaults in the client.go before sending them to the
server. However, we might be talking to a client that is not doing this
so also set the defaults within the server.
mcp/mcp_test.go Outdated
name string
schema *jsonschema.Schema
expectedKey string
expectedValue any
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe just have want map[string]any, and use cmp.Diff to compare with the content we got?

That allows for more complex tests, and (I think) simplifies the test body.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great idea! I liked that this simplified things and even handled the float comparison out of the box

mcp/mcp_test.go Outdated
expectedKey: "key",
expectedValue: "one",
},
// TODO: should we have a test with number (float) types?
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes please!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

mcp/mcp_test.go Outdated
}
defer cs.Close()

schemas := []struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

'tests'? More than just schemas.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good point, renamed to testcases

@markus-kusano
Copy link
Contributor Author

PTAL

findleyr
findleyr previously approved these changes Nov 20, 2025
Copy link
Contributor

@findleyr findleyr left a comment

Choose a reason for hiding this comment

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

LGTM, pending perhaps a couple more test cases.

We are adding support for defaults for non-boolean types, this adds
tests for invalid values for these new default types.
@markus-kusano
Copy link
Contributor Author

PTAL, I updated the server side to both apply defaults and do validation. I also removed the use of reflect as discussed offline (thanks for the help!)

if err := remarshal(wireSchema, &schema); err != nil {
return nil, err
}
if schema == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is possible? wireShema is non-nil, so wouldn't a nil schema be an error here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

TL;DR: I think we either need a reflect.IsNil() call on wireSchema to determine if it is really nil, or we need to check if the result of remarshall is nil when err is != nil (which feels gross).

In more detail:

In the server, as I understand, the wireschema is **jsonschema. we pass in a nil value for this which gets wrapped in another pointer. so, in the server, wireschema is non-nil but *wireschema is nil. This means we end up passing a non-nil wireschema here, but it is unmarshalling a nil jsonschema.

This means that when we get back here since we passed &schema into remarshall now schema is nil.

It might make remarshall more robust to have a reflect isNil call and return an err, but then we'd need to add in the reflect call.

Copy link
Contributor

Choose a reason for hiding this comment

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

On the server the schema should be a *jsonschema.Schema, not a **jsonschema.Schema. Where are you seeing this?

Let's merge this as-is, and I will take a look.

Copy link
Contributor

Choose a reason for hiding this comment

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

BTW, I looked into it: the test uses a typed nil (one of the downsides of having any for the schema).

I think the code, as written, is fine.

@findleyr findleyr merged commit d9263f7 into main Nov 21, 2025
8 checks passed
starlit-cartographer pushed a commit to starlit-cartographer/go-sdk that referenced this pull request Nov 23, 2025

resolved, err := schema.Resolve(nil)
if err != nil {
fmt.Printf(" resolve err: %s", err)
Copy link

Choose a reason for hiding this comment

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

Is this okay?

@findleyr findleyr deleted the elicit-defaults branch January 10, 2026 21:18
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.

4 participants