Skip to content

fix: correct MCP tool cache check operator precedence#628

Open
MarvelNwachukwu wants to merge 2 commits intomainfrom
fix-mcp-tool-cache-check
Open

fix: correct MCP tool cache check operator precedence#628
MarvelNwachukwu wants to merge 2 commits intomainfrom
fix-mcp-tool-cache-check

Conversation

@MarvelNwachukwu
Copy link
Contributor

@MarvelNwachukwu MarvelNwachukwu commented Mar 19, 2026

Description

Why this matters: When connecting to external tool servers (MCP), ADK caches the list of available tools so it doesn't have to re-fetch them every time. A typo-level bug meant this cache was silently broken — tools were being re-fetched on every call, adding unnecessary latency and server load.

What changed: Fixed a single operator precedence issue (!x === falsex !== false) that was preventing the cache from ever being used.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)

How Has This Been Tested?

All existing tests pass (478 tests). Build succeeds without errors.

Checklist

  • My code follows the code style of this project
  • All new and existing tests passed
  • My changes generate no new warnings

Changed `!this.config.cacheConfig?.enabled === false` to
`this.config.cacheConfig?.enabled !== false` to fix operator precedence bug.
The original expression never evaluated to true, preventing the cache from
being used in the default case when cacheConfig is undefined. This matches
the correct pattern already used elsewhere in the file.
@vercel
Copy link
Contributor

vercel bot commented Mar 19, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
adk-typescript-docs Ready Ready Preview Mar 19, 2026 3:40pm
adk-web Ready Ready Preview Mar 19, 2026 3:40pm

Request Review

@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 bug where the MCP tool's cache was not being utilized as intended due to an operator precedence error in its configuration check. The fix ensures that the cache enablement logic evaluates correctly, restoring expected caching behavior and improving performance.

Highlights

  • Operator Precedence Bug Fix: Corrected an operator precedence issue in the MCP tool cache check condition !this.config.cacheConfig?.enabled === false, which was incorrectly preventing cache usage when cacheConfig was undefined. The condition was updated to this.config.cacheConfig?.enabled !== false for correct evaluation.
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.

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 fixes a bug related to operator precedence in the MCP tool cache check, ensuring that caching is enabled by default as intended. The fix is clean and consistent with the existing codebase. I have added one suggestion to further improve maintainability by refactoring the duplicated cache-check logic into a helper method.

this.tools.length > 0 &&
!this.config.cacheConfig?.enabled === false
) {
if (this.tools.length > 0 && this.config.cacheConfig?.enabled !== false) {
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This logic to check if the cache is enabled is also used on line 172. To improve readability and avoid duplication, consider extracting this logic into a private helper method.

For example, you could add a method to the McpToolset class:

private isCacheEnabled(): boolean {
    return this.config.cacheConfig?.enabled !== false;
}

And then use it here and on line 172:

if (this.tools.length > 0 && this.isCacheEnabled()) {
    return this.tools;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call — extracted into a private isCacheEnabled() helper and updated both call sites in eb4ad9e.

Deduplicate the cache-enabled check used in two places by extracting
it into a private isCacheEnabled() method.
@changeset-bot
Copy link

changeset-bot bot commented Mar 19, 2026

⚠️ No Changeset found

Latest commit: eb4ad9e

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

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.

fix: mcp tool cache never activates due to operator precedence

1 participant