feat(mcp): add compact tool mode to reduce context window usage#172
feat(mcp): add compact tool mode to reduce context window usage#172jpoehnelt merged 9 commits intogoogleworkspace:mainfrom
Conversation
Gmail and other APIs use nested resources (e.g., users.messages, users.threads under users). The compact tool descriptions and gws_discover Level 1/2/3 now recursively traverse the resource tree using dot-separated paths, exposing all sub-resources correctly.
MCP spec requires tool execution errors to be returned as successful results with isError: true. Returning JSON-RPC protocol errors causes clients like Claude Desktop to show generic "Tool execution failed" with no detail about the actual error (auth failures, validation, etc).
🦋 Changeset detectedLatest commit: 2acfdd5 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
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 introduces a new 'compact' tool mode for the Highlights
Changelog
Activity
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 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 counter productive. 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. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a compact tool mode for mcp to significantly reduce the context window usage by AI clients, which is a valuable optimization. However, a security vulnerability related to path traversal was identified in the file upload sanitization logic. The current check to restrict file uploads to the current directory is insufficient on Windows, potentially allowing an attacker to read arbitrary files on the same drive. A more robust component-based validation is suggested to address this. Additionally, there are a few suggestions to improve code clarity and follow idiomatic Rust practices, particularly in a helper function and the new test cases.
- Replace std::slice::from_ref with &[svc_name.to_string()] for consistency - Simplify find_resource using idiomatic iterator pattern - Use #[tokio::test] instead of manual Runtime::new().block_on()
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #172 +/- ##
==========================================
+ Coverage 55.19% 55.85% +0.66%
==========================================
Files 38 38
Lines 13166 13627 +461
==========================================
+ Hits 7267 7612 +345
- Misses 5899 6015 +116 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Summary
Addresses #82 — MCP tool count optimization.
When using
gws mcp -s all, the current behavior generates 200-400 tool definitions (one per API method) that permanently occupy 40-100K tokens in the AI client's context window. Most conversations only use 3-5 methods.This PR adds a
--tool-mode compact|fullflag:full(default): unchanged behavior, one tool per API methodcompact: one tool per service + agws_discovermeta-tool for schema queriesCompact mode details
resourceandmethodargumentsgws_discoverprovides three-level schema query: service → resources → methods → full parameter schemausers.messages,users.threads) are recursively discovered via dot-separated pathsisError: trueresults instead of JSON-RPC protocol errors, so clients display actual error messagesContext budget comparison
fullwith-s allcompactwith-s allUsage
Test Plan