Skip to content

chore(tools/bigtable,tools/cassandra,tools/clickhouse): decouple config from tool#2061

Merged
Yuan325 merged 4 commits into
config-branchfrom
config-bigtable-etc
Dec 11, 2025
Merged

chore(tools/bigtable,tools/cassandra,tools/clickhouse): decouple config from tool#2061
Yuan325 merged 4 commits into
config-branchfrom
config-bigtable-etc

Conversation

@Yuan325

@Yuan325 Yuan325 commented Nov 27, 2025

Copy link
Copy Markdown
Contributor

Description

Within Invoke() and RequiresClientAuthorization(), get Source from ResourceManager and use it to call functions directly.

PR Checklist

Thank you for opening a Pull Request! Before submitting your PR, there are a
few things you can do to make sure it goes smoothly:

  • Make sure you reviewed
    CONTRIBUTING.md
  • Make sure to open an issue as a
    bug/issue
    before writing your code! That way we can discuss the change, evaluate
    designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)
  • Make sure to add ! if this involve a breaking change

🛠️ Fixes #<issue_number_goes_here>

@Yuan325 Yuan325 requested a review from a team November 27, 2025 17:20
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @Yuan325, 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 significant architectural improvement by decoupling the configuration of various data source tools (Bigtable, Cassandra, ClickHouse) from their underlying client instances. This change centralizes the management and retrieval of data source clients through a ResourceManager, enhancing modularity, reducing tight coupling, and making the system more flexible and easier to maintain. Tools now request their required client at the point of use rather than holding onto it from initialization.

Highlights

  • Decoupling Tool Configuration from Client Instances: The pull request refactors Bigtable, Cassandra, and ClickHouse tools to no longer hold direct client instances (e.g., *bigtable.Client, *gocql.Session, *sql.DB) within their Tool structs. Instead, these clients are now retrieved dynamically from a tools.SourceProvider (resource manager) during the Invoke method execution.
  • Centralized Source Management: The Initialize methods for these tools have been simplified, removing the logic for verifying source existence and compatibility, and the direct assignment of client instances. This responsibility is now shifted to the Invoke method, which fetches the appropriate source from the ResourceManager at runtime.
  • Updated RequiresClientAuthorization Signature: The RequiresClientAuthorization method across all affected tools has been updated to return (bool, error) instead of just bool, aligning with a more robust error handling pattern.
  • Code Clean-up and Simplification: Unused imports, compatibleSources variables, and direct client assignments have been removed, leading to cleaner and more maintainable code in the tool implementations.
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.

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

Copy link
Copy Markdown
Contributor

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 does a great job of decoupling the tool implementations from their configurations by moving the source retrieval logic into the Invoke method. This is a solid refactoring that improves modularity. I've found a critical compilation issue in the ClickHouse tools due to function redeclaration, and a critical security vulnerability (SQL injection). I've also included a suggestion to reduce code duplication across the Invoke methods.

Comment thread internal/tools/clickhouse/clickhouseexecutesql/clickhouseexecutesql.go Outdated
Comment thread internal/tools/clickhouse/clickhouseexecutesql/clickhouseexecutesql.go Outdated
Comment thread internal/tools/clickhouse/clickhouselistdatabases/clickhouselistdatabases.go Outdated
Comment thread internal/tools/clickhouse/clickhouselistdatabases/clickhouselistdatabases.go Outdated
Comment thread internal/tools/clickhouse/clickhouselisttables/clickhouselisttables.go Outdated
Comment thread internal/tools/clickhouse/clickhouselisttables/clickhouselisttables.go Outdated
Comment thread internal/tools/clickhouse/clickhousesql/clickhousesql.go
Comment thread internal/tools/clickhouse/clickhousesql/clickhousesql.go
Comment thread internal/tools/bigtable/bigtable.go
@averikitsch averikitsch assigned averikitsch and unassigned duwenxin99 Dec 1, 2025
if !ok {
return nil, fmt.Errorf("unable to retrieve source %s in tool %s", t.Source, t.Name)
}
source, ok := s.(compatibleSource)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we only have a compatible source check on invoke? When Toolbox starts up it should ensure compatibility.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@averikitsch Yes. In cases where user adds the tool before adding the source, we don't want the server to fail. (that way the initialization of tool does not depend on the source).

Base automatically changed from config-server to config-branch December 9, 2025 01:36
@Yuan325 Yuan325 requested a review from a team December 9, 2025 01:36
@Yuan325

Yuan325 commented Dec 10, 2025

Copy link
Copy Markdown
Contributor Author

/gemini review

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

Copy link
Copy Markdown
Contributor

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 effectively decouples tool implementations from their source configurations by deferring source retrieval to the Invoke method. This is a solid architectural improvement that enhances modularity. The change to the Tool interface, allowing RequiresClientAuthorization to return an error, is well-handled in both the API and MCP layers. My review includes suggestions to improve error handling consistency and to make error messages more descriptive for better debuggability of configuration issues.

Comment thread internal/server/api.go
Comment thread internal/tools/bigtable/bigtable.go
Comment thread internal/tools/cassandra/cassandracql/cassandracql.go
Comment thread internal/tools/clickhouse/clickhousesql/clickhousesql.go
@Yuan325 Yuan325 force-pushed the config-bigtable-etc branch from b297a57 to 67277c3 Compare December 11, 2025 04:05
@Yuan325 Yuan325 merged commit 025a6b1 into config-branch Dec 11, 2025
6 of 11 checks passed
@Yuan325 Yuan325 deleted the config-bigtable-etc branch December 11, 2025 04:06
Yuan325 added a commit that referenced this pull request Dec 17, 2025
…ig from tool (#2061)

## Description

Within Invoke() and RequiresClientAuthorization(), get Source from
ResourceManager and use it to call functions directly.

## PR Checklist

> Thank you for opening a Pull Request! Before submitting your PR, there
are a
> few things you can do to make sure it goes smoothly:

- [ ] Make sure you reviewed

[CONTRIBUTING.md](https://github.com/googleapis/genai-toolbox/blob/main/CONTRIBUTING.md)
- [ ] Make sure to open an issue as a

[bug/issue](https://github.com/googleapis/genai-toolbox/issues/new/choose)
  before writing your code! That way we can discuss the change, evaluate
  designs, and agree on the general idea
- [ ] Ensure the tests and linter pass
- [ ] Code coverage does not decrease (if any source code was changed)
- [ ] Appropriate docs were updated (if necessary)
- [ ] Make sure to add `!` if this involve a breaking change

🛠️ Fixes #<issue_number_goes_here>
Yuan325 added a commit that referenced this pull request Dec 18, 2025
…ig from tool (#2061)

## Description

Within Invoke() and RequiresClientAuthorization(), get Source from
ResourceManager and use it to call functions directly.

## PR Checklist

> Thank you for opening a Pull Request! Before submitting your PR, there
are a
> few things you can do to make sure it goes smoothly:

- [ ] Make sure you reviewed

[CONTRIBUTING.md](https://github.com/googleapis/genai-toolbox/blob/main/CONTRIBUTING.md)
- [ ] Make sure to open an issue as a

[bug/issue](https://github.com/googleapis/genai-toolbox/issues/new/choose)
  before writing your code! That way we can discuss the change, evaluate
  designs, and agree on the general idea
- [ ] Ensure the tests and linter pass
- [ ] Code coverage does not decrease (if any source code was changed)
- [ ] Appropriate docs were updated (if necessary)
- [ ] Make sure to add `!` if this involve a breaking change

🛠️ Fixes #<issue_number_goes_here>
Yuan325 added a commit that referenced this pull request Dec 19, 2025
…ig from tool (#2061)

## Description

Within Invoke() and RequiresClientAuthorization(), get Source from
ResourceManager and use it to call functions directly.

## PR Checklist

> Thank you for opening a Pull Request! Before submitting your PR, there
are a
> few things you can do to make sure it goes smoothly:

- [ ] Make sure you reviewed

[CONTRIBUTING.md](https://github.com/googleapis/genai-toolbox/blob/main/CONTRIBUTING.md)
- [ ] Make sure to open an issue as a

[bug/issue](https://github.com/googleapis/genai-toolbox/issues/new/choose)
  before writing your code! That way we can discuss the change, evaluate
  designs, and agree on the general idea
- [ ] Ensure the tests and linter pass
- [ ] Code coverage does not decrease (if any source code was changed)
- [ ] Appropriate docs were updated (if necessary)
- [ ] Make sure to add `!` if this involve a breaking change

🛠️ Fixes #<issue_number_goes_here>
Yuan325 added a commit that referenced this pull request Dec 19, 2025
…ig from tool (#2061)

## Description

Within Invoke() and RequiresClientAuthorization(), get Source from
ResourceManager and use it to call functions directly.

## PR Checklist

> Thank you for opening a Pull Request! Before submitting your PR, there
are a
> few things you can do to make sure it goes smoothly:

- [ ] Make sure you reviewed

[CONTRIBUTING.md](https://github.com/googleapis/genai-toolbox/blob/main/CONTRIBUTING.md)
- [ ] Make sure to open an issue as a

[bug/issue](https://github.com/googleapis/genai-toolbox/issues/new/choose)
  before writing your code! That way we can discuss the change, evaluate
  designs, and agree on the general idea
- [ ] Ensure the tests and linter pass
- [ ] Code coverage does not decrease (if any source code was changed)
- [ ] Appropriate docs were updated (if necessary)
- [ ] Make sure to add `!` if this involve a breaking change

🛠️ Fixes #<issue_number_goes_here>
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.

3 participants