Skip to content

Commit 75c8478

Browse files
committed
mcp: fix some documentation
- Add some doc strings. - Remove markdown-like notations.
1 parent abb650e commit 75c8478

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
//
@@ -133,12 +133,12 @@ type CancelledParams struct {
133133
// This property is reserved by the protocol to allow clients and servers to
134134
// attach additional metadata to their responses.
135135
Meta `json:"_meta,omitempty"`
136-
// An optional string describing the reason for the cancellation. This MAY be
136+
// An optional string describing the reason for the cancellation. This may be
137137
// logged or presented to the user.
138138
Reason string `json:"reason,omitempty"`
139139
// The ID of the request to cancel.
140140
//
141-
// This MUST correspond to the ID of a request previously issued in the same
141+
// This must correspond to the ID of a request previously issued in the same
142142
// direction.
143143
RequestID any `json:"requestId"`
144144
}
@@ -168,21 +168,21 @@ type CreateMessageParams struct {
168168
// attach additional metadata to their responses.
169169
Meta `json:"_meta,omitempty"`
170170
// A request to include context from one or more MCP servers (including the
171-
// caller), to be attached to the prompt. The client MAY ignore this request.
171+
// caller), to be attached to the prompt. The client may ignore this request.
172172
IncludeContext string `json:"includeContext,omitempty"`
173173
// The maximum number of tokens to sample, as requested by the server. The
174-
// client MAY choose to sample fewer tokens than requested.
174+
// client may choose to sample fewer tokens than requested.
175175
MaxTokens int64 `json:"maxTokens"`
176176
Messages []*SamplingMessage `json:"messages"`
177177
// Optional metadata to pass through to the LLM provider. The format of this
178178
// metadata is provider-specific.
179179
Metadata struct{} `json:"metadata,omitempty"`
180-
// The server's preferences for which model to select. The client MAY ignore
180+
// The server's preferences for which model to select. The client may ignore
181181
// these preferences.
182182
ModelPreferences *ModelPreferences `json:"modelPreferences,omitempty"`
183183
StopSequences []string `json:"stopSequences,omitempty"`
184184
// An optional system prompt the server wants to use for sampling. The client
185-
// MAY modify or omit this prompt.
185+
// may modify or omit this prompt.
186186
SystemPrompt string `json:"systemPrompt,omitempty"`
187187
Temperature float64 `json:"temperature,omitempty"`
188188
}
@@ -236,7 +236,7 @@ type InitializeParams struct {
236236
Capabilities *ClientCapabilities `json:"capabilities"`
237237
ClientInfo *implementation `json:"clientInfo"`
238238
// The latest version of the Model Context Protocol that the client supports.
239-
// The client MAY decide to support older versions as well.
239+
// The client may decide to support older versions as well.
240240
ProtocolVersion string `json:"protocolVersion"`
241241
}
242242

@@ -254,11 +254,11 @@ type InitializeResult struct {
254254
//
255255
// This can be used by clients to improve the LLM's understanding of available
256256
// tools, resources, etc. It can be thought of like a "hint" to the model. For
257-
// example, this information MAY be added to the system prompt.
257+
// example, this information may be added to the system prompt.
258258
Instructions string `json:"instructions,omitempty"`
259259
// The version of the Model Context Protocol that the server wants to use. This
260260
// may not match the version that the client requested. If the client cannot
261-
// support this version, it MUST disconnect.
261+
// support this version, it must disconnect.
262262
ProtocolVersion string `json:"protocolVersion"`
263263
ServerInfo *implementation `json:"serverInfo"`
264264
}
@@ -424,12 +424,12 @@ func (x *LoggingMessageParams) SetProgressToken(t any) { setProgressToken(x, t)
424424
type ModelHint struct {
425425
// A hint for a model name.
426426
//
427-
// The client SHOULD treat this as a substring of a model name; for example: -
427+
// The client should treat this as a substring of a model name; for example: -
428428
// `claude-3-5-sonnet` should match `claude-3-5-sonnet-20241022` - `sonnet`
429429
// should match `claude-3-5-sonnet-20241022`, `claude-3-sonnet-20240229`, etc. -
430430
// `claude` should match any Claude model
431431
//
432-
// The client MAY also map the string to a different provider's model name or a
432+
// The client may also map the string to a different provider's model name or a
433433
// different model family, as long as it fills a similar niche; for example: -
434434
// `gemini-1.5-flash` could match `claude-3-haiku-20240307`
435435
Name string `json:"name,omitempty"`
@@ -444,7 +444,7 @@ type ModelHint struct {
444444
// on. This interface allows servers to express their priorities across multiple
445445
// dimensions to help clients make an appropriate selection for their use case.
446446
//
447-
// These preferences are always advisory. The client MAY ignore them. It is also
447+
// These preferences are always advisory. The client may ignore them. It is also
448448
// up to the client to decide how to interpret these preferences and how to
449449
// balance them against other considerations.
450450
type ModelPreferences struct {
@@ -453,10 +453,10 @@ type ModelPreferences struct {
453453
CostPriority float64 `json:"costPriority,omitempty"`
454454
// Optional hints to use for model selection.
455455
//
456-
// If multiple hints are specified, the client MUST evaluate them in order (such
456+
// If multiple hints are specified, the client must evaluate them in order (such
457457
// that the first match is taken).
458458
//
459-
// The client SHOULD prioritize these hints over the numeric priorities, but MAY
459+
// The client should prioritize these hints over the numeric priorities, but may
460460
// still use the priorities to select from ambiguous matches.
461461
Hints []*ModelHint `json:"hints,omitempty"`
462462
// How much to prioritize intelligence and capabilities when selecting a model.
@@ -536,7 +536,7 @@ func (x *PromptListChangedParams) SetProgressToken(t any) { setProgressToken(x,
536536

537537
// Describes a message returned as part of a prompt.
538538
//
539-
// This is similar to `SamplingMessage`, but also supports the embedding of
539+
// This is similar to SamplingMessage, but also supports the embedding of
540540
// resources from the MCP server.
541541
type PromptMessage struct {
542542
Content Content `json:"content"`
@@ -609,7 +609,7 @@ type Resource struct {
609609
// easily understood, even by those unfamiliar with domain-specific terminology.
610610
//
611611
// If not provided, the name should be used for display (except for Tool, where
612-
// `annotations.title` should be given precedence over using `name`, if
612+
// Annotations.Title should be given precedence over using name, if
613613
// present).
614614
Title string `json:"title,omitempty"`
615615
// The URI of this resource.
@@ -647,7 +647,7 @@ type ResourceTemplate struct {
647647
// easily understood, even by those unfamiliar with domain-specific terminology.
648648
//
649649
// If not provided, the name should be used for display (except for Tool, where
650-
// `annotations.title` should be given precedence over using `name`, if
650+
// Annotations.Title should be given precedence over using name, if
651651
// present).
652652
Title string `json:"title,omitempty"`
653653
// A URI template (according to RFC 6570) that can be used to construct resource
@@ -757,24 +757,24 @@ type Tool struct {
757757

758758
// Additional properties describing a Tool to clients.
759759
//
760-
// NOTE: all properties in ToolAnnotations are **hints**. They are not
760+
// NOTE: all properties in ToolAnnotations are hints. They are not
761761
// guaranteed to provide a faithful description of tool behavior (including
762-
// descriptive properties like `title`).
762+
// descriptive properties like title).
763763
//
764764
// Clients should never make tool use decisions based on ToolAnnotations
765765
// received from untrusted servers.
766766
type ToolAnnotations struct {
767767
// If true, the tool may perform destructive updates to its environment. If
768768
// false, the tool performs only additive updates.
769769
//
770-
// (This property is meaningful only when `readOnlyHint == false`)
770+
// (This property is meaningful only when ReadOnlyHint == false.)
771771
//
772772
// Default: true
773773
DestructiveHint bool `json:"destructiveHint,omitempty"`
774774
// If true, calling the tool repeatedly with the same arguments will have no
775775
// additional effect on the its environment.
776776
//
777-
// (This property is meaningful only when `readOnlyHint == false`)
777+
// (This property is meaningful only when ReadOnlyHint == false.)
778778
//
779779
// Default: false
780780
IdempotentHint bool `json:"idempotentHint,omitempty"`

mcp/shared.go

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

245+
// Meta is additional metadata for requests, responses and other types.
245246
type Meta map[string]any
246247

247-
func (m Meta) GetMeta() map[string]any { return m }
248+
// GetMeta returns metadata from a value.
249+
func (m Meta) GetMeta() map[string]any { return m }
250+
251+
// SetMeta sets the metadata on a value.
248252
func (m *Meta) SetMeta(x map[string]any) { *m = x }
249253

250254
const progressTokenKey = "progressToken"
@@ -269,7 +273,9 @@ func setProgressToken(p Params, pt any) {
269273

270274
// Params is a parameter (input) type for an MCP call or notification.
271275
type Params interface {
276+
// GetMeta returns metadata from a value.
272277
GetMeta() map[string]any
278+
// SetMeta sets the metadata on a value.
273279
SetMeta(map[string]any)
274280
}
275281

@@ -288,7 +294,9 @@ type RequestParams interface {
288294

289295
// Result is a result of an MCP call.
290296
type Result interface {
297+
// GetMeta returns metadata from a value.
291298
GetMeta() map[string]any
299+
// SetMeta sets the metadata on a value.
292300
SetMeta(map[string]any)
293301
}
294302

0 commit comments

Comments
 (0)