-
Notifications
You must be signed in to change notification settings - Fork 334
Elicit defaults #644
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+177
−9
Merged
Elicit defaults #644
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
85edee3
mcp/client: elicitation default values
eb22aaf
mcp/client: elicitation default values
27cc3fd
mcp/server.go: use elicitation defaults in server
c4dae13
mcp/mcp_test use map for expected values
69cd55f
mcp/mcp_test: add tests for invalid defaults
ba3ee68
mcp/server.go: remove unecessary reflect on schema
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1015,7 +1015,37 @@ func (ss *ServerSession) Elicit(ctx context.Context, params *ElicitParams) (*Eli | |
| if err := ss.checkInitialized(methodElicit); err != nil { | ||
| return nil, err | ||
| } | ||
| return handleSend[*ElicitResult](ctx, methodElicit, newServerRequest(ss, orZero[Params](params))) | ||
|
|
||
| res, err := handleSend[*ElicitResult](ctx, methodElicit, newServerRequest(ss, orZero[Params](params))) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| if params.RequestedSchema == nil { | ||
| return res, nil | ||
| } | ||
| schema, err := validateElicitSchema(params.RequestedSchema) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| if schema == nil { | ||
| return res, nil | ||
| } | ||
|
|
||
| resolved, err := schema.Resolve(nil) | ||
| if err != nil { | ||
| fmt.Printf(" resolve err: %s", err) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this okay? |
||
| return nil, err | ||
| } | ||
| if err := resolved.Validate(res.Content); err != nil { | ||
| return nil, fmt.Errorf("elicitation result content does not match requested schema: %v", err) | ||
| } | ||
| err = resolved.ApplyDefaults(&res.Content) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to apply schema defalts to elicitation result: %v", err) | ||
| } | ||
|
|
||
| return res, nil | ||
| } | ||
|
|
||
| // Log sends a log message to the client. | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
wireSchemato 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 anilvalue for this which gets wrapped in another pointer. so, in the server,wireschemais non-nil but*wireschemais nil. This means we end up passing a non-nil wireschema here, but it is unmarshalling aniljsonschema.This means that when we get back here since we passed
&schemainto remarshall nowschemais 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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
anyfor the schema).I think the code, as written, is fine.