-
Notifications
You must be signed in to change notification settings - Fork 740
Add docstrings for annotation-related functions #673
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
Conversation
Improve documentation for exported functions in mcp/resources.go and mcp/utils.go: - WithAnnotations: describe return type and field initialization - WithLastModified: consolidate timestamp format documentation - WithTemplateAnnotations: describe return type and field initialization - ValidateISO8601Timestamp: document empty string handling and return behavior - ParseAnnotations: add comprehensive docstring for parsing behavior
WalkthroughUpdates resource option helpers and annotations handling to ensure nil-safety and add annotation parsing. Modifies WithAnnotations, WithLastModified, and WithTemplateAnnotations to initialize Annotations before use, adds ParseAnnotations function to parse annotation data from maps, and strengthens RFC3339 validation documentation across timestamp handling. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Possibly related PRs
Suggested labels
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
mcp/resources.go (1)
59-69: Consider validating the timestamp format.The function initializes
Annotationscorrectly and is well-documented. However, it accepts any string without validation, even thoughValidateISO8601Timestampexists in the same file (lines 120-130). Invalid timestamps will only be detected later when consumed.🔎 Optional: Add validation
If you want to enforce format validation at construction time:
func WithLastModified(timestamp string) ResourceOption { return func(r *Resource) { + if err := ValidateISO8601Timestamp(timestamp); err != nil { + // Option: return early, log warning, or panic depending on error handling strategy + return + } if r.Annotations == nil { r.Annotations = &Annotations{} } r.Annotations.LastModified = timestamp } }Note: This changes the error handling model (functional options typically don't return errors), so this may not align with your design. Current approach allows flexibility for callers to validate separately if needed.
📜 Review details
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
mcp/resources.go(4 hunks)mcp/utils.go(1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.go
📄 CodeRabbit inference engine (AGENTS.md)
**/*.go: Order imports: standard library first, then third-party, then local packages (goimports enforces this)
Follow Go naming conventions: exported identifiers in PascalCase; unexported in camelCase; acronyms uppercase (HTTP, JSON, MCP)
Error handling: return sentinel errors, wrap with fmt.Errorf("context: %w", err), and check with errors.Is/As
Prefer explicit types and strongly-typed structs; avoid using any except where protocol flexibility is required (e.g., Arguments any)
All exported types and functions must have GoDoc comments starting with the identifier name; avoid inline comments unless necessary
Functions that are handlers or long-running must accept context.Context as the first parameter
Ensure thread safety for shared state using sync.Mutex and document thread-safety requirements in comments
For JSON: use json struct tags with omitempty for optional fields; use json.RawMessage for flexible/deferred parsing
Files:
mcp/utils.gomcp/resources.go
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: test
🔇 Additional comments (4)
mcp/utils.go (1)
539-573: LGTM! Well-documented and implemented annotation parsing.The
ParseAnnotationsfunction is well-designed with comprehensive documentation. The implementation correctly:
- Returns nil for nil input
- Parses priority as a pointer (allowing distinction between "not set" and "zero")
- Filters audience to valid roles (RoleUser and RoleAssistant)
- Handles LastModified as a string
The nil-safety checks and use of the cast library for type conversions are appropriate.
mcp/resources.go (3)
45-57: LGTM! Clear documentation and nil-safe implementation.The documentation accurately describes the behavior, and the implementation properly initializes
Annotationswhen nil before setting fields. The priority is correctly stored as a pointer.
107-118: LGTM! Documentation and implementation are correct.The function properly initializes
Annotationswhen nil and sets all three fields as documented. The behavior matchesWithAnnotationsfor resources.
120-130: LGTM! Clear validation function with proper documentation.The documentation accurately describes the RFC3339/ISO 8601 validation behavior, including the handling of empty strings as valid. The implementation is straightforward and correct.
Description
Add comprehensive docstrings for exported annotation-related functions in
mcp/resources.goandmcp/utils.go.This is based on PR #664 but with improved documentation that avoids duplication (as noted in the review comments on that PR).
Type of Change
Checklist
Additional Information
Functions updated:
WithAnnotations: Describes return type and field initialization behaviorWithLastModified: Consolidates timestamp format documentation (fixes duplication issue from 📝 Add docstrings tofeat/annotations-mcp-2025-11-25#664)WithTemplateAnnotations: Describes return type and field initialization behaviorValidateISO8601Timestamp: Documents empty string handling and return behaviorParseAnnotations: Adds comprehensive docstring explaining parsing behavior for each fieldSummary by CodeRabbit
Release Notes
Bug Fixes
Improvements
✏️ Tip: You can customize this high-level summary in your review settings.