feat(js/plugins/mcp): allow passing context data to the server for to… #2662
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.
feat(js/plugins/mcp): allow passing context data to the server for tool execution
This feature introduces the ability to send Genkit context data to the MCP server when executing tools. This can be useful in scenarios where the MCP server needs access to context information like userId from the Genkit execution environment to properly execute tools.
Description
This commit adds a new optional parameter
sendGenkitContextto theMcpClientOptionsin thegenkitx-mcpplugin. When set totrue, this flag will include the Genkit context data in the_meta.contextfield of theCallToolRequestsent to the MCP server.On the server side, the
GenkitMcpServerhas been updated to optionally receive and utilize this context data. If context data is present in the request, it will be merged with the server's current context and passed to the tool function.Usage Example
To enable sending Genkit context, you can configure the
McpClientOptionswhen initializing the MCP client:When
sendGenkitContextis set totrue, any tool calls made through this MCP client will include the Genkit context.Checklist:
sendGenkitContextoption.