diff --git a/README.md b/README.md index a12a0267..8b093f5a 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ The SDK consists of several importable packages: their own transports. - The [`github.com/modelcontextprotocol/go-sdk/auth`](https://pkg.go.dev/github.com/modelcontextprotocol/go-sdk/auth) - package provides some primitives for supporting oauth. + package provides some primitives for supporting OAuth. - The [`github.com/modelcontextprotocol/go-sdk/oauthex`](https://pkg.go.dev/github.com/modelcontextprotocol/go-sdk/oauthex) package provides extensions to the OAuth protocol, such as ProtectedResourceMetadata. @@ -78,7 +78,7 @@ func main() { // Create a server with a single tool. server := mcp.NewServer(&mcp.Implementation{Name: "greeter", Version: "v1.0.0"}, nil) mcp.AddTool(server, &mcp.Tool{Name: "greet", Description: "say hi"}, SayHi) - // Run the server over stdin/stdout, until the client disconnects + // Run the server over stdin/stdout, until the client disconnects. if err := server.Run(context.Background(), &mcp.StdioTransport{}); err != nil { log.Fatal(err) } @@ -106,7 +106,7 @@ func main() { // Create a new client, with no features. client := mcp.NewClient(&mcp.Implementation{Name: "mcp-client", Version: "v1.0.0"}, nil) - // Connect to a server over stdin/stdout + // Connect to a server over stdin/stdout. transport := &mcp.CommandTransport{Command: exec.Command("myserver")} session, err := client.Connect(ctx, transport, nil) if err != nil { diff --git a/auth/auth.go b/auth/auth.go index 7cc0074a..0eea1d87 100644 --- a/auth/auth.go +++ b/auth/auth.go @@ -56,8 +56,6 @@ func TokenInfoFromContext(ctx context.Context) *TokenInfo { // If verification succeeds, the [TokenInfo] is added to the request's context and the request proceeds. // If verification fails, the request fails with a 401 Unauthenticated, and the WWW-Authenticate header // is populated to enable [protected resource metadata]. -// - // // [protected resource metadata]: https://datatracker.ietf.org/doc/rfc9728 func RequireBearerToken(verifier TokenVerifier, opts *RequireBearerTokenOptions) func(http.Handler) http.Handler { diff --git a/internal/jsonrpc2/messages.go b/internal/jsonrpc2/messages.go index 9c0d5d69..791e698d 100644 --- a/internal/jsonrpc2/messages.go +++ b/internal/jsonrpc2/messages.go @@ -16,8 +16,8 @@ type ID struct { value any } -// MakeID coerces the given Go value to an ID. The value is assumed to be the -// default JSON marshaling of a Request identifier -- nil, float64, or string. +// MakeID coerces the given Go value to an ID. The value should be the +// default JSON marshaling of a Request identifier: nil, float64, or string. // // Returns an error if the value type was not a valid Request ID type. // diff --git a/internal/readme/README.src.md b/internal/readme/README.src.md index 10ce9b67..08944a8c 100644 --- a/internal/readme/README.src.md +++ b/internal/readme/README.src.md @@ -32,7 +32,7 @@ The SDK consists of several importable packages: their own transports. - The [`github.com/modelcontextprotocol/go-sdk/auth`](https://pkg.go.dev/github.com/modelcontextprotocol/go-sdk/auth) - package provides some primitives for supporting oauth. + package provides some primitives for supporting OAuth. - The [`github.com/modelcontextprotocol/go-sdk/oauthex`](https://pkg.go.dev/github.com/modelcontextprotocol/go-sdk/oauthex) package provides extensions to the OAuth protocol, such as ProtectedResourceMetadata. diff --git a/internal/readme/client/client.go b/internal/readme/client/client.go index 9f357964..8fc99727 100644 --- a/internal/readme/client/client.go +++ b/internal/readme/client/client.go @@ -19,7 +19,7 @@ func main() { // Create a new client, with no features. client := mcp.NewClient(&mcp.Implementation{Name: "mcp-client", Version: "v1.0.0"}, nil) - // Connect to a server over stdin/stdout + // Connect to a server over stdin/stdout. transport := &mcp.CommandTransport{Command: exec.Command("myserver")} session, err := client.Connect(ctx, transport, nil) if err != nil { diff --git a/internal/readme/server/server.go b/internal/readme/server/server.go index bfa08254..5d7656df 100644 --- a/internal/readme/server/server.go +++ b/internal/readme/server/server.go @@ -32,7 +32,7 @@ func main() { // Create a server with a single tool. server := mcp.NewServer(&mcp.Implementation{Name: "greeter", Version: "v1.0.0"}, nil) mcp.AddTool(server, &mcp.Tool{Name: "greet", Description: "say hi"}, SayHi) - // Run the server over stdin/stdout, until the client disconnects + // Run the server over stdin/stdout, until the client disconnects. if err := server.Run(context.Background(), &mcp.StdioTransport{}); err != nil { log.Fatal(err) } diff --git a/jsonrpc/jsonrpc.go b/jsonrpc/jsonrpc.go index 1cf1202f..1633d4e3 100644 --- a/jsonrpc/jsonrpc.go +++ b/jsonrpc/jsonrpc.go @@ -19,8 +19,8 @@ type ( Response = jsonrpc2.Response ) -// MakeID coerces the given Go value to an ID. The value is assumed to be the -// default JSON marshaling of a Request identifier -- nil, float64, or string. +// MakeID coerces the given Go value to an ID. The value should be the +// default JSON marshaling of a Request identifier: nil, float64, or string. // // Returns an error if the value type was not a valid Request ID type. func MakeID(v any) (ID, error) { diff --git a/mcp/client.go b/mcp/client.go index dea3e854..ad95384b 100644 --- a/mcp/client.go +++ b/mcp/client.go @@ -668,7 +668,7 @@ func (cs *ClientSession) callProgressNotificationHandler(ctx context.Context, pa // NotifyProgress sends a progress notification from the client to the server // associated with this session. // This can be used if the client is performing a long-running task that was -// initiated by the server +// initiated by the server. func (cs *ClientSession) NotifyProgress(ctx context.Context, params *ProgressNotificationParams) error { return handleNotify(ctx, notificationProgress, newClientRequest(cs, orZero[Params](params))) } @@ -701,7 +701,7 @@ func (cs *ClientSession) Resources(ctx context.Context, params *ListResourcesPar // ResourceTemplates provides an iterator for all resource templates available on the server, // automatically fetching pages and managing cursors. -// The `params` argument can set the initial cursor. +// The params argument can set the initial cursor. // Iteration stops at the first encountered error, which will be yielded. func (cs *ClientSession) ResourceTemplates(ctx context.Context, params *ListResourceTemplatesParams) iter.Seq2[*ResourceTemplate, error] { if params == nil { diff --git a/mcp/content.go b/mcp/content.go index 108b0271..e53cad14 100644 --- a/mcp/content.go +++ b/mcp/content.go @@ -189,7 +189,7 @@ type ResourceContents struct { Meta Meta `json:"_meta,omitempty"` } -func (r ResourceContents) MarshalJSON() ([]byte, error) { +func (r *ResourceContents) MarshalJSON() ([]byte, error) { // If we could assume Go 1.24, we could use omitzero for Blob and avoid this method. if r.URI == "" { return nil, errors.New("ResourceContents missing URI") @@ -197,7 +197,7 @@ func (r ResourceContents) MarshalJSON() ([]byte, error) { if r.Blob == nil { // Text. Marshal normally. type wireResourceContents ResourceContents // (lacks MarshalJSON method) - return json.Marshal((wireResourceContents)(r)) + return json.Marshal((wireResourceContents)(*r)) } // Blob. if r.Text != "" { diff --git a/mcp/event.go b/mcp/event.go index bd78cdee..1dd36f4e 100644 --- a/mcp/event.go +++ b/mcp/event.go @@ -176,7 +176,6 @@ type EventStore interface { // with all of its streams. // A store cannot rely on this method being called for cleanup. It should institute // additional mechanisms, such as timeouts, to reclaim storage. - // SessionClosed(_ context.Context, sessionID string) error // There is no StreamClosed method. A server doesn't know when a stream is finished, because diff --git a/mcp/protocol.go b/mcp/protocol.go index f3f23f58..eacb9047 100644 --- a/mcp/protocol.go +++ b/mcp/protocol.go @@ -18,7 +18,7 @@ import ( ) // Optional annotations for the client. The client can use annotations to inform -// how objects are used or displayed +// how objects are used or displayed. type Annotations struct { // Describes who the intended customer of this object or data is. // diff --git a/mcp/server.go b/mcp/server.go index 27de09a3..882ac9fa 100644 --- a/mcp/server.go +++ b/mcp/server.go @@ -27,6 +27,7 @@ import ( "github.com/yosida95/uritemplate/v3" ) +// DefaultPageSize is the default for [ServerOptions.PageSize]. const DefaultPageSize = 1000 // A Server is an instance of an MCP server. diff --git a/mcp/shared.go b/mcp/shared.go index 69b8836a..46e994f6 100644 --- a/mcp/shared.go +++ b/mcp/shared.go @@ -453,13 +453,13 @@ func clientRequestFor[P Params](s *ClientSession, p P) *ClientRequest[P] { // Params is a parameter (input) type for an MCP call or notification. type Params interface { - // isParams discourages implementation of Params outside of this package. - isParams() - // GetMeta returns metadata from a value. GetMeta() map[string]any // SetMeta sets the metadata on a value. SetMeta(map[string]any) + + // isParams discourages implementation of Params outside of this package. + isParams() } // RequestParams is a parameter (input) type for an MCP request. diff --git a/oauthex/oauthex.go b/oauthex/oauthex.go index eb3a3e78..df326781 100644 --- a/oauthex/oauthex.go +++ b/oauthex/oauthex.go @@ -7,4 +7,6 @@ package oauthex import "github.com/modelcontextprotocol/go-sdk/internal/oauthex" +// ProtectedResourceMetadata is the metadata for an OAuth 2.0 protected resource, +// as defined in section 2 of https://www.rfc-editor.org/rfc/rfc9728.html. type ProtectedResourceMetadata = oauthex.ProtectedResourceMetadata