feat(mcp): forward session ID and plugin _meta to MCP tool calls#21624
feat(mcp): forward session ID and plugin _meta to MCP tool calls#21624Sathvik-1007 wants to merge 1 commit intoanomalyco:devfrom
Conversation
|
The following comment was made by an LLM, it may be inaccurate: I found a related PR that may be a duplicate or predecessor: Related PR Found:
This PR appears to be addressing the same core feature of forwarding metadata ( Why they're related:
You may want to check if PR #21539 is still open and whether #21624 supersedes it or if they should be combined. |
|
Relationship to #21539 This PR supersedes #21539. Same 3 files, same approach. Diff comparison:
Net: this is #21539 + built-in sessionID. If this merges, #21539 can close. cc @moghtader — credit to you for the plugin |
24199a9 to
dd7db23
Compare
Issue for this PR
Closes #6279
Closes #17084
Type of change
What does this PR do?
MCP servers currently have no way to know which opencode session called them. This adds two things:
Built-in session context: opencode now always includes
_meta: { sessionID }in everycallTool()request. MCP servers receive the caller's session ID automatically via the standard MCP_metafield.Plugin-extensible
_meta: thetool.execute.beforehook output now includes an optional_metafield. Plugins can add custom metadata (correlation IDs, trace context, etc.) that gets forwarded to downstream MCP servers alongside the built-in sessionID.When no plugin sets
_meta, MCP servers still receive{ sessionID }. When a plugin adds fields, they merge with the built-in ones.Files changed (3):
packages/opencode/src/mcp/index.ts— read_metafrom execute opts, forward toclient.callTool()packages/opencode/src/session/prompt.ts— seed_metawith{ sessionID }, pass through hook and into executepackages/plugin/src/index.ts— add_metatotool.execute.beforehook output typeHow did you verify your code works?
llm.tserrors are from upstream feat(llm): integrate GitLab DWS tool approval with permission system #19955, present on baredev)Checklist