Skip to content

feat: add tool annotation - #226

Merged
iFurySt merged 4 commits into
AmoyLab:mainfrom
qiankunli:feat/add-tool-annotation
Aug 7, 2025
Merged

iFurySt merged 4 commits into
AmoyLab:mainfrom
qiankunli:feat/add-tool-annotation

Conversation

@qiankunli

@qiankunli qiankunli commented Aug 7, 2025 •

Copy link
Copy Markdown
Contributor

Summary by Sourcery

Add support for optional tool annotations across config, MCP schemas, and SSE server handling, and introduce map utility functions with corresponding tests

New Features:

  • Support tool annotations (title, destructiveHint, idempotentHint, openWorldHint, readOnlyHint) in configuration and protocol schemas
  • Add utility functions GetBool and GetString to safely extract typed values from map[string]any

Enhancements:

  • Include annotations in SSE server’s tool descriptions

Tests:

  • Add unit tests for GetBool and GetString in pkg/utils

@sourcery-ai

sourcery-ai Bot commented Aug 7, 2025 •

Copy link
Copy Markdown
Contributor

Reviewer's Guide

This PR introduces optional tool annotations by extending config structs, mapping them into the MCP schema, updating server types and SSE handling, and providing utility functions with tests for safe extraction of annotation values.

Class diagram for ToolConfig and ToolSchema with Annotations

classDiagram
    class ToolConfig {
        string Name
        string Description
        string RequestBody
        string ResponseBody
        map[string]any InputSchema
        map[string]any Annotations  // newly added
        ToToolSchema() mcp.ToolSchema
    }
    class ToolSchema {
        string Name
        string Description
        ToolInputSchema InputSchema
        ToolAnnotations* Annotations  // newly added
    }
    class ToolAnnotations {
        bool DestructiveHint
        bool IdempotentHint
        bool OpenWorldHint
        bool ReadOnlyHint
        string Title
    }
    ToolConfig --|> ToolSchema : ToToolSchema()
    ToolSchema o-- ToolAnnotations : optional
Loading

Class diagram for utility functions in utils package

classDiagram
    class utils {
        +GetBool(map[string]any, string, bool) bool
        +GetString(map[string]any, string, string) string
    }
Loading

Class diagram for updated PromptConfig and PromptSchema

classDiagram
    class PromptConfig {
        string Name
        string Description
        []PromptArgument Arguments
        []PromptResponse PromptResponse
        ToPromptSchema() mcp.PromptSchema
    }
    class PromptSchema {
        string Name
        string Description
        []PromptArgumentSchema Arguments
        []PromptResponseSchema PromptResponse
    }
    PromptConfig --|> PromptSchema : ToPromptSchema()
Loading

File-Level Changes

Change Details Files
Add Annotations field to configuration structs
  • Introduce Annotations map[string]any in ToolConfig and PromptConfig
  • Update JSON/YAML tags and struct field alignment
internal/common/config/mcp.go
Map config Annotations into mcp.ToolAnnotations
  • Implement conditional mapping in ToToolSchema using utils.GetString/GetBool
  • Pass constructed ToolAnnotations pointer into returned ToolSchema
internal/common/config/mcp.go
Extend MCP server types with ToolAnnotations
  • Define ToolAnnotations struct with title and hint fields
  • Add Annotations pointer field to ToolSchema and update PromptSchema formatting
pkg/mcp/server_types.go
Propagate annotations in SSE tool responses
  • Include tool.Annotations in handlePostMessage response payload
  • Fix minor formatting and spacing issues
internal/core/sse.go
Introduce utils helpers and tests for annotations
  • Add GetBool and GetString in pkg/utils/map.go
  • Add unit tests for both functions in pkg/utils/map_test.go
pkg/utils/map.go
pkg/utils/map_test.go

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai 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.

Hey @qiankunli - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@iFurySt iFurySt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM! Thanks!

@iFurySt
iFurySt merged commit 96e9bc4 into AmoyLab:main Aug 7, 2025
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