chore: add error return for RequiresClientAuthorization()#2058
Conversation
Summary of ChangesHello @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 enhances the error handling mechanism for tool authorization checks. By modifying the Highlights
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
Code Review
This pull request correctly adds error handling to the RequiresClientAuthorization function by changing its signature to return an error. This is a good improvement for robustness, and the changes are applied consistently across the Tool interface, mock implementations, and API handlers.
My main feedback concerns code duplication that has been introduced with these changes:
- In
internal/server/api.go, thetoolInvokeHandlerfunction now contains duplicated logic for checking client authorization. - A similar pattern of duplication is present within the
toolsCallHandlerfunction across multiple versioned MCP files (v20241105,v20250326,v20250618).
I've added specific comments with suggestions to address this. Resolving the duplication will improve code maintainability. I also found a minor issue with the choice of a JSON-RPC error code, for which I've also left a comment.
## 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>
## 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>
## 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>
## 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>
Description
Add error to return of
RequiresClientAuthorization()function. The function will runresourceMgr.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 fromRequiresClientAuthorization().PR Checklist
CONTRIBUTING.md
bug/issue
before writing your code! That way we can discuss the change, evaluate
designs, and agree on the general idea
!if this involve a breaking change🛠️ Fixes #<issue_number_goes_here>