Replies: 13 comments 24 replies
-
Thank you so much for hard work on this! Excited to try this out at GitHub. 🔥 |
Beta Was this translation helpful? Give feedback.
-
This looks great, thank you for your work. As I read the function signatures, I had a similar question as: mark3labs/mcp-go#294, which perhaps you also have a good answer for. You say:
And the type ToolHandler func(context.Context, *ServerSession, *CallToolParams) (*CallToolResult, error) Under what circumstances would you expect a Tool to return a non-nil |
Beta Was this translation helpful? Give feedback.
-
@findleyr, as valuable as this document is for noodling on, I'm very eager to get my hands on the implementation to give feedback based on empirical use. At the top of the discussion you said:
Please let me know if you start executing in such a way that I can start trying it out. |
Beta Was this translation helpful? Give feedback.
-
Really excited to see this moving forward — the design looks thoughtful and well aligned with Go idioms. I’d be happy to help with early testing, especially around session handling, transport abstractions, and tool integration. Please feel free to loop me in where hands-on feedback would be most useful. Looking forward to contributing! |
Beta Was this translation helpful? Give feedback.
-
Thanks for the doc @findleyr. As you know I am mostly looking at the observability aspect of the SDK, especially propagating distributed context. Some initial thoughts
|
Beta Was this translation helpful? Give feedback.
-
Hello @findleyr and fellow contributors, Thanks for the very thoughtful design proposal and discussion. I have an alternate proposal and discussion that I kickstarted with the rust sdk authors here Reproducing the gist of that discussion here: Folks, as MCP’s language ecosystem expands, we’re spending more time re‑implementing the same deterministic‑state logic than shipping new ideas. I’d like us to flip that ratio by standardizing on a single, Rust core (rust‑sdk) that owns the workflow engine— sessions, peering, transport, serialization—while each language surface (Python, JS/TS, Go, etc.) stays 100 % idiomatic and lightweight. Rust gives us memory‑safe, no‑GC performance overhead, a stable FFI, and a proven path. The payoff is immediate: one quality, security and performance audit instead of five, feature parity across languages on day 1, and p99 latencies that drop from milliseconds to microseconds—without asking Python or JavaScript developers to learn Rust. In short, one deterministic engine, many friendly faces. We have built a V 0.1 Python and Typescript SDK based on this architecture so that we write less boilerplate and innovate faster on the parts that matter. I know that as Golang stewards and enthusiasts you may want to write the SDK from scratch but would love to hear your views and counterpoints to this. The Python Bindings PR is here The Typescript Bindings PR is here |
Beta Was this translation helpful? Give feedback.
-
I think this might be consistent with other MCP SDKs, but I did want to mention that having the client by default always claim to have roots support is sometimes not ideal, because while the protocol may be "supported", that doesn't mean the client actually ever will set any roots. This makes it difficult for a server to handle clients which don't actually ever set roots, for instance they may want to conditionally add a tool to manage roots. I ran into this developing the MCP server for Dart/Flutter tooling, cursor claims to support roots but does not actually support them, so I had to add a flag to force enable a fallback mode instead of relying on detection of the supported features. |
Beta Was this translation helpful? Give feedback.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as spam.
This comment was marked as spam.
-
Had a random thought, I was wondering what the future of the design is in terms of ownership. I found the section on package layout
which seems to indicate the future is in the If the intention is to be I think it would be quite helpful to clarify what the goals are in terms of ownership and community engagement in this design, probably more so than even the technical details which will all somehow be resolved before a v1 release by the community. My advice would be to add a |
Beta Was this translation helpful? Give feedback.
This comment was marked as disruptive content.
This comment was marked as disruptive content.
This comment was marked as disruptive content.
This comment was marked as disruptive content.
-
🔥 Design looks impeccable, as I'd expect from the Go team!!!!!! Great work Robert! Can't wait to get my hands on it re: Governance and ownershipOne area I see as missing from this discussion is how the SDK will be governed and managed - Go code is one thing, governing the Go community around the SDK is another. From what I've inferred:
Open questions from this structure:
I don't think this is blocking, just would be good to iron out now. And maybe some of these questions are things that are better left for the core |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Pre-submission Checklist
Your Idea
Hi everyone 👋! This is a design discussion for the Go MCP SDK, following up on /discussions/224, where we (the Go team) volunteered to help contribute an official SDK.
In the original discussion, many people expressed support for a Go SDK, which is fantastic. With so much interest, we felt that it was more important than ever to start with a concrete design; otherwise we’d risk a lot of churn as we all worked out the APIs incrementally.
We analyzed a number of SDKs in Go and other languages to arrive at the design below. Wherever possible, we tried to align with the very successful mark3labs/mcp-go. However, as you’ll see, we diverged in a number of ways in order to keep the APIs minimal and to be cautious about future spec evolution. We address the differences between this design and mcp-go throughout the document.
Our goal is to make sure that there is a good official SDK for Go. We want your feedback. If discussion reveals that some of the APIs below aren’t right, we’ll change them.
To achieve this, let’s proceed as follows:
Thanks!
-Rob
Changelog
slog.logger
. changesGo SDK Design
This document discusses the design of a Go SDK for the model context protocol. The golang.org/x/tools/internal/mcp package contains a prototype that we built to explore the MCP design space. Many of the ideas there are present in this document. However, we have diverged from and expanded on the APIs of that prototype, and this document should be considered canonical.
Similarities and differences with mark3labs/mcp-go (and others)
The most popular unofficial MCP SDK for Go is mark3labs/mcp-go. As of this writing, it is imported by over 400 packages that span over 200 modules.
We admire mcp-go, and where possible tried to align with its design. However, the APIs here diverge in a number of ways in order to keep the official SDK minimal, allow for future spec evolution, and support additional features. We have noted significant differences from mcp-go in the sections below. Although the API here is not compatible with mcp-go, translating between them should be straightforward in most cases. (Later, we will provide a detailed translation guide.)
Thank you to everyone who contributes to mcp-go and other Go SDKs. We hope that we can collaborate to leverage all that we've learned about MCP and Go in an official SDK.
Requirements
These may be obvious, but it's worthwhile to define goals for an official MCP SDK. An official SDK should aim to be:
Design considerations
In the sections below, we visit each aspect of the MCP spec, in approximately the order they are presented by the official spec For each, we discuss considerations for the Go implementation, and propose a Go API.
Foundations
Package layout
In the sections that follow, it is assumed that most of the MCP API lives in a single shared package, the
mcp
package. This is inconsistent with other MCP SDKs, but is consistent with Go packages likenet/http
,net/rpc
, orgoogle.golang.org/grpc
. We believe that having a single package aids discoverability in package documentation and in the IDE. Furthermore, it avoids arbitrary decisions about package structure that may be rendered inaccurate by future evolution of the spec.Functionality that is not directly related to MCP (like jsonschema or jsonrpc2) belongs in a separate package.
Therefore, this is the core package layout, assuming github.com/modelcontextprotocol/go-sdk as the module path.
github.com/modelcontextprotocol/go-sdk/mcp
: the bulk of the user facing APIgithub.com/modelcontextprotocol/go-sdk/jsonschema
: a jsonschema implementation, with validationgithub.com/modelcontextprotocol/go-sdk/internal/jsonrpc2
: a fork of x/tools/internal/jsonrpc2_v2The JSON-RPC implementation is hidden, to avoid tight coupling. As described in the next section, the only aspects of JSON-RPC that need to be exposed in the SDK are the message types, for the purposes of defining custom transports. We can expose these types by promoting them from the
mcp
package using aliases or wrappers.Difference from mcp-go: Our
mcp
package includes all the functionality of mcp-go'smcp
,client
,server
andtransport
packages.JSON-RPC and Transports
The MCP is defined in terms of client-server communication over bidirectional JSON-RPC message streams. Specifically, version
2025-03-26
of the spec defines two transports:Additionally, version
2024-11-05
of the spec defined a simpler (yet stateful) HTTP transport:text/event-stream
, and sends messages via POST to a session endpoint.Furthermore, the spec states that it must be possible for users to define their own custom transports.
Given the diversity of the transport implementations, they can be challenging to abstract. However, since JSON-RPC requires a bidirectional stream, we can use this to model the MCP transport abstraction:
Methods accept a Go
Context
and return anerror
, as is idiomatic for APIs that do I/O.A
Transport
is something that connects a logical JSON-RPC stream, and nothing more. Streams must be closeable in order to implement client and server shutdown, and therefore conform to theio.Closer
interface.Other SDKs define higher-level transports, with, for example, methods to send a notification or make a call. Those are jsonrpc2 operations on top of the logical stream, and the lower-level interface is easier to implement in most cases, which means it is easier to implement custom transports.
For our prototype, we've used an internal
jsonrpc2
package based on the Go language servergopls
, which we propose to fork for the MCP SDK. It already handles concerns like client/server connection, request lifecycle, cancellation, and shutdown.Differences from mcp-go: The Go team has a battle-tested JSON-RPC implementation that we use for gopls, our Go LSP server. We are using the new version of this library as part of our MCP SDK. It handles all JSON-RPC 2.0 features, including cancellation.
The
Transport
interface here is lower-level than that of mcp-go, but serves a similar purpose. We believe the lower-level interface is easier to implement.stdio transports
In the MCP Spec, the stdio transport uses newline-delimited JSON to communicate over stdin/stdout. It's possible to model both client side and server side of this communication with a shared type that communicates over an
io.ReadWriteCloser
. However, for the purposes of future-proofing, we should use a different types for client and server stdio transport.The
CommandTransport
is the client side of the stdio transport, and connects by starting a command and binding its jsonrpc2 stream to its stdin/stdout.The
StdIOTransport
is the server side of the stdio transport, and connects by binding toos.Stdin
andos.Stdout
.HTTP transports
The HTTP transport APIs are even more asymmetrical. Since connections are initiated via HTTP requests, the client developer will create a transport, but the server developer will typically install an HTTP handler. Internally, the HTTP handler will create a logical transport for each new client connection.
Importantly, since they serve many connections, the HTTP handlers must accept a callback to get an MCP server for each new session. As described below, MCP servers can optionally connect to multiple clients. This allows customization of per-session servers: if the MCP server is stateless, the user can return the same MCP server for each connection. On the other hand, if any per-session customization is required, it is possible by returning a different
Server
instance for each connection.Notably absent are options to hook into low-level request handling for the purposes of authentication or context injection. These concerns are instead handled using standard HTTP middleware patterns. For middleware at the level of the MCP protocol, see Middleware below.
By default, the SSE handler creates messages endpoints with the
?sessionId=...
query parameter. Users that want more control over the management of sessions and session endpoints may write their own handler, and createSSEServerTransport
instances themselves for incoming GET requests.The SSE client transport is simpler, and hopefully self-explanatory.
The Streamable HTTP transports are similar to the SSE transport, albeit with a
more complicated implementation. For brevity, we summarize only the differences
from the equivalent SSE types:
Differences from mcp-go: In mcp-go, server authors create an
MCPServer
, populate it with tools, resources and so on, and then wrap it in anSSEServer
orStdioServer
. Users can manage their own sessions withRegisterSession
andUnregisterSession
. Rather than use a server constructor to get a distinct server for each connection, there is a concept of a "session tool" that overlays tools for a specific session.Here, we tried to differentiate the concept of a
Server
,HTTPHandler
, andTransport
, and provide per-session customization through either thegetServer
constructor or middleware. Additionally, individual handlers and transports here have a minimal API, and do not expose internal details. (Open question: are we oversimplifying?)Other transports
We also provide a couple of transport implementations for special scenarios. An InMemoryTransport can be used when the client and server reside in the same process. A LoggingTransport is a middleware layer that logs RPC logs to a desired location, specified as an io.Writer.
Protocol types
Types needed for the protocol are generated from the JSON schema of the MCP spec.
These types will be included in the
mcp
package, but will be unexported unless they are needed for the user-facing API. Notably, JSON-RPC request types are elided, since they are handled by thejsonrpc2
package and should not be observed by the user.For user-provided data, we use
json.RawMessage
, so that marshalling/unmarshalling can be delegated to the business logic of the client or server.For union types, which can't be represented in Go (specifically
Content
andResourceContents
), we prefer distinguished unions: struct types with fields corresponding to the union of all properties for union elements.For brevity, only a few examples are shown here:
Differences from mcp-go: these types are largely similar, but our type generator flattens types rather than using struct embedding.
Clients and Servers
Generally speaking, the SDK is used by creating a
Client
orServer
instance, adding features to it, and connecting it to a peer.However, the SDK must make a non-obvious choice in these APIs: are clients 1:1 with their logical connections? What about servers? Both clients and servers are stateful: users may add or remove roots from clients, and tools, prompts, and resources from servers. Additionally, handlers for these features may themselves be stateful, for example if a tool handler caches state from earlier requests in the session.
We believe that in the common case, any change to a client or server, such as adding a tool, is intended for all its peers. It is therefore more useful to allow multiple connections from a client, and to a server. This is similar to the
net/http
packages, in which anhttp.Client
andhttp.Server
each may handle multiple unrelated connections. When users add features to a client or server, all connected peers are notified of the change.Supporting multiple connections to servers (and from clients) still allows for stateful components, as it is up to the user to decide whether or not to create distinct servers/clients for each connection. For example, if the user wants to create a distinct server for each new connection, they can do so in the
getServer
factory passed to transport handlers.Following the terminology of the spec, we call the logical connection between a client and server a "session." There must necessarily be a
ClientSession
and aServerSession
, corresponding to the APIs available from the client and server perspective, respectively.Sessions are created from either
Client
orServer
using theConnect
method.Here's an example of these APIs from the client side:
A server that can handle that client call would look like this:
For convenience, we provide
Server.Run
to handle the common case of running a session until the client disconnects:Differences from mcp-go: the Server APIs are similar to mcp-go, though the association between servers and transports is different. In mcp-go, a single server is bound to what we would call an
SSEHTTPHandler
, and reused for all sessions. Per-session behavior is implemented though a 'session tool' overlay. As discussed above, the transport abstraction here is differentiated from HTTP serving, and theServer.Connect
method provides a consistent API for binding to an arbitrary transport. Servers here do not have methods for sending notifications or calls, because they are logically distinct from theServerSession
. In mcp-go, servers aren:1
, but there is no abstraction of a server session: sessions are addressed in Server APIs through theirsessionID
:SendNotificationToAllClients
,SendNotificationToClient
,SendNotificationToSpecificClient
.The client API here is different, since clients and client sessions are conceptually distinct. The
ClientSession
is closer to mcp-go's notion of Client.For both clients and servers, mcp-go uses variadic options to customize behavior, whereas an options struct is used here. We felt that in this case, an options struct would be more readable, and result in simpler package documentation.
Spec Methods
In our SDK, RPC methods that are defined in the specification take a context and a params pointer as arguments, and return a result pointer and error:
Our SDK has a method for every RPC in the spec, and except for
CallTool
, their signatures all share this form. We do this, rather than providing more convenient shortcut signatures, to maintain backward compatibility if the spec makes backward-compatible changes such as adding a new property to the request parameters (as in this commit, for example). To avoid boilerplate, we don't repeat this signature for RPCs defined in the spec; readers may assume it when we mention a "spec method."CallTool
is the only exception: for convenience, it takes the tool name and arguments, with an options struct for additional request fields. See the section on Tools below for details.Why do we use params instead of the full JSON-RPC request? As much as possible, we endeavor to hide JSON-RPC details when they are not relevant to the business logic of your client or server. In this case, the additional information in the JSON-RPC request is just the request ID and method name; the request ID is irrelevant, and the method name is implied by the name of the Go method providing the API.
We believe that any change to the spec that would require callers to pass a new a parameter is not backward compatible. Therefore, it will always work to pass
nil
for anyXXXParams
argument that isn't currently necessary. For example, it is okay to callPing
like so:Iterator Methods
For convenience, iterator methods handle pagination for the
List
spec methods automatically, traversing all pages. If Params are supplied, iteration begins from the provided cursor (if present).Middleware
We provide a mechanism to add MCP-level middleware on the both the client and server side, which runs after the request has been parsed but before any normal handling.
As an example, this code adds server-side logging:
Differences from mcp-go: Version 0.26.0 of mcp-go defines 24 server hooks. Each hook consists of a field in the
Hooks
struct, aHooks.Add
method, and a type for the hook function. These are rarely used. The most common isOnError
, which occurs fewer than ten times in open-source code.Errors
With the exception of tool handler errors, protocol errors are handled transparently as Go errors: errors in server-side feature handlers are propagated as errors from calls from the
ClientSession
, and vice-versa.Protocol errors wrap a
JSONRPCError
type which exposes its underlying error code.As described by the spec, tool execution errors are reported in tool results.
Differences from mcp-go: the
JSONRPCError
type here does not include ID and Method, which can be inferred from the caller. Otherwise, this behavior is similar.Cancellation
Cancellation is implemented transparently using context cancellation. The user can cancel an operation by cancelling the associated context:
When this client call is cancelled, a
"notifications/cancelled"
notification is sent to the server. However, the client call returns immediately withctx.Err()
: it does not wait for the result from the server.The server observes a client cancellation as a cancelled context.
Progress handling
A caller can request progress notifications by setting the
ProgressToken
field on any request.Handlers can notify their peer about progress by calling the
NotifyProgress
method. The notification is only sent if the peer requested it by providing a progress token.Ping / KeepAlive
Both
ClientSession
andServerSession
expose aPing
method to call "ping" on their peer.Additionally, client and server sessions can be configured with automatic keepalive behavior. If the
KeepAlive
option is set to a non-zero duration, it defines an interval for regular "ping" requests. If the peer fails to respond to pings originating from the keepalive check, the session is automatically closed.Differences from mcp-go: in mcp-go the
Ping
method is only provided for client, not server, and the keepalive option is only provided for SSE servers (as a variadic option).Client Features
Roots
Clients support the MCP Roots feature, including roots-changed notifications. Roots can be added and removed from a
Client
withAddRoots
andRemoveRoots
:Server sessions can call the spec method
ListRoots
to get the roots. If a server installs aRootsChangedHandler
, it will be called when the client sends a roots-changed notification, which happens whenever the list of roots changes after a connection has been established.The
Roots
method provides a cached iterator of the root set, invalidated when roots change.Sampling
Clients that support sampling are created with a
CreateMessageHandler
option for handling server calls. To perform sampling, a server session calls the spec methodCreateMessage
.Server Features
Tools
A
Tool
is a logical MCP tool, generated from the MCP spec, and aServerTool
is a tool bound to a tool handler.Add tools to a server with
AddTools
:Remove them by name with
RemoveTools
:A tool's input schema, expressed as a JSON Schema, provides a way to validate the tool's input. One of the challenges in defining tools is the need to associate them with a Go function, yet support the arbitrary complexity of JSON Schema. To achieve this, we have seen two primary approaches:
metoro-io/mcp-golang
)mark3labs/mcp-go
).Both of these have their advantages and disadvantages. Reflection is nice, because it allows you to bind directly to a Go API, and means that the JSON schema of your API is compatible with your Go types by construction. It also means that concerns like parsing and validation can be handled automatically. However, it can become cumbersome to express the full breadth of JSON schema using Go types or struct tags, and sometimes you want to express things that aren’t naturally modeled by Go types, like unions. Explicit schemas are simple and readable, and give the caller full control over their tool definition, but involve significant boilerplate.
We have found that a hybrid model works well, where the initial schema is derived using reflection, but any customization on top of that schema is applied using variadic options. We achieve this using a
NewTool
helper, which generates the schema from the input type, and wraps the handler to provide parsing and validation. The schema (and potentially other features) can be customized using ToolOptions.NewTool
determines the input schema for a Tool from the struct used in the handler. Each struct field that would be marshaled byencoding/json.Marshal
becomes a property of the schema. The property is required unless the field'sjson
tag specifies "omitempty" or "omitzero" (new in Go 1.24). For example, given this struct:"name" and "Choices" are required, while "count" is optional.
As of this writing, the only
ToolOption
isInput
, which allows customizing the input schema of the tool using schema options. These schema options are recursive, in the sense that they may also be applied to properties.For example:
The most recent JSON Schema spec defines over 40 keywords. Providing them all as options would bloat the API despite the fact that most would be very rarely used. For less common keywords, use the
Schema
option to set the schema explicitly:Schemas are validated on the server before the tool handler is called.
Since all the fields of the Tool struct are exported, a Tool can also be created directly with assignment or a struct literal.
Client sessions can call the spec method
ListTools
or an iterator methodTools
to list the available tools.As mentioned above, the client session method
CallTool
has a non-standard signature, so thatCallTool
can handle the marshalling of tool arguments: the type ofCallToolParams.Arguments
isjson.RawMessage
, to delegate unmarshalling to the tool handler.Differences from mcp-go: using variadic options to configure tools was significantly inspired by mcp-go. However, the distinction between
ToolOption
andSchemaOption
allows for recursive application of schema options. For example, that limitation is visible in this code, which must resort to untyped maps to express a nested schema.Additionally, the
NewTool
helper provides a means for building a tool from a Go function using reflection, that automatically handles parsing and validation of inputs.We provide a full JSON Schema implementation for validating tool input schemas against incoming arguments. The
jsonschema.Schema
type provides exported features for all keywords in the JSON Schema draft2020-12 spec. Tool definers can use it to construct any schema they want, so there is no need to provide options for all of them. When combined with schema inference from input structs, we found that we needed only three options to cover the common cases, instead of mcp-go's 23. For example, we will provideEnum
, which occurs 125 times in open source code, but not MinItems, MinLength or MinProperties, which each occur only once (and in an SDK that wraps mcp-go).For registering tools, we provide only
AddTools
; mcp-go'sSetTools
,AddTool
,AddSessionTool
, andAddSessionTools
are deemed unnecessary. (Similarly for Delete/Remove).Prompts
Use
NewPrompt
to create a prompt. As with tools, prompt argument schemas can be inferred from a struct, or obtained from options.Use
AddPrompts
to add prompts to the server, andRemovePrompts
to remove them by name.
Client sessions can call the spec method
ListPrompts
or the iterator methodPrompts
to list the available prompts, and the spec methodGetPrompt
to get one.Differences from mcp-go: We provide a
NewPrompt
helper to bind a prompt handler to a Go function using reflection to derive its arguments. We provideRemovePrompts
to remove prompts from the server.Resources and resource templates
In our design, each resource and resource template is associated with a function that reads it, with this signature:
The arguments include the
ServerSession
so the handler can observe the client's roots. The handler should return the resource contents in aReadResourceResult
, calling eitherNewTextResourceContents
orNewBlobResourceContents
. If the handler omits the URI or MIME type, the server will populate them from the resource.The
ServerResource
andServerResourceTemplate
types hold the association between the resource and its handler:To add a resource or resource template to a server, users call the
AddResources
andAddResourceTemplates
methods with one or moreServerResource
s orServerResourceTemplate
s. We also provide methods to remove them.The
ReadResource
method finds a resource or resource template matching the argument URI and calls its associated handler.To read files from the local filesystem, we recommend using
FileResourceHandler
to construct a handler:Here is an example:
Server sessions also support the spec methods
ListResources
andListResourceTemplates
, and the corresponding iterator methodsResources
andResourceTemplates
.Differences from mcp-go: for symmetry with tools and prompts, we use
AddResources
rather thanAddResource
. Additionally, theResourceHandler
returns aReadResourceResult
, rather than just its content, for compatibility with future evolution of the spec.Subscriptions
ClientSessions can manage change notifications on particular resources:
The server does not implement resource subscriptions. It passes along subscription requests to the user, and supplies a method to notify clients of changes. It tracks which sessions have subscribed to which resources so the user doesn't have to.
If a server author wants to support resource subscriptions, they must provide handlers to be called when clients subscribe and unsubscribe. It is an error to provide only one of these handlers.
User code should call
ResourceUpdated
when a subscribed resource changes.The server routes these notifications to the server sessions that subscribed to the resource.
ListChanged notifications
When a list of tools, prompts or resources changes as the result of an AddXXX or RemoveXXX call, the server informs all its connected clients by sending the corresponding type of notification. A client will receive these notifications if it was created with the corresponding option:
Differences from mcp-go: mcp-go instead provides a general
OnNotification
handler. For type-safety, and to hide JSON RPC details, we provide feature-specific handlers here.Completion
Clients call the spec method
Complete
to request completions. Servers automatically handle these requests based on their collections of prompts and resources.Differences from mcp-go: the client API is similar. mcp-go has not yet defined its server-side behavior.
Logging
MCP specifies a notification for servers to log to clients. Server sessions implement this with the
LoggingMessage
method. It honors the minimum log level established by the client session'sSetLevel
call.As a convenience, we also provide a
slog.Handler
that allows server authors to write logs with thelog/slog
package::Server-to-client logging is configured with
ServerOptions
:A call to a log method like
Info
is translated to aLoggingMessageNotification
as follows:The attributes and the message populate the "data" property with the output of a
slog.JSONHandler
: The result is always a JSON object, with the key "msg" for the message.If the
LoggerName
server option is set, it populates the "logger" property.The standard slog levels
Info
,Debug
,Warn
andError
map to the corresponding levels in the MCP spec. The other spec levels map to integers between the slog levels. For example, "notice" is level 2 because it is between "warning" (slog value 4) and "info" (slog value 0). Themcp
package defines consts for these levels. To log at the "notice" level, a handler would callLog(ctx, mcp.LevelNotice, "message")
.A client that wishes to receive log messages must provide a handler:
Pagination
Servers initiate pagination for
ListTools
,ListPrompts
,ListResources
, andListResourceTemplates
, dictating the page size and providing aNextCursor
field in the Result if more pages exist. The SDK implements keyset pagination, using the unique ID of the feature as the key for a stable sort order and encoding the cursor as an opaque string.For server implementations, the page size for the list operation may be configured via the
ServerOptions.PageSize
field. PageSize must be a non-negative integer. If zero, a sensible default is used.Client requests for List methods include an optional Cursor field for pagination. Server responses for List methods include a
NextCursor
field if more pages exist.In addition to the
List
methods, the SDK provides an iterator method for each list operation. This simplifies pagination for clients by automatically handling the underlying pagination logic. See Iterator Methods above.Differences with mcp-go: the PageSize configuration is set with a configuration field rather than a variadic option. Additionally, this design proposes pagination by default, as this is likely desirable for most servers
Scope
Beta Was this translation helpful? Give feedback.
All reactions