Skip to content

fix(mcp): align tools/list namespace with aliased services#165

Open
abhinavkale-dev wants to merge 3 commits intogoogleworkspace:mainfrom
abhinavkale-dev:fix-mcp-alias-tools-mismatch
Open

fix(mcp): align tools/list namespace with aliased services#165
abhinavkale-dev wants to merge 3 commits intogoogleworkspace:mainfrom
abhinavkale-dev:fix-mcp-alias-tools-mismatch

Conversation

@abhinavkale-dev
Copy link

Fixes #162.

Summary

When gws mcp is started with aliased services (for example -s events), tools/list previously returned Discovery-prefixed names (for example workspaceevents_*) while tools/call validated alias prefixes (for example events_*).
This made listed tools uncallable in the same MCP session.

This PR makes tools/list use the configured service alias prefix so tools/list and tools/call share the same namespace.

What changed

  • Updated src/mcp_server.rs:
    • build_tools_list now prefixes tool names with svc_name (configured alias) instead of doc.name.
  • Added regression tests in src/mcp_server.rs:
    • build_tools_list_uses_alias_prefixes_for_aliased_services
    • handle_tools_call_rejects_discovery_prefix_when_alias_is_enabled
  • Added changeset:
    • .changeset/fix-mcp-alias-tools-mismatch.md

Checklist:

  • My code follows the AGENTS.md guidelines (no generated google-* crates).
  • I have run cargo fmt --all to format the code perfectly.
  • I have run cargo clippy -- -D warnings and resolved all warnings.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have provided a Changeset file (e.g. via pnpx changeset) to document my changes.

@changeset-bot
Copy link

changeset-bot bot commented Mar 5, 2026

🦋 Changeset detected

Latest commit: 569af9e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@googleworkspace/cli Patch

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

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, 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 addresses a critical inconsistency in the gws mcp command's handling of aliased services. Previously, tools/list would present tool names using their original Discovery-prefixed names, while tools/call expected the configured alias prefix, rendering listed tools uncallable. The changes ensure that both commands operate within the same namespace by making tools/list use the service alias prefix, thereby unifying the tool naming convention and enabling aliased tools to function as expected.

Highlights

  • Tool Naming Consistency: The build_tools_list function now correctly uses the configured service alias (svc_name) instead of the Discovery document's default name (doc.name) when generating tool names, ensuring consistency with tools/call.
  • Regression Tests Added: New regression tests were introduced to verify that tools/list utilizes alias prefixes for aliased services and that tools/call properly rejects Discovery prefixes when an alias is active, preventing future regressions.
  • Changelog Entry: A new changeset file (.changeset/fix-mcp-alias-tools-mismatch.md) was added to document this fix for the MCP alias tool namespace mismatch.
Changelog
  • .changeset/fix-mcp-alias-tools-mismatch.md
    • Added a new changeset entry describing the fix for the MCP alias tool namespace mismatch.
  • src/mcp_server.rs
    • Modified the build_tools_list function to use the service alias name (svc_name) for tool prefixes instead of the Discovery document's name.
    • Introduced new test cases (build_tools_list_uses_alias_prefixes_for_aliased_services and handle_tools_call_rejects_discovery_prefix_when_alias_is_enabled) to validate the correct behavior of aliased services.
Activity
  • No specific activity (comments, reviews, progress updates) has been recorded for this pull request yet.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly aligns the tool names generated by tools/list with the aliases expected by tools/call, fixing a key usability issue in MCP sessions with aliased services. The change is simple and effective. The addition of regression tests is excellent, ensuring this issue does not reappear. I've left a couple of minor suggestions in the test code to remove unnecessary unsafe blocks for better code clarity and adherence to Rust's safety principles.

Comment on lines +489 to +495
unsafe {
if let Some(old) = &self.old {
std::env::set_var(self.key, old);
} else {
std::env::remove_var(self.key);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The unsafe block here is unnecessary. Neither std::env::set_var nor std::env::remove_var are unsafe functions. While modifying environment variables is not thread-safe, the #[serial_test::serial] attribute already ensures these tests run sequentially, mitigating the risk of data races. Using unsafe for operations that are not memory-unsafe can be misleading.

            if let Some(old) = &self.old {
                std::env::set_var(self.key, old);
            } else {
                std::env::remove_var(self.key);
            }

Comment on lines +501 to +503
unsafe {
std::env::set_var(key, value);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Similar to the drop implementation, this unsafe block is not necessary because std::env::set_var is a safe function. The #[serial_test::serial] attribute handles the thread-safety concerns for these tests.

        std::env::set_var(key, value);

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.

MCP tools/list returns uncallable tool names for aliased services (events, apps-script, admin-reports)

1 participant