Skip to content

Commit 1db477e

Browse files
authored
Add docstrings for annotation-related functions (#673)
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
1 parent bd8762d commit 1db477e

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

mcp/resources.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ func WithMIMEType(mimeType string) ResourceOption {
4242
}
4343
}
4444

45-
// WithAnnotations adds annotations to the Resource.
46-
// Annotations can provide additional metadata about the resource's intended use.
45+
// WithAnnotations returns a ResourceOption that sets the resource's Annotations fields.
46+
// It initializes Annotations if nil, sets Audience to the provided slice,
47+
// stores Priority as a pointer to the provided value, and sets LastModified to the provided timestamp.
4748
func WithAnnotations(audience []Role, priority float64, lastModified string) ResourceOption {
4849
return func(r *Resource) {
4950
if r.Annotations == nil {
@@ -55,9 +56,9 @@ func WithAnnotations(audience []Role, priority float64, lastModified string) Res
5556
}
5657
}
5758

58-
// WithLastModified adds a last modified timestamp to the Resource.
59-
// The timestamp should be in ISO 8601 format (e.g., "2025-01-12T15:00:58Z").
60-
// Callers should use ValidateISO8601Timestamp to validate the timestamp before use.
59+
// WithLastModified returns a ResourceOption that sets the resource's Annotations.LastModified
60+
// to the provided timestamp. If the resource's Annotations is nil, it will be initialized.
61+
// The timestamp is expected to be an ISO 8601 (RFC3339) formatted string (e.g., "2025-01-12T15:00:58Z").
6162
func WithLastModified(timestamp string) ResourceOption {
6263
return func(r *Resource) {
6364
if r.Annotations == nil {
@@ -103,8 +104,8 @@ func WithTemplateMIMEType(mimeType string) ResourceTemplateOption {
103104
}
104105
}
105106

106-
// WithTemplateAnnotations adds annotations to the ResourceTemplate.
107-
// Annotations can provide additional metadata about the template's intended use.
107+
// WithTemplateAnnotations returns a ResourceTemplateOption that sets the template's
108+
// Annotations field, initializing it if nil, and setting Audience, Priority, and LastModified.
108109
func WithTemplateAnnotations(audience []Role, priority float64, lastModified string) ResourceTemplateOption {
109110
return func(t *ResourceTemplate) {
110111
if t.Annotations == nil {
@@ -116,7 +117,9 @@ func WithTemplateAnnotations(audience []Role, priority float64, lastModified str
116117
}
117118
}
118119

119-
// ValidateISO8601Timestamp checks if a string is a valid ISO 8601 timestamp
120+
// ValidateISO8601Timestamp verifies that timestamp is a valid ISO 8601 timestamp
121+
// using the RFC3339 layout. An empty string is considered valid. It returns nil
122+
// when the timestamp is valid, or the parsing error when it is not.
120123
func ValidateISO8601Timestamp(timestamp string) error {
121124
if timestamp == "" {
122125
return nil // Empty is valid (optional field)

mcp/utils.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,11 @@ func ExtractString(data map[string]any, key string) string {
536536
return ""
537537
}
538538

539+
// ParseAnnotations parses priority, audience, and lastModified fields from the provided map
540+
// and returns an Annotations struct populated with any valid values found.
541+
// If data is nil, ParseAnnotations returns nil. Priority is set when a numeric value can be
542+
// parsed and is stored as a *float64. Audience is populated from string values and includes
543+
// only RoleUser and RoleAssistant entries. LastModified is set when the value is a string.
539544
func ParseAnnotations(data map[string]any) *Annotations {
540545
if data == nil {
541546
return nil

0 commit comments

Comments
 (0)