Skip to content

Update mcp's list function to check for disablement.#21148

Merged
DavidAPierce merged 13 commits intomainfrom
mcp_exclude_update
Mar 9, 2026
Merged

Update mcp's list function to check for disablement.#21148
DavidAPierce merged 13 commits intomainfrom
mcp_exclude_update

Conversation

@DavidAPierce
Copy link
Contributor

@DavidAPierce DavidAPierce commented Mar 4, 2026

Summary

modified packages/cli/src/commands/mcp/list.ts to integrate the canLoadServer function which enforces mcp.excluded rules, as well as checking against mcp.allowed and the user's manual enable/disable settings from McpServerEnablementManager.

Details

Imported canLoadServer and McpServerEnablementManager into list.ts.
Updated the getServerStatus function to consult canLoadServer before attempting testMCPConnection.
Added string enums BLOCKED and DISABLED to the return type MCPServerStatus of getServerStatus to accurately represent servers that shouldn't be loaded without actually connecting to them.
Updated listMcpServers to correctly display the output string using chalk colors for Blocked and Disabled states.
Adjusted packages/cli/src/commands/mcp/list.test.ts to mock the necessary Storage parameters and cover the new Blocked functionality explicitly. The test suite passes fully without attempting RCE on excluded servers.

Related Issues

Fixes https://github.com/google-gemini/maintainers-gemini-cli/issues/1442

@DavidAPierce DavidAPierce requested a review from a team as a code owner March 4, 2026 20:18
@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 significantly enhances the mcp list command by integrating robust server enablement checks. It ensures that the CLI accurately reflects the status of Model Context Protocol (MCP) servers, not just their connection state, but also whether they are allowed to load based on administrative configurations (mcp.excluded, mcp.allowed) and user-defined enablement settings. This prevents attempts to connect to servers that are explicitly disallowed, improving efficiency and adherence to policy.

Highlights

  • Enhanced Server Status Checks: Integrated the canLoadServer function into the mcp list command to enforce mcp.excluded, mcp.allowed rules, and user-defined enablement settings before attempting server connections.
  • New Server Statuses: Introduced BLOCKED and DISABLED states to the MCPServerStatus enum, providing more granular reporting for servers that are disallowed by configuration or user settings.
  • Improved CLI Output: Updated the mcp list command to display Blocked and Disabled servers with distinct chalk colors, enhancing readability and user understanding.
  • Expanded Test Coverage: Added new unit tests to list.test.ts specifically covering the Blocked server functionality, ensuring robustness and preventing connection attempts to excluded servers.
Changelog
  • packages/cli/src/commands/mcp/list.test.ts
    • Imported McpServerEnablementManager for testing enablement logic.
    • Added a mock for getGlobalGeminiDir to simulate the global Gemini directory path.
    • Reset McpServerEnablementManager instance and mocked isFileEnabled in beforeEach to control enablement behavior.
    • Added a new test case to verify the display of Blocked status for servers in the excluded list.
  • packages/cli/src/commands/mcp/list.ts
    • Imported canLoadServer and McpServerEnablementManager to perform server enablement checks.
    • Modified getServerStatus to utilize canLoadServer and return BLOCKED or DISABLED statuses based on the check results.
    • Updated listMcpServers to include display logic for BLOCKED and DISABLED statuses using chalk for colored output.
  • packages/core/src/tools/mcp-client.ts
    • Extended the MCPServerStatus enum with new BLOCKED and DISABLED states to represent additional server conditions.
Activity
  • No specific activity (comments, reviews, or progress updates) has been provided in the context for this pull request.
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 implements disablement checks for MCP servers in the list command, preventing connections to blocked or disabled servers. The changes are logical and include corresponding test updates. However, I've identified a significant performance issue where settings are loaded repeatedly within a loop, which should be addressed, aligning with the guideline to gather all settings first for initialization.

@github-actions
Copy link

github-actions bot commented Mar 4, 2026

Size Change: +1.33 kB (+0.01%)

Total Size: 26 MB

Filename Size Change
./bundle/gemini.js 25.6 MB +1.33 kB (+0.01%)
ℹ️ View Unchanged
Filename Size
./bundle/node_modules/@google/gemini-cli-devtools/dist/client/main.js 221 kB
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/_client-assets.js 227 kB
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/index.js 11.5 kB
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/types.js 132 B
./bundle/sandbox-macos-permissive-open.sb 890 B
./bundle/sandbox-macos-permissive-proxied.sb 1.31 kB
./bundle/sandbox-macos-restrictive-open.sb 3.36 kB
./bundle/sandbox-macos-restrictive-proxied.sb 3.56 kB
./bundle/sandbox-macos-strict-open.sb 4.82 kB
./bundle/sandbox-macos-strict-proxied.sb 5.02 kB

compressed-size-action

@gemini-cli gemini-cli bot added the priority/p2 Important but can be addressed in a future release. label Mar 4, 2026
@gemini-cli gemini-cli bot added the status/need-issue Pull requests that need to have an associated issue. label Mar 5, 2026
@galz10
Copy link
Collaborator

galz10 commented Mar 5, 2026

If i follow the instructions in https://github.com/google-gemini/maintainers-gemini-cli/issues/1442 i get two MCPs in the list

image

@galz10 galz10 self-requested a review March 6, 2026 18:52
@DavidAPierce DavidAPierce enabled auto-merge March 9, 2026 15:32
@DavidAPierce DavidAPierce added this pull request to the merge queue Mar 9, 2026
Merged via the queue into main with commit e7b20c4 Mar 9, 2026
27 checks passed
@DavidAPierce DavidAPierce deleted the mcp_exclude_update branch March 9, 2026 18:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority/p2 Important but can be addressed in a future release. status/need-issue Pull requests that need to have an associated issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants