Wrap read_mcp_resource output with wrapUntrusted() for consistency with mcp-tool#27979
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request improves the security posture of the MCP resource reading tool by applying consistent untrusted-content signaling. By wrapping resource output with wrapUntrusted(), the system ensures that third-party data is handled with the same security context as other tool invocations, preventing potential issues with unvalidated model inputs. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
|
📊 PR Size: size/S
|
🛑 Action Required: Evaluation ApprovalSteering changes have been detected in this PR. To prevent regressions, a maintainer must approve the evaluation run before this PR can be merged. Maintainers:
Once approved, the evaluation results will be posted here automatically. |
There was a problem hiding this comment.
Code Review
This pull request updates the ReadMcpResourceTool to wrap the retrieved resource content in wrapUntrusted before returning it as llmContent. The corresponding unit tests in read-mcp-resource.test.ts have also been updated to reflect this change. There are no review comments to address, and I have no feedback to provide.
|
@googlebot I signed it! |
read_mcp_resource returned MCP-server-supplied resource text to the model without the untrusted-context wrapper that sibling tools apply. mcp-tool.ts already wraps the same kind of MCP content via wrapUntrusted() (resource text and text blocks); this makes read-mcp-resource consistent so MCP resource content is marked as untrusted context rather than trusted input. Updates the tests to cover the wrapped output.
9a37b80 to
e9c94ca
Compare
Resolves #27983
What
Wrap the resource text returned by
read_mcp_resourcewithwrapUntrusted()before it is passed to the model, and update the tests accordingly.Why
ReadMcpResourceToolInvocationreturns MCP-server-supplied resource text directly asllmContent, while the sibling MCP path inmcp-tool.tsalready wraps the same class of content withwrapUntrusted()(resource text and text blocks). MCP resource content is third-party / untrusted input, so todayread_mcp_resourceoutput reaches the model without the untrusted-context signal that every other tool applies. This change makes the two code paths consistent.Changes
packages/core/src/tools/read-mcp-resource.ts: importwrapUntrustedand wrap non-emptycontentText(the empty-content fallback message is unchanged).packages/core/src/tools/read-mcp-resource.test.ts: assertions updated to expect the wrapped output.Testing
npx vitest run src/tools/read-mcp-resource.test.tsinpackages/core→ 5/5 passing.prettier --checkandeslintare clean on the changed files.Prepared with AI assistance; reviewed and tested locally.