Skip to content

feat: Enable tool handlers to use "_meta" from req#56

Merged
jpmcb merged 1 commit intomainfrom
optional-meta-for-tools
Nov 25, 2025
Merged

feat: Enable tool handlers to use "_meta" from req#56
jpmcb merged 1 commit intomainfrom
optional-meta-for-tools

Conversation

@jpmcb
Copy link
Contributor

@jpmcb jpmcb commented Nov 25, 2025

This patch enables a tool handler to accept an optional _meta argument: this is in support of the OpenAI apps sdk which recommends passing UI widget state along in the tool call/resp _meta field. This ensures that clients don't have to pass along all the content or structuredContent to the LLM.

Notice in the examples/servers/apps-sdk, this now uses _meta for the todo list's full state and the structuredContent now carries only the current todos.

Copilot AI review requested due to automatic review settings November 25, 2025 21:05
Signed-off-by: John McBride <john@zuplo.com>
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR enables tool handlers to accept an optional _meta parameter from tool call requests, supporting the OpenAI Apps SDK pattern where UI widget state is passed via _meta rather than in the content shown to the LLM.

Key Changes:

  • Updated handler signatures in ToolConfig and RegisteredTool to accept optional _meta parameter
  • Modified handleToolCallRequest to pass toolCallReq.params._meta to tool handlers
  • Updated the apps-sdk example to demonstrate returning full state in _meta while keeping structuredContent minimal (non-completed todos only)

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
src/tools/types.ts Added optional _meta parameter to handler signature in ToolConfig
src/server/types.ts Added optional _meta parameter to handler signature in RegisteredTool
src/server/index.ts Modified handleToolCallRequest to pass _meta from request to handler
examples/servers/apps-sdk/src/index.ts Updated todo app example to return full state in _meta and filtered todos in structuredContent

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

name: string;
validator: V;
handler: (params: ParsedData<V>) => Promise<R> | R;
handler: (params: ParsedData<V>, _meta?: object) => Promise<R> | R;
Copy link

Copilot AI Nov 25, 2025

Choose a reason for hiding this comment

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

The _meta parameter type in the handler signature is object | undefined, but according to the schema definition in src/jsonrpc2/schemas/request.ts, toolCallReq.params._meta is typed as RequestMeta | undefined (which has a progressToken?: string | number field and allows additional properties via .loose()). This type mismatch could lead to type safety issues.

Consider updating the handler signature to use a more specific type that matches the schema, or explicitly document why the generic object type is used here.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We're not really supporting progressToken in any meaningful way: this simply passes along the object to the called handler and it can do something with it / infer the progressToken itself

@jpmcb jpmcb merged commit 2fd454b into main Nov 25, 2025
4 checks passed
@jpmcb jpmcb deleted the optional-meta-for-tools branch November 25, 2025 21:18
@franz-zuplo
Copy link
Contributor

LGTM!

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