Skip to content

refactor: decouple Source from Tool#2204

Merged
Yuan325 merged 18 commits into
mainfrom
config-branch
Dec 20, 2025
Merged

refactor: decouple Source from Tool#2204
Yuan325 merged 18 commits into
mainfrom
config-branch

Conversation

@Yuan325

@Yuan325 Yuan325 commented Dec 19, 2025

Copy link
Copy Markdown
Contributor

This PR update the linking mechanism between Source and Tool.

Tools are directly linked to their Source, either by pointing to the Source's functions or by assigning values from the source during Tool's initialization. However, the existing approach means that any modification to the Source after Tool's initialization might not be reflected. To address this limitation, each tool should only store a name reference to the Source, rather than direct link or assigned values.

Tools will provide interface for compatibleSource. This will be used to determine if a Source is compatible with the Tool.

type compatibleSource interface{
    Client() http.Client
    ProjectID() string
}

During Invoke(), the tool will run the following operations:

  • retrieve Source from the resourceManager with source's named defined in Tool's config
  • validate Source via compatibleSource interface{}
  • run the remaining Invoke() function. Fields that are needed is retrieved directly from the source.

With this update, resource manager is also added as input to other Tool's function that require access to source (e.g. RequiresClientAuthorization()).

@Yuan325 Yuan325 requested review from a team December 19, 2025 02:56
@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 significantly refactors the interaction between 'Source' and 'Tool' components by decoupling their direct dependencies. The change moves from static linking to dynamic retrieval of 'Source' instances during 'Tool' invocation, ensuring that tools always use up-to-date source configurations. This is achieved through a new 'compatibleSource' interface for validation and updates to authorization-related method signatures to support this dynamic interaction model.

Highlights

  • Decoupled Source from Tool: The core change involves updating the linking mechanism between 'Source' and 'Tool' components. Tools no longer hold direct references to 'Source' instances or their assigned values, preventing stale data issues if the 'Source' changes after 'Tool' initialization.
  • Dynamic Source Retrieval: Tools now store only a name reference to their associated 'Source'. During the 'Invoke()' method call, the 'Tool' dynamically retrieves the 'Source' instance from a 'resourceManager', ensuring it always operates with the most current 'Source' information.
  • Introduced CompatibleSource Interface: A new 'compatibleSource' interface has been introduced. This interface is used by 'Tool' instances to validate whether a retrieved 'Source' is compatible with the 'Tool's requirements before proceeding with operations.
  • Enhanced Authorization Method Signatures: The 'RequiresClientAuthorization()' and 'GetAuthTokenHeaderName()' methods have been updated across various tools. They now accept a 'tools.SourceProvider' argument and return an error, improving error handling and flexibility in authorization checks.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

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 introduces a significant refactoring to decouple Source from Tool. The approach of using a compatibleSource interface and dynamically resolving the source at runtime is well-implemented and consistently applied across the codebase. This change will improve the system's flexibility, allowing for source configurations to be updated without re-initializing tools. My review includes one suggestion to reduce code duplication in error handling within the MCP handlers, which would further enhance maintainability.

Comment thread internal/server/mcp/v20241105/method.go
## Description

Add error to return of `RequiresClientAuthorization()` function. The
function will run `resourceMgr.GetSource(t.SourceName)` before checking
for source's oauth setting. With this, it will return an error if the
retrieval is not successful. In that case, we would want to return an
error from `RequiresClientAuthorization()`.

## 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:

- [x] Make sure you reviewed

[CONTRIBUTING.md](https://github.com/googleapis/genai-toolbox/blob/main/CONTRIBUTING.md)
- [x] 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
- [x] Ensure the tests and linter pass
- [x] Code coverage does not decrease (if any source code was changed)
- [x] Appropriate docs were updated (if necessary)
- [x] Make sure to add `!` if this involve a breaking change

🛠️ Fixes #<issue_number_goes_here>
…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>
Within Invoke() and RequiresClientAuthorization(), get Source from
ResourceManager and use it to call functions directly.
…ool (#2059)

## Description

Decouple source config from tools.

## 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>
…onfig from tools (#2062)

Within Invoke() and RequiresClientAuthorization(), get Source from
ResourceManager and use it to call functions directly.
Within Invoke() and RequiresClientAuthorization(), get Source from
ResourceManager and use it to call functions directly.
…s/elasticsearch,tools/firebird): decouple source config from tools (#2064)

Within Invoke() and RequiresClientAuthorization(), get Source from
ResourceManager and use it to call functions directly.
…le source config from tools (#2065)

Within Invoke() and RequiresClientAuthorization(), get Source from
ResourceManager and use it to call functions directly.
Within Invoke() and RequiresClientAuthorization(), get Source from
ResourceManager and use it to call functions directly.
…source config from tools (#2067)

Within Invoke() and RequiresClientAuthorization(), get Source from
ResourceManager and use it to call functions directly.
…/spanner): decouple source config from tools (#2068)

Within Invoke() and RequiresClientAuthorization(), get Source from
ResourceManager and use it to call functions directly.
…tools/yugabytedbsql): decouple source config from tools (#2070)

Within Invoke() and RequiresClientAuthorization(), get Source from
ResourceManager and use it to call functions directly.
## 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>
Update `Authorized()` function in all tools to take a new input
parameter -- resourceManager. This was updated for looker tool
previously since that tool require access to the source.

When running lint and unit tests, this PR also updates the following:
* Remove unit tests that checks for Source compatibility or missing
Source during initialization. These tests are not relevant since most of
the tools only check for source compatibility when it is needed (e.g.
during `Invoke()`)
* Update sources configs to be exported (specifically alloydbadmin and
cloudsqladmin).
Added a generic `GetCompatibleSource()` in tools.go.
rebase `config-branch` to `main` and update newly added tools. Also
resolve merge conflicts.
@Yuan325 Yuan325 merged commit 967a72d into main Dec 20, 2025
11 checks passed
@Yuan325 Yuan325 deleted the config-branch branch December 20, 2025 05:27
github-actions Bot pushed a commit to apprendiendo/genai-toolbox that referenced this pull request Dec 21, 2025
This PR update the linking mechanism between Source and Tool.

Tools are directly linked to their Source, either by pointing to the
Source's functions or by assigning values from the source during Tool's
initialization. However, the existing approach means that any
modification to the Source after Tool's initialization might not be
reflected. To address this limitation, each tool should only store a
name reference to the Source, rather than direct link or assigned
values.

Tools will provide interface for `compatibleSource`. This will be used
to determine if a Source is compatible with the Tool.
```
type compatibleSource interface{
    Client() http.Client
    ProjectID() string
}
```

During `Invoke()`, the tool will run the following operations:
* retrieve Source from the `resourceManager` with source's named defined
in Tool's config
* validate Source via `compatibleSource interface{}`
* run the remaining `Invoke()` function. Fields that are needed is
retrieved directly from the source.

With this update, resource manager is also added as input to other
Tool's function that require access to source (e.g.
`RequiresClientAuthorization()`). 967a72d
github-actions Bot pushed a commit to isaurabhuttam/genai-toolbox that referenced this pull request Dec 23, 2025
This PR update the linking mechanism between Source and Tool.

Tools are directly linked to their Source, either by pointing to the
Source's functions or by assigning values from the source during Tool's
initialization. However, the existing approach means that any
modification to the Source after Tool's initialization might not be
reflected. To address this limitation, each tool should only store a
name reference to the Source, rather than direct link or assigned
values.

Tools will provide interface for `compatibleSource`. This will be used
to determine if a Source is compatible with the Tool.
```
type compatibleSource interface{
    Client() http.Client
    ProjectID() string
}
```

During `Invoke()`, the tool will run the following operations:
* retrieve Source from the `resourceManager` with source's named defined
in Tool's config
* validate Source via `compatibleSource interface{}`
* run the remaining `Invoke()` function. Fields that are needed is
retrieved directly from the source.

With this update, resource manager is also added as input to other
Tool's function that require access to source (e.g.
`RequiresClientAuthorization()`). 967a72d
vinodhinic pushed a commit to vinodhinic/genai-toolbox that referenced this pull request Jan 14, 2026
This PR update the linking mechanism between Source and Tool.

Tools are directly linked to their Source, either by pointing to the
Source's functions or by assigning values from the source during Tool's
initialization. However, the existing approach means that any
modification to the Source after Tool's initialization might not be
reflected. To address this limitation, each tool should only store a
name reference to the Source, rather than direct link or assigned
values.

Tools will provide interface for `compatibleSource`. This will be used
to determine if a Source is compatible with the Tool.
```
type compatibleSource interface{
    Client() http.Client
    ProjectID() string
}
```

During `Invoke()`, the tool will run the following operations:
* retrieve Source from the `resourceManager` with source's named defined
in Tool's config
* validate Source via `compatibleSource interface{}`
* run the remaining `Invoke()` function. Fields that are needed is
retrieved directly from the source.

With this update, resource manager is also added as input to other
Tool's function that require access to source (e.g.
`RequiresClientAuthorization()`).
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