Skip to content

Comments

refactor: use annotations to determine if tool should be included#38

Merged
cgrinds merged 1 commit intomainfrom
cbg-tools
Feb 20, 2026
Merged

refactor: use annotations to determine if tool should be included#38
cgrinds merged 1 commit intomainfrom
cbg-tools

Conversation

@cgrinds
Copy link
Collaborator

@cgrinds cgrinds commented Feb 20, 2026

No description provided.

Copilot AI review requested due to automatic review settings February 20, 2026 14:20
@cgrinds cgrinds requested a review from Hardikl as a code owner February 20, 2026 14:20
@cgrinds cgrinds merged commit fc83122 into main Feb 20, 2026
19 checks passed
@cgrinds cgrinds deleted the cbg-tools branch February 20, 2026 14:24
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the tool registration logic to centralize read-only mode checks. Instead of wrapping tool registration calls with explicit if !a.options.ReadOnly conditionals scattered throughout the code, the PR moves this logic into the addTool helper function, which uses annotation comparison to determine whether a tool should be registered.

Changes:

  • Centralized read-only mode checking in the addTool function by comparing annotations
  • Changed annotation variables from pointers to values for comparison
  • Removed repetitive if !a.options.ReadOnly conditionals from tool registration code

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


func addTool[In, Out any](server *mcp.Server, name string, description string, annotations *mcp.ToolAnnotations, handler mcp.ToolHandlerFor[In, Out]) {
func addTool[In, Out any](a *App, server *mcp.Server, name string, description string, annotations mcp.ToolAnnotations, handler mcp.ToolHandlerFor[In, Out]) {
if a.options.ReadOnly && annotations != readOnlyAnnotation {
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

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

Struct comparison with pointer fields is fragile. While this works because package-level annotation variables are used consistently, it compares pointer addresses rather than values. A more robust approach would be to check the annotation fields directly (e.g., checking if ReadOnlyHint is true) or add a method to ToolAnnotations to determine if it's read-only. This would make the intent clearer and prevent issues if annotations are created differently in the future.

Suggested change
if a.options.ReadOnly && annotations != readOnlyAnnotation {
if a.options.ReadOnly && !annotations.ReadOnlyHint {

Copilot uses AI. Check for mistakes.
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.

2 participants