Skip to content
Merged
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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 0 additions & 2 deletions auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions internal/jsonrpc2/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
//
Expand Down
2 changes: 1 addition & 1 deletion internal/readme/README.src.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion internal/readme/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion internal/readme/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions jsonrpc/jsonrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions mcp/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
}
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions mcp/content.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,15 @@ 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")
}
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 != "" {
Expand Down
1 change: 0 additions & 1 deletion mcp/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion mcp/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
//
Expand Down
1 change: 1 addition & 0 deletions mcp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions mcp/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions oauthex/oauthex.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading