Skip to content

refactor: Pull out Annotations structure rather than being an anonymous inner struct #203

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 25, 2025

Conversation

rm-hull
Copy link
Contributor

@rm-hull rm-hull commented Apr 23, 2025

Fixes #177

Note: I guess this technically would be a breaking change

Summary by CodeRabbit

  • Refactor
    • Improved the internal structure for annotation metadata, making the system more maintainable without affecting user-facing behavior. No visible changes to the interface or data format.

Copy link
Contributor

coderabbitai bot commented Apr 23, 2025

Walkthrough

The changes introduce a new named struct, Annotations, to encapsulate annotation metadata previously represented by an anonymous struct. The Annotated struct is updated to use a pointer to this new Annotations type. All relevant initialization logic in the codebase is refactored to use the named struct for the Annotations field, replacing previous anonymous struct usage. The JSON structure and semantics of the annotations remain unchanged.

Changes

Files Change Summary
mcp/types.go Introduced the Annotations struct with Audience and Priority fields; updated Annotated to use it.
mcp/resources.go Refactored annotation initialization to use the named Annotations struct instead of an anonymous struct.

Assessment against linked issues

Objective Addressed Explanation
Refactor Annotated.Annotations to use a named Annotations struct instead of a pointer to an anonymous struct (#177)
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between edda393 and ff91247.

📒 Files selected for processing (2)
  • mcp/resources.go (2 hunks)
  • mcp/types.go (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
mcp/resources.go (1)
mcp/types.go (1)
  • Annotations (662-675)
mcp/types.go (1)
mcp/prompts.go (1)
  • Role (68-68)
🔇 Additional comments (3)
mcp/types.go (1)

662-675: Good refactoring of the annotation structure.

Creating a named Annotations struct improves code organization and provides a clear, reusable structure for annotation metadata. The JSON field names remain consistent, which helps maintain compatibility with existing JSON data.

mcp/resources.go (2)

46-47: Update to use the new Annotations type is correct.

The code properly instantiates a new Annotations struct when the field is nil, consistent with the refactoring in types.go.


94-95: Consistent use of the new Annotations type.

This code follows the same pattern as in WithAnnotations, properly instantiating a new Annotations struct when needed.

Comment on lines 680 to 682
type Annotated struct {
Annotations *struct {
// Describes who the intended customer of this object or data is.
//
// It can include multiple entries to indicate content useful for multiple
// audiences (e.g., `["user", "assistant"]`).
Audience []Role `json:"audience,omitempty"`

// Describes how important this data is for operating the server.
//
// A value of 1 means "most important," and indicates that the data is
// effectively required, while 0 means "least important," and indicates that
// the data is entirely optional.
Priority float64 `json:"priority,omitempty"`
} `json:"annotations,omitempty"`
Annotations *Annotations `json:"annotations,omitempty"`
}
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Consider documenting this breaking change.

Changing Annotations from an inline anonymous struct to a pointer to a named struct is a breaking change that could affect existing code. Any code that directly accessed the fields of the anonymous struct now needs to handle potential nil pointers.


🏁 Script executed:

#!/bin/bash
# Search for code that might be affected by this change
rg -A2 "\.Annotations\." --type go

Length of output: 329


🏁 Script executed:

#!/bin/bash
# Inspect context around usage of r.Annotations.Audience
rg -n -C3 "r\.Annotations\.Audience" mcp/resources.go

# Inspect context around usage of t.Annotations.Audience
rg -n -C3 "t\.Annotations\.Audience" mcp/resources.go

# Search for nil-checks or initialization of Annotations pointers
rg -n -C3 "Annotations == nil" --type go
rg -n -C3 "Annotations = &Annotations" --type go

Length of output: 2195


Document Breaking Change to Annotations Field

Changing Annotations from an inline struct to a *Annotations pointer is a breaking change. Any code that previously did:

r := Resource{}
// r.Annotations.Priority == 0

will now panic on r.Annotations.Priority because r.Annotations can be nil.

Please update your documentation and migration guide:

• Add a note under Breaking Changes in CHANGELOG.md (or RELEASE_NOTES) that the Annotations field is now a pointer.
• In README or docs, advise users to initialize with WithAnnotations(...) or check for nil before accessing fields.
• (Optional) Consider adding a custom UnmarshalJSON on Annotated to default the pointer.

Affected locations:

  • mcp/types.go at type Annotated struct { Annotations *Annotations ... }
  • mcp/resources.go builder funcs already guard against nil, but any unmarshaled or literal Annotated must be initialized.

@ezynda3 ezynda3 changed the title Pull out Annotations structure rather than being an anonymous inner struct refactor: Pull out Annotations structure rather than being an anonymous inner struct Apr 25, 2025
@ezynda3 ezynda3 merged commit 9d62b19 into mark3labs:main Apr 25, 2025
2 checks passed
adlternative pushed a commit to adlternative/mcp-go that referenced this pull request May 20, 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.

Pointer to anonymous structure [refactor?]
2 participants