Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions mcp/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ func WithMIMEType(mimeType string) ResourceOption {
}
}

// WithAnnotations adds annotations to the Resource.
// Annotations can provide additional metadata about the resource's intended use.
// WithAnnotations returns a ResourceOption that sets the resource's Annotations fields.
// It ensures Annotations is allocated when nil, sets Audience to the provided slice,
// stores Priority as a pointer to the provided value, and sets LastModified to the provided timestamp.
func WithAnnotations(audience []Role, priority float64, lastModified string) ResourceOption {
return func(r *Resource) {
if r.Annotations == nil {
Expand All @@ -57,7 +58,9 @@ func WithAnnotations(audience []Role, priority float64, lastModified string) Res

// WithLastModified adds a last modified timestamp to the Resource.
// The timestamp should be in ISO 8601 format (e.g., "2025-01-12T15:00:58Z").
Copy link
Contributor

Choose a reason for hiding this comment

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

@coderabbitai fix this duplication please

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ezynda3, I can see the duplication in the WithLastModified function documentation. The comment mentions the ISO 8601 format requirement twice. Here's the fixed version:

// WithLastModified returns a ResourceOption that sets the resource's Annotations.LastModified
// to the provided timestamp. If the resource's Annotations is nil it will be initialized.
// The timestamp is expected to be an ISO 8601 (RFC3339) formatted string (e.g., "2025-01-12T15:00:58Z").
func WithLastModified(timestamp string) ResourceOption {
	return func(r *Resource) {
		if r.Annotations == nil {
			r.Annotations = &Annotations{}
		}
		r.Annotations.LastModified = timestamp
	}
}

This consolidates the information about what the function does and the expected timestamp format into a clear, non-redundant comment.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you edit the file in this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ezynda3, I'm unable to directly edit files or commit code to the PR. However, I've already provided the fixed code in my previous comment that you can copy and apply to the file.

If you'd like, you can:

  1. Copy the corrected WithLastModified function documentation from my previous comment
  2. Apply it manually to the mcp/resources.go file
  3. Commit the change to this PR

Is there anything else I can help you with regarding this fix or any other part of the code?

// Callers should use ValidateISO8601Timestamp to validate the timestamp before use.
// WithLastModified returns a ResourceOption that sets the resource's Annotations.LastModified
// to the provided timestamp. If the resource's Annotations is nil it will be initialized.
// The timestamp is expected to be an ISO 8601 (RFC3339) formatted string.
func WithLastModified(timestamp string) ResourceOption {
return func(r *Resource) {
if r.Annotations == nil {
Expand Down Expand Up @@ -104,7 +107,7 @@ func WithTemplateMIMEType(mimeType string) ResourceTemplateOption {
}

// WithTemplateAnnotations adds annotations to the ResourceTemplate.
// Annotations can provide additional metadata about the template's intended use.
// Annotations field is initialized and setting Audience, Priority, and LastModified.
func WithTemplateAnnotations(audience []Role, priority float64, lastModified string) ResourceTemplateOption {
return func(t *ResourceTemplate) {
if t.Annotations == nil {
Expand All @@ -116,7 +119,9 @@ func WithTemplateAnnotations(audience []Role, priority float64, lastModified str
}
}

// ValidateISO8601Timestamp checks if a string is a valid ISO 8601 timestamp
// ValidateISO8601Timestamp verifies that timestamp is a valid ISO 8601 timestamp
// using the RFC3339 layout. An empty string is considered valid. It returns nil
// when the timestamp is valid, or the parsing error when it is not.
func ValidateISO8601Timestamp(timestamp string) error {
if timestamp == "" {
return nil // Empty is valid (optional field)
Expand All @@ -140,4 +145,4 @@ func WithTemplateIcons(icons ...Icon) ResourceTemplateOption {
return func(rt *ResourceTemplate) {
rt.Icons = icons
}
}
}
9 changes: 8 additions & 1 deletion mcp/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,13 @@ func ExtractString(data map[string]any, key string) string {
return ""
}

// ParseAnnotations parses priority, audience, and lastModified fields from the provided map
// and returns an Annotations struct populated with any valid values found.
//
// If data is nil, ParseAnnotations returns nil.
// Priority is set when a numeric value can be parsed and is stored as a *float64.
// Audience is populated from string values and includes only RoleUser and RoleAssistant entries.
// LastModified is set when the corresponding value is a string.
func ParseAnnotations(data map[string]any) *Annotations {
if data == nil {
return nil
Expand Down Expand Up @@ -986,4 +993,4 @@ func GetTextFromContent(content any) string {
default:
return fmt.Sprintf("%v", content)
}
}
}