-
Notifications
You must be signed in to change notification settings - Fork 812
feat(mcptoolset): surface elicitation and tool result _meta #1168
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -147,9 +147,7 @@ func (t *mcpTool) Run(ctx agent.Context, args any) (map[string]any, error) { | |
| } | ||
|
|
||
| if res.StructuredContent != nil { | ||
| return map[string]any{ | ||
| "output": res.StructuredContent, | ||
| }, nil | ||
| return functionResponse(res, res.StructuredContent), nil | ||
| } | ||
|
|
||
| textResponse := strings.Builder{} | ||
|
|
@@ -169,9 +167,22 @@ func (t *mcpTool) Run(ctx agent.Context, args any) (map[string]any, error) { | |
| return nil, errors.New("no text content in tool response") | ||
| } | ||
|
|
||
| return map[string]any{ | ||
| "output": textResponse.String(), | ||
| }, nil | ||
| return functionResponse(res, textResponse.String()), nil | ||
| } | ||
|
|
||
| // functionResponse builds the function response map for a tool result. | ||
| // The result's _meta field is preserved under the "_meta" key, mirroring the | ||
| // raw MCP serialization, so that metadata attached by the server (e.g. auth | ||
| // challenges from MCP gateways) reaches callbacks and the embedding | ||
| // application instead of being silently dropped. | ||
|
Contributor
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. Small doc clarification: this map is the function response returned to the model, so |
||
| func functionResponse(res *mcp.CallToolResult, output any) map[string]any { | ||
| response := map[string]any{ | ||
| "output": output, | ||
| } | ||
| if len(res.Meta) > 0 { | ||
| response["_meta"] = map[string]any(res.Meta) | ||
| } | ||
| return response | ||
| } | ||
|
|
||
| var ( | ||
|
|
||
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.
The capability branch is gated on either handler being set, but only
ElicitationHandlercan actually service an incomingelicitation/create. If a caller sets onlyElicitationCompleteHandler, the client advertises form+URL elicitation yet the SDK rejects the request at runtime with"client does not support elicitation"— and a completion notification can't arrive without a prior elicitation anyway, so this config can't work.Simplest fix is to fail fast in
New, e.g. right after the custom-client check:(Alternatively, gate just the
Capabilities.Elicitationadvertisement oncfg.ElicitationHandler != nil— but since the complete-handler-only case is inert, erroring is clearer.)