Skip to content

Commit ff0d746

Browse files
authored
mcp: fix some documentation (#41)
- Add some doc strings. - Remove markdown-like notations.
1 parent 81eb55e commit ff0d746

File tree

2 files changed

+36
-28
lines changed

2 files changed

+36
-28
lines changed

mcp/protocol.go

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ type Annotations struct {
2222
// Describes who the intended customer of this object or data is.
2323
//
2424
// It can include multiple entries to indicate content useful for multiple
25-
// audiences (e.g., `["user", "assistant"]`).
25+
// audiences (e.g., []Role{"user", "assistant"}).
2626
Audience []Role `json:"audience,omitempty"`
2727
// The moment the resource was last modified, as an ISO 8601 formatted string.
2828
//
@@ -70,12 +70,12 @@ type CallToolResult struct {
7070
//
7171
// If not set, this is assumed to be false (the call was successful).
7272
//
73-
// Any errors that originate from the tool SHOULD be reported inside the result
74-
// object, with `isError` set to true, _not_ as an MCP protocol-level error
73+
// Any errors that originate from the tool should be reported inside the result
74+
// object, with isError set to true, not as an MCP protocol-level error
7575
// response. Otherwise, the LLM would not be able to see that an error occurred
7676
// and self-correct.
7777
//
78-
// However, any errors in _finding_ the tool, an error indicating that the
78+
// However, any errors in finding the tool, an error indicating that the
7979
// server does not support tool calls, or any other exceptional conditions,
8080
// should be reported as an MCP error response.
8181
IsError bool `json:"isError,omitempty"`
@@ -115,8 +115,8 @@ type CallToolResultFor[Out any] struct {
115115
//
116116
// If not set, this is assumed to be false (the call was successful).
117117
//
118-
// Any errors that originate from the tool SHOULD be reported inside the result
119-
// object, with `isError` set to true, not as an MCP protocol-level error
118+
// Any errors that originate from the tool should be reported inside the result
119+
// object, with isError set to true, not as an MCP protocol-level error
120120
// response. Otherwise, the LLM would not be able to see that an error occurred
121121
// and self-correct.
122122
//
@@ -152,12 +152,12 @@ type CancelledParams struct {
152152
// This property is reserved by the protocol to allow clients and servers to
153153
// attach additional metadata to their responses.
154154
Meta `json:"_meta,omitempty"`
155-
// An optional string describing the reason for the cancellation. This MAY be
155+
// An optional string describing the reason for the cancellation. This may be
156156
// logged or presented to the user.
157157
Reason string `json:"reason,omitempty"`
158158
// The ID of the request to cancel.
159159
//
160-
// This MUST correspond to the ID of a request previously issued in the same
160+
// This must correspond to the ID of a request previously issued in the same
161161
// direction.
162162
RequestID any `json:"requestId"`
163163
}
@@ -187,21 +187,21 @@ type CreateMessageParams struct {
187187
// attach additional metadata to their responses.
188188
Meta `json:"_meta,omitempty"`
189189
// A request to include context from one or more MCP servers (including the
190-
// caller), to be attached to the prompt. The client MAY ignore this request.
190+
// caller), to be attached to the prompt. The client may ignore this request.
191191
IncludeContext string `json:"includeContext,omitempty"`
192192
// The maximum number of tokens to sample, as requested by the server. The
193-
// client MAY choose to sample fewer tokens than requested.
193+
// client may choose to sample fewer tokens than requested.
194194
MaxTokens int64 `json:"maxTokens"`
195195
Messages []*SamplingMessage `json:"messages"`
196196
// Optional metadata to pass through to the LLM provider. The format of this
197197
// metadata is provider-specific.
198198
Metadata struct{} `json:"metadata,omitempty"`
199-
// The server's preferences for which model to select. The client MAY ignore
199+
// The server's preferences for which model to select. The client may ignore
200200
// these preferences.
201201
ModelPreferences *ModelPreferences `json:"modelPreferences,omitempty"`
202202
StopSequences []string `json:"stopSequences,omitempty"`
203203
// An optional system prompt the server wants to use for sampling. The client
204-
// MAY modify or omit this prompt.
204+
// may modify or omit this prompt.
205205
SystemPrompt string `json:"systemPrompt,omitempty"`
206206
Temperature float64 `json:"temperature,omitempty"`
207207
}
@@ -255,7 +255,7 @@ type InitializeParams struct {
255255
Capabilities *ClientCapabilities `json:"capabilities"`
256256
ClientInfo *implementation `json:"clientInfo"`
257257
// The latest version of the Model Context Protocol that the client supports.
258-
// The client MAY decide to support older versions as well.
258+
// The client may decide to support older versions as well.
259259
ProtocolVersion string `json:"protocolVersion"`
260260
}
261261

@@ -273,11 +273,11 @@ type InitializeResult struct {
273273
//
274274
// This can be used by clients to improve the LLM's understanding of available
275275
// tools, resources, etc. It can be thought of like a "hint" to the model. For
276-
// example, this information MAY be added to the system prompt.
276+
// example, this information may be added to the system prompt.
277277
Instructions string `json:"instructions,omitempty"`
278278
// The version of the Model Context Protocol that the server wants to use. This
279279
// may not match the version that the client requested. If the client cannot
280-
// support this version, it MUST disconnect.
280+
// support this version, it must disconnect.
281281
ProtocolVersion string `json:"protocolVersion"`
282282
ServerInfo *implementation `json:"serverInfo"`
283283
}
@@ -443,12 +443,12 @@ func (x *LoggingMessageParams) SetProgressToken(t any) { setProgressToken(x, t)
443443
type ModelHint struct {
444444
// A hint for a model name.
445445
//
446-
// The client SHOULD treat this as a substring of a model name; for example: -
446+
// The client should treat this as a substring of a model name; for example: -
447447
// `claude-3-5-sonnet` should match `claude-3-5-sonnet-20241022` - `sonnet`
448448
// should match `claude-3-5-sonnet-20241022`, `claude-3-sonnet-20240229`, etc. -
449449
// `claude` should match any Claude model
450450
//
451-
// The client MAY also map the string to a different provider's model name or a
451+
// The client may also map the string to a different provider's model name or a
452452
// different model family, as long as it fills a similar niche; for example: -
453453
// `gemini-1.5-flash` could match `claude-3-haiku-20240307`
454454
Name string `json:"name,omitempty"`
@@ -463,7 +463,7 @@ type ModelHint struct {
463463
// on. This interface allows servers to express their priorities across multiple
464464
// dimensions to help clients make an appropriate selection for their use case.
465465
//
466-
// These preferences are always advisory. The client MAY ignore them. It is also
466+
// These preferences are always advisory. The client may ignore them. It is also
467467
// up to the client to decide how to interpret these preferences and how to
468468
// balance them against other considerations.
469469
type ModelPreferences struct {
@@ -472,10 +472,10 @@ type ModelPreferences struct {
472472
CostPriority float64 `json:"costPriority,omitempty"`
473473
// Optional hints to use for model selection.
474474
//
475-
// If multiple hints are specified, the client MUST evaluate them in order (such
475+
// If multiple hints are specified, the client must evaluate them in order (such
476476
// that the first match is taken).
477477
//
478-
// The client SHOULD prioritize these hints over the numeric priorities, but MAY
478+
// The client should prioritize these hints over the numeric priorities, but may
479479
// still use the priorities to select from ambiguous matches.
480480
Hints []*ModelHint `json:"hints,omitempty"`
481481
// How much to prioritize intelligence and capabilities when selecting a model.
@@ -555,7 +555,7 @@ func (x *PromptListChangedParams) SetProgressToken(t any) { setProgressToken(x,
555555

556556
// Describes a message returned as part of a prompt.
557557
//
558-
// This is similar to `SamplingMessage`, but also supports the embedding of
558+
// This is similar to SamplingMessage, but also supports the embedding of
559559
// resources from the MCP server.
560560
type PromptMessage struct {
561561
Content Content `json:"content"`
@@ -628,7 +628,7 @@ type Resource struct {
628628
// easily understood, even by those unfamiliar with domain-specific terminology.
629629
//
630630
// If not provided, the name should be used for display (except for Tool, where
631-
// `annotations.title` should be given precedence over using `name`, if
631+
// Annotations.Title should be given precedence over using name, if
632632
// present).
633633
Title string `json:"title,omitempty"`
634634
// The URI of this resource.
@@ -666,7 +666,7 @@ type ResourceTemplate struct {
666666
// easily understood, even by those unfamiliar with domain-specific terminology.
667667
//
668668
// If not provided, the name should be used for display (except for Tool, where
669-
// `annotations.title` should be given precedence over using `name`, if
669+
// Annotations.Title should be given precedence over using name, if
670670
// present).
671671
Title string `json:"title,omitempty"`
672672
// A URI template (according to RFC 6570) that can be used to construct resource
@@ -776,24 +776,24 @@ type Tool struct {
776776

777777
// Additional properties describing a Tool to clients.
778778
//
779-
// NOTE: all properties in ToolAnnotations are **hints**. They are not
779+
// NOTE: all properties in ToolAnnotations are hints. They are not
780780
// guaranteed to provide a faithful description of tool behavior (including
781-
// descriptive properties like `title`).
781+
// descriptive properties like title).
782782
//
783783
// Clients should never make tool use decisions based on ToolAnnotations
784784
// received from untrusted servers.
785785
type ToolAnnotations struct {
786786
// If true, the tool may perform destructive updates to its environment. If
787787
// false, the tool performs only additive updates.
788788
//
789-
// (This property is meaningful only when `readOnlyHint == false`)
789+
// (This property is meaningful only when ReadOnlyHint == false.)
790790
//
791791
// Default: true
792792
DestructiveHint *bool `json:"destructiveHint,omitempty"`
793793
// If true, calling the tool repeatedly with the same arguments will have no
794794
// additional effect on the its environment.
795795
//
796-
// (This property is meaningful only when `readOnlyHint == false`)
796+
// (This property is meaningful only when ReadOnlyHint == false.)
797797
//
798798
// Default: false
799799
IdempotentHint bool `json:"idempotentHint,omitempty"`

mcp/shared.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,13 @@ func notifySessions[S Session](sessions []S, method string, params Params) {
236236
}
237237
}
238238

239+
// Meta is additional metadata for requests, responses and other types.
239240
type Meta map[string]any
240241

241-
func (m Meta) GetMeta() map[string]any { return m }
242+
// GetMeta returns metadata from a value.
243+
func (m Meta) GetMeta() map[string]any { return m }
244+
245+
// SetMeta sets the metadata on a value.
242246
func (m *Meta) SetMeta(x map[string]any) { *m = x }
243247

244248
const progressTokenKey = "progressToken"
@@ -263,7 +267,9 @@ func setProgressToken(p Params, pt any) {
263267

264268
// Params is a parameter (input) type for an MCP call or notification.
265269
type Params interface {
270+
// GetMeta returns metadata from a value.
266271
GetMeta() map[string]any
272+
// SetMeta sets the metadata on a value.
267273
SetMeta(map[string]any)
268274
}
269275

@@ -282,7 +288,9 @@ type RequestParams interface {
282288

283289
// Result is a result of an MCP call.
284290
type Result interface {
291+
// GetMeta returns metadata from a value.
285292
GetMeta() map[string]any
293+
// SetMeta sets the metadata on a value.
286294
SetMeta(map[string]any)
287295
}
288296

0 commit comments

Comments
 (0)