mcp: Deprecate roots, sampling and logging (SEP-2577) (#1017)

Fixes #1013
This commit is contained in:
Guglielmo Colombo 2026-06-23 11:11:08 +02:00 • committed by GitHub
commit b6649db4f9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
22 changed files with 320 additions and 25 deletions

View file

@ -44,6 +44,13 @@ The following table shows which versions of the Go SDK support which versions of
\*\* Partial support for 2025-11-25 (client side OAuth and Sampling with tools not available). \*\* Partial support for 2025-11-25 (client side OAuth and Sampling with tools not available).
The roots, sampling, and logging features are deprecated as of protocol version
2026-07-28 by
[SEP-2577](https://modelcontextprotocol.io/seps/2577-deprecate-roots-sampling-and-logging).
The SDK continues to support them for compatibility during the deprecation
window (at least twelve months). See the individual feature documentation for
migration guidance.
New releases of the SDK target only supported versions of Go. See New releases of the SDK target only supported versions of Go. See
https://go.dev/doc/devel/release#policy for more information. https://go.dev/doc/devel/release#policy for more information.

View file

@ -5,6 +5,8 @@
// The conformance server implements features required for MCP conformance testing. // The conformance server implements features required for MCP conformance testing.
// It mirrors the functionality of the TypeScript conformance server at // It mirrors the functionality of the TypeScript conformance server at
// https://github.com/modelcontextprotocol/conformance/blob/main/examples/servers/typescript/everything-server.ts // https://github.com/modelcontextprotocol/conformance/blob/main/examples/servers/typescript/everything-server.ts
//
//lint:file-ignore SA1019 conformance server exercises deprecated SEP-2577 APIs (roots, sampling, logging).
package main package main
import ( import (

View file

@ -10,6 +10,13 @@
## Roots ## Roots
> **Note:** The roots feature is deprecated as of protocol version 2026-07-28
> ([SEP-2577](https://modelcontextprotocol.io/seps/2577-deprecate-roots-sampling-and-logging)).
> It remains fully functional during the deprecation window (at least twelve
> months). The SDK continues to support roots for compatibility. New code
> should pass paths via tool parameters, resource URIs, or configuration
> instead.
MCP allows clients to specify a set of filesystem MCP allows clients to specify a set of filesystem
["roots"](https://modelcontextprotocol.io/specification/2025-06-18/client/roots). ["roots"](https://modelcontextprotocol.io/specification/2025-06-18/client/roots).
The SDK supports this as follows: The SDK supports this as follows:
@ -77,6 +84,13 @@ func Example_roots() {
## Sampling ## Sampling
> **Note:** The sampling feature is deprecated as of protocol version
> 2026-07-28
> ([SEP-2577](https://modelcontextprotocol.io/seps/2577-deprecate-roots-sampling-and-logging)).
> It remains fully functional during the deprecation window (at least twelve
> months). The SDK continues to support sampling for compatibility. Servers
> that need LLM completions should call LLM provider APIs directly.
[Sampling](https://modelcontextprotocol.io/specification/2025-06-18/client/sampling) [Sampling](https://modelcontextprotocol.io/specification/2025-06-18/client/sampling)
is a way for servers to leverage the client's AI capabilities. It is is a way for servers to leverage the client's AI capabilities. It is
implemented in the SDK as follows: implemented in the SDK as follows:

View file

@ -474,6 +474,13 @@ _ = mcp.NewServer(&mcp.Implementation{Name: "server"}, &mcp.ServerOptions{
### Logging ### Logging
> **Note:** The logging feature is deprecated as of protocol version
> 2026-07-28
> ([SEP-2577](https://modelcontextprotocol.io/seps/2577-deprecate-roots-sampling-and-logging)).
> It remains fully functional during the deprecation window (at least twelve
> months). The SDK continues to support logging for compatibility. Servers
> should migrate to stderr logging (for STDIO transports) or OpenTelemetry.
MCP servers can send logging messages to MCP clients. MCP servers can send logging messages to MCP clients.
(This form of logging is distinct from server-side logging, where the (This form of logging is distinct from server-side logging, where the
server produces logs that remain server-side, for use by server maintainers.) server produces logs that remain server-side, for use by server maintainers.)

View file

@ -16,6 +16,8 @@
// Example: // Example:
// //
// ./distributed -http=localhost:8080 -child_ports=8081,8082 // ./distributed -http=localhost:8080 -child_ports=8081,8082
//
//lint:file-ignore SA1019 example server exercises deprecated SEP-2577 logging API for demonstration.
package main package main
import ( import (

View file

@ -3,6 +3,8 @@
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
// The everything server implements all supported features of an MCP server. // The everything server implements all supported features of an MCP server.
//
//lint:file-ignore SA1019 example server exercises deprecated SEP-2577 APIs (roots, sampling, logging) for demonstration.
package main package main
import ( import (

View file

@ -4,6 +4,13 @@
## Roots ## Roots
> **Note:** The roots feature is deprecated as of protocol version 2026-07-28
> ([SEP-2577](https://modelcontextprotocol.io/seps/2577-deprecate-roots-sampling-and-logging)).
> It remains fully functional during the deprecation window (at least twelve
> months). The SDK continues to support roots for compatibility. New code
> should pass paths via tool parameters, resource URIs, or configuration
> instead.
MCP allows clients to specify a set of filesystem MCP allows clients to specify a set of filesystem
["roots"](https://modelcontextprotocol.io/specification/2025-06-18/client/roots). ["roots"](https://modelcontextprotocol.io/specification/2025-06-18/client/roots).
The SDK supports this as follows: The SDK supports this as follows:
@ -26,6 +33,13 @@ method. To receive notifications about root changes, set
## Sampling ## Sampling
> **Note:** The sampling feature is deprecated as of protocol version
> 2026-07-28
> ([SEP-2577](https://modelcontextprotocol.io/seps/2577-deprecate-roots-sampling-and-logging)).
> It remains fully functional during the deprecation window (at least twelve
> months). The SDK continues to support sampling for compatibility. Servers
> that need LLM completions should call LLM provider APIs directly.
[Sampling](https://modelcontextprotocol.io/specification/2025-06-18/client/sampling) [Sampling](https://modelcontextprotocol.io/specification/2025-06-18/client/sampling)
is a way for servers to leverage the client's AI capabilities. It is is a way for servers to leverage the client's AI capabilities. It is
implemented in the SDK as follows: implemented in the SDK as follows:

View file

@ -236,6 +236,13 @@ requests.
### Logging ### Logging
> **Note:** The logging feature is deprecated as of protocol version
> 2026-07-28
> ([SEP-2577](https://modelcontextprotocol.io/seps/2577-deprecate-roots-sampling-and-logging)).
> It remains fully functional during the deprecation window (at least twelve
> months). The SDK continues to support logging for compatibility. Servers
> should migrate to stderr logging (for STDIO transports) or OpenTelemetry.
MCP servers can send logging messages to MCP clients. MCP servers can send logging messages to MCP clients.
(This form of logging is distinct from server-side logging, where the (This form of logging is distinct from server-side logging, where the
server produces logs that remain server-side, for use by server maintainers.) server produces logs that remain server-side, for use by server maintainers.)

View file

@ -43,6 +43,13 @@ The following table shows which versions of the Go SDK support which versions of
\*\* Partial support for 2025-11-25 (client side OAuth and Sampling with tools not available). \*\* Partial support for 2025-11-25 (client side OAuth and Sampling with tools not available).
The roots, sampling, and logging features are deprecated as of protocol version
2026-07-28 by
[SEP-2577](https://modelcontextprotocol.io/seps/2577-deprecate-roots-sampling-and-logging).
The SDK continues to support them for compatibility during the deprecation
window (at least twelve months). See the individual feature documentation for
migration guidance.
New releases of the SDK target only supported versions of Go. See New releases of the SDK target only supported versions of Go. See
https://go.dev/doc/devel/release#policy for more information. https://go.dev/doc/devel/release#policy for more information.

View file

@ -2,6 +2,8 @@
// Use of this source code is governed by an MIT-style // Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
//lint:file-ignore SA1019 tests exercise deprecated SEP-2577 APIs (roots, sampling, logging).
package mcp package mcp
import ( import (

View file

@ -82,6 +82,12 @@ type ClientOptions struct {
// &SamplingCapabilities{}. If [ClientOptions.Capabilities] is set and has a // &SamplingCapabilities{}. If [ClientOptions.Capabilities] is set and has a
// non nil value for [ClientCapabilities.Sampling], that value overrides the // non nil value for [ClientCapabilities.Sampling], that value overrides the
// inferred capability. // inferred capability.
//
// Deprecated: the sampling feature is deprecated as of protocol version
// 2026-07-28 (SEP-2577). It remains functional during the deprecation
// window (at least twelve months). Migrate to calling LLM provider APIs
// directly from your server. See
// https://modelcontextprotocol.io/seps/2577-deprecate-roots-sampling-and-logging.
CreateMessageHandler func(context.Context, *CreateMessageRequest) (*CreateMessageResult, error) CreateMessageHandler func(context.Context, *CreateMessageRequest) (*CreateMessageResult, error)
// CreateMessageWithToolsHandler handles incoming sampling/createMessage // CreateMessageWithToolsHandler handles incoming sampling/createMessage
// requests that may involve tool use. It returns // requests that may involve tool use. It returns
@ -95,6 +101,12 @@ type ClientOptions struct {
// //
// It is a panic to set both CreateMessageHandler and // It is a panic to set both CreateMessageHandler and
// CreateMessageWithToolsHandler. // CreateMessageWithToolsHandler.
//
// Deprecated: the sampling feature is deprecated as of protocol version
// 2026-07-28 (SEP-2577). It remains functional during the deprecation
// window (at least twelve months). Migrate to calling LLM provider APIs
// directly from your server. See
// https://modelcontextprotocol.io/seps/2577-deprecate-roots-sampling-and-logging.
CreateMessageWithToolsHandler func(context.Context, *CreateMessageWithToolsRequest) (*CreateMessageWithToolsResult, error) CreateMessageWithToolsHandler func(context.Context, *CreateMessageWithToolsRequest) (*CreateMessageWithToolsResult, error)
// ElicitationHandler handles incoming requests for elicitation/create. // ElicitationHandler handles incoming requests for elicitation/create.
// //
@ -152,10 +164,17 @@ type ClientOptions struct {
// ElicitationCompleteHandler handles incoming notifications for notifications/elicitation/complete. // ElicitationCompleteHandler handles incoming notifications for notifications/elicitation/complete.
ElicitationCompleteHandler func(context.Context, *ElicitationCompleteNotificationRequest) ElicitationCompleteHandler func(context.Context, *ElicitationCompleteNotificationRequest)
// Handlers for notifications from the server. // Handlers for notifications from the server.
ToolListChangedHandler func(context.Context, *ToolListChangedRequest) ToolListChangedHandler func(context.Context, *ToolListChangedRequest)
PromptListChangedHandler func(context.Context, *PromptListChangedRequest) PromptListChangedHandler func(context.Context, *PromptListChangedRequest)
ResourceListChangedHandler func(context.Context, *ResourceListChangedRequest) ResourceListChangedHandler func(context.Context, *ResourceListChangedRequest)
ResourceUpdatedHandler func(context.Context, *ResourceUpdatedNotificationRequest) ResourceUpdatedHandler func(context.Context, *ResourceUpdatedNotificationRequest)
// LoggingMessageHandler handles incoming notifications/message
// notifications from the server.
//
// Deprecated: the logging feature is deprecated as of protocol version
// 2026-07-28 (SEP-2577). It remains functional during the deprecation
// window (at least twelve months). See
// https://modelcontextprotocol.io/seps/2577-deprecate-roots-sampling-and-logging.
LoggingMessageHandler func(context.Context, *LoggingMessageRequest) LoggingMessageHandler func(context.Context, *LoggingMessageRequest)
ProgressNotificationHandler func(context.Context, *ProgressNotificationClientRequest) ProgressNotificationHandler func(context.Context, *ProgressNotificationClientRequest)
// MultiRoundTrip configures the automatic MultiRoundTrip (Multi Round-Trip Requests) middleware. // MultiRoundTrip configures the automatic MultiRoundTrip (Multi Round-Trip Requests) middleware.
@ -615,6 +634,12 @@ func (cs *ClientSession) startKeepalive(interval time.Duration) {
// AddRoots adds the given roots to the client, // AddRoots adds the given roots to the client,
// replacing any with the same URIs, // replacing any with the same URIs,
// and notifies any connected servers. // and notifies any connected servers.
//
// Deprecated: the roots feature is deprecated as of protocol version
// 2026-07-28 (SEP-2577). It remains functional during the deprecation window
// (at least twelve months). Migrate to passing paths via tool parameters,
// resource URIs, or configuration. See
// https://modelcontextprotocol.io/seps/2577-deprecate-roots-sampling-and-logging.
func (c *Client) AddRoots(roots ...*Root) { func (c *Client) AddRoots(roots ...*Root) {
// Only notify if something could change. // Only notify if something could change.
if len(roots) == 0 { if len(roots) == 0 {
@ -627,6 +652,12 @@ func (c *Client) AddRoots(roots ...*Root) {
// RemoveRoots removes the roots with the given URIs, // RemoveRoots removes the roots with the given URIs,
// and notifies any connected servers if the list has changed. // and notifies any connected servers if the list has changed.
// It is not an error to remove a nonexistent root. // It is not an error to remove a nonexistent root.
//
// Deprecated: the roots feature is deprecated as of protocol version
// 2026-07-28 (SEP-2577). It remains functional during the deprecation window
// (at least twelve months). Migrate to passing paths via tool parameters,
// resource URIs, or configuration. See
// https://modelcontextprotocol.io/seps/2577-deprecate-roots-sampling-and-logging.
func (c *Client) RemoveRoots(uris ...string) { func (c *Client) RemoveRoots(uris ...string) {
changeAndNotify(c, notificationRootsListChanged, &RootsListChangedParams{}, changeAndNotify(c, notificationRootsListChanged, &RootsListChangedParams{},
func() bool { return c.roots.remove(uris...) }) func() bool { return c.roots.remove(uris...) })
@ -1242,6 +1273,14 @@ func (cs *ClientSession) CallTool(ctx context.Context, params *CallToolParams) (
return handleSend[*CallToolResult](ctx, methodCallTool, newClientRequest(cs, orZero[Params](params))) return handleSend[*CallToolResult](ctx, methodCallTool, newClientRequest(cs, orZero[Params](params)))
} }
// SetLoggingLevel sets the minimum severity level for log messages sent by
// the server.
//
// Deprecated: the logging feature is deprecated as of protocol version
// 2026-07-28 (SEP-2577). It remains functional during the deprecation window
// (at least twelve months). Migrate to consuming stderr output (for STDIO
// servers) or OpenTelemetry. See
// https://modelcontextprotocol.io/seps/2577-deprecate-roots-sampling-and-logging.
func (cs *ClientSession) SetLoggingLevel(ctx context.Context, params *SetLoggingLevelParams) error { func (cs *ClientSession) SetLoggingLevel(ctx context.Context, params *SetLoggingLevelParams) error {
_, err := handleSend[*emptyResult](ctx, methodSetLevel, newClientRequest(cs, orZero[Params](params))) _, err := handleSend[*emptyResult](ctx, methodSetLevel, newClientRequest(cs, orZero[Params](params)))
return err return err

View file

@ -2,6 +2,8 @@
// Use of this source code is governed by an MIT-style // Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
//lint:file-ignore SA1019 examples exercise deprecated SEP-2577 APIs (roots, sampling) for demonstration.
package mcp_test package mcp_test
import ( import (

View file

@ -2,6 +2,8 @@
// Use of this source code is governed by an MIT-style // Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
//lint:file-ignore SA1019 tests exercise deprecated SEP-2577 APIs (roots, sampling, logging).
package mcp package mcp
import ( import (

View file

@ -189,6 +189,11 @@ func (c *EmbeddedResource) fromWire(wire *wireContent) {
// ToolUseContent represents a request from the assistant to invoke a tool. // ToolUseContent represents a request from the assistant to invoke a tool.
// This content type is only valid in sampling messages. // This content type is only valid in sampling messages.
//
// Deprecated: the sampling feature is deprecated as of protocol version
// 2026-07-28 (SEP-2577). It remains functional during the deprecation window
// (at least twelve months). See
// https://modelcontextprotocol.io/seps/2577-deprecate-roots-sampling-and-logging.
type ToolUseContent struct { type ToolUseContent struct {
// ID is a unique identifier for this tool use, used to match with ToolResultContent. // ID is a unique identifier for this tool use, used to match with ToolResultContent.
ID string ID string
@ -229,6 +234,11 @@ func (c *ToolUseContent) fromWire(wire *wireContent) {
// ToolResultContent represents the result of a tool invocation. // ToolResultContent represents the result of a tool invocation.
// This content type is only valid in sampling messages with role "user". // This content type is only valid in sampling messages with role "user".
//
// Deprecated: the sampling feature is deprecated as of protocol version
// 2026-07-28 (SEP-2577). It remains functional during the deprecation window
// (at least twelve months). See
// https://modelcontextprotocol.io/seps/2577-deprecate-roots-sampling-and-logging.
type ToolResultContent struct { type ToolResultContent struct {
// ToolUseID references the ID from the corresponding ToolUseContent. // ToolUseID references the ID from the corresponding ToolUseContent.
ToolUseID string ToolUseID string

View file

@ -69,6 +69,11 @@ func compareLevels(l1, l2 LoggingLevel) int {
} }
// LoggingHandlerOptions are options for a LoggingHandler. // LoggingHandlerOptions are options for a LoggingHandler.
//
// Deprecated: the logging feature is deprecated as of protocol version
// 2026-07-28 (SEP-2577). It remains functional during the deprecation window
// (at least twelve months). See
// https://modelcontextprotocol.io/seps/2577-deprecate-roots-sampling-and-logging.
type LoggingHandlerOptions struct { type LoggingHandlerOptions struct {
// The value for the "logger" field of logging notifications. // The value for the "logger" field of logging notifications.
LoggerName string LoggerName string
@ -79,6 +84,11 @@ type LoggingHandlerOptions struct {
} }
// A LoggingHandler is a [slog.Handler] for MCP. // A LoggingHandler is a [slog.Handler] for MCP.
//
// Deprecated: the logging feature is deprecated as of protocol version
// 2026-07-28 (SEP-2577). It remains functional during the deprecation window
// (at least twelve months). See
// https://modelcontextprotocol.io/seps/2577-deprecate-roots-sampling-and-logging.
type LoggingHandler struct { type LoggingHandler struct {
opts LoggingHandlerOptions opts LoggingHandlerOptions
ss *ServerSession ss *ServerSession
@ -101,6 +111,11 @@ func ensureLogger(l *slog.Logger) *slog.Logger {
// NewLoggingHandler creates a [LoggingHandler] that logs to the given [ServerSession] using a // NewLoggingHandler creates a [LoggingHandler] that logs to the given [ServerSession] using a
// [slog.JSONHandler]. // [slog.JSONHandler].
//
// Deprecated: the logging feature is deprecated as of protocol version
// 2026-07-28 (SEP-2577). It remains functional during the deprecation window
// (at least twelve months). See
// https://modelcontextprotocol.io/seps/2577-deprecate-roots-sampling-and-logging.
func NewLoggingHandler(ss *ServerSession, opts *LoggingHandlerOptions) *LoggingHandler { func NewLoggingHandler(ss *ServerSession, opts *LoggingHandlerOptions) *LoggingHandler {
var buf bytes.Buffer var buf bytes.Buffer
jsonHandler := slog.NewJSONHandler(&buf, &slog.HandlerOptions{ jsonHandler := slog.NewJSONHandler(&buf, &slog.HandlerOptions{

View file

@ -2,6 +2,8 @@
// Use of this source code is governed by an MIT-style // Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
//lint:file-ignore SA1019 tests exercise deprecated SEP-2577 APIs (roots, sampling, logging).
package mcp package mcp
import ( import (

View file

@ -2,6 +2,8 @@
// Use of this source code is governed by the license // Use of this source code is governed by the license
// that can be found in the LICENSE file. // that can be found in the LICENSE file.
//lint:file-ignore SA1019 tests exercise deprecated SEP-2577 APIs (roots, sampling, logging).
package mcp package mcp
import ( import (

View file

@ -439,6 +439,11 @@ func (x *CancelledParams) GetProgressToken() any { return getProgressToken(x) }
func (x *CancelledParams) SetProgressToken(t any) { setProgressToken(x, t) } func (x *CancelledParams) SetProgressToken(t any) { setProgressToken(x, t) }
// RootCapabilities describes a client's support for roots. // RootCapabilities describes a client's support for roots.
//
// Deprecated: the roots feature is deprecated as of protocol version
// 2026-07-28 (SEP-2577). It remains functional during the deprecation window
// (at least twelve months). See
// https://modelcontextprotocol.io/seps/2577-deprecate-roots-sampling-and-logging.
type RootCapabilities struct { type RootCapabilities struct {
// ListChanged reports whether the client supports notifications for // ListChanged reports whether the client supports notifications for
// changes to the roots list. // changes to the roots list.
@ -466,14 +471,27 @@ type ClientCapabilities struct {
// Deprecated: use RootsV2. As described in #607, Roots should have been a // Deprecated: use RootsV2. As described in #607, Roots should have been a
// pointer to a RootCapabilities value. Roots will be continue to be // pointer to a RootCapabilities value. Roots will be continue to be
// populated, but any new fields will only be added in the RootsV2 field. // populated, but any new fields will only be added in the RootsV2 field.
//
// The roots feature itself is also deprecated by SEP-2577; see RootsV2.
Roots struct { Roots struct {
// ListChanged reports whether the client supports notifications for // ListChanged reports whether the client supports notifications for
// changes to the roots list. // changes to the roots list.
ListChanged bool `json:"listChanged,omitempty"` ListChanged bool `json:"listChanged,omitempty"`
} `json:"roots,omitempty"` } `json:"roots,omitempty"`
// RootsV2 is present if the client supports roots. When capabilities are explicitly configured via [ClientOptions.Capabilities] // RootsV2 is present if the client supports roots. When capabilities are
// explicitly configured via [ClientOptions.Capabilities].
//
// Deprecated: the roots feature is deprecated as of protocol version
// 2026-07-28 (SEP-2577). It remains functional during the deprecation
// window (at least twelve months). See
// https://modelcontextprotocol.io/seps/2577-deprecate-roots-sampling-and-logging.
RootsV2 *RootCapabilities `json:"-"` RootsV2 *RootCapabilities `json:"-"`
// Sampling is present if the client supports sampling from an LLM. // Sampling is present if the client supports sampling from an LLM.
//
// Deprecated: the sampling feature is deprecated as of protocol version
// 2026-07-28 (SEP-2577). It remains functional during the deprecation
// window (at least twelve months). See
// https://modelcontextprotocol.io/seps/2577-deprecate-roots-sampling-and-logging.
Sampling *SamplingCapabilities `json:"sampling,omitempty"` Sampling *SamplingCapabilities `json:"sampling,omitempty"`
// Elicitation is present if the client supports elicitation from the server. // Elicitation is present if the client supports elicitation from the server.
Elicitation *ElicitationCapabilities `json:"elicitation,omitempty"` Elicitation *ElicitationCapabilities `json:"elicitation,omitempty"`
@ -641,6 +659,12 @@ type CompleteResult struct {
func (*CompleteResult) isResult() {} func (*CompleteResult) isResult() {}
// CreateMessageParams holds parameters for a sampling/createMessage request.
//
// Deprecated: the sampling feature is deprecated as of protocol version
// 2026-07-28 (SEP-2577). It remains functional during the deprecation window
// (at least twelve months). See
// https://modelcontextprotocol.io/seps/2577-deprecate-roots-sampling-and-logging.
type CreateMessageParams struct { type CreateMessageParams struct {
// This property is reserved by the protocol to allow clients and servers to // This property is reserved by the protocol to allow clients and servers to
// attach additional metadata to their responses. // attach additional metadata to their responses.
@ -648,10 +672,11 @@ type CreateMessageParams struct {
// A request to include context from one or more MCP servers (including the // A request to include context from one or more MCP servers (including the
// caller), to be attached to the prompt. The client may ignore this request. // caller), to be attached to the prompt. The client may ignore this request.
// //
// The default is "none". Values "thisServer" and // The default is "none". The values "thisServer" and "allServers" are
// "allServers" are soft-deprecated. Servers SHOULD only use these values if // deprecated as of protocol version 2025-11-25 (SEP-2596) and will be
// the client declares ClientCapabilities.sampling.context. These values may // removed no later than the sampling feature itself (SEP-2577). Servers
// be removed in future spec releases. // SHOULD omit this field or use "none". See
// https://modelcontextprotocol.io/seps/2596-feature-lifecycle-and-deprecation-policy.
IncludeContext string `json:"includeContext,omitempty"` IncludeContext string `json:"includeContext,omitempty"`
// The maximum number of tokens to sample, as requested by the server. The // The maximum number of tokens to sample, as requested by the server. The
// client may choose to sample fewer tokens than requested. // client may choose to sample fewer tokens than requested.
@ -681,6 +706,11 @@ func (x *CreateMessageParams) SetProgressToken(t any) { setProgressToken(x, t) }
// and messages that support array content (for parallel tool calls). // and messages that support array content (for parallel tool calls).
// //
// Use with [ServerSession.CreateMessageWithTools]. // Use with [ServerSession.CreateMessageWithTools].
//
// Deprecated: the sampling feature is deprecated as of protocol version
// 2026-07-28 (SEP-2577). It remains functional during the deprecation window
// (at least twelve months). See
// https://modelcontextprotocol.io/seps/2577-deprecate-roots-sampling-and-logging.
type CreateMessageWithToolsParams struct { type CreateMessageWithToolsParams struct {
Meta `json:"_meta,omitempty"` Meta `json:"_meta,omitempty"`
IncludeContext string `json:"includeContext,omitempty"` IncludeContext string `json:"includeContext,omitempty"`
@ -741,6 +771,11 @@ func (p *CreateMessageWithToolsParams) toBase() (*CreateMessageParams, error) {
// object for compatibility with pre-2025-11-25 implementations. When // object for compatibility with pre-2025-11-25 implementations. When
// unmarshaling, a single JSON content object is accepted and wrapped in a // unmarshaling, a single JSON content object is accepted and wrapped in a
// one-element slice. // one-element slice.
//
// Deprecated: the sampling feature is deprecated as of protocol version
// 2026-07-28 (SEP-2577). It remains functional during the deprecation window
// (at least twelve months). See
// https://modelcontextprotocol.io/seps/2577-deprecate-roots-sampling-and-logging.
type SamplingMessageV2 struct { type SamplingMessageV2 struct {
Content []Content `json:"content"` Content []Content `json:"content"`
Role Role `json:"role"` Role Role `json:"role"`
@ -782,6 +817,11 @@ func (m *SamplingMessageV2) UnmarshalJSON(data []byte) error {
// The client should inform the user before returning the sampled message, to // The client should inform the user before returning the sampled message, to
// allow them to inspect the response (human in the loop) and decide whether to // allow them to inspect the response (human in the loop) and decide whether to
// allow the server to see it. // allow the server to see it.
//
// Deprecated: the sampling feature is deprecated as of protocol version
// 2026-07-28 (SEP-2577). It remains functional during the deprecation window
// (at least twelve months). See
// https://modelcontextprotocol.io/seps/2577-deprecate-roots-sampling-and-logging.
type CreateMessageResult struct { type CreateMessageResult struct {
// This property is reserved by the protocol to allow clients and servers to // This property is reserved by the protocol to allow clients and servers to
// attach additional metadata to their responses. // attach additional metadata to their responses.
@ -828,6 +868,11 @@ func (r *CreateMessageResult) UnmarshalJSON(data []byte) error {
// //
// When unmarshaling, a single JSON content object is accepted and wrapped in a // When unmarshaling, a single JSON content object is accepted and wrapped in a
// one-element slice, for compatibility with clients that return a single block. // one-element slice, for compatibility with clients that return a single block.
//
// Deprecated: the sampling feature is deprecated as of protocol version
// 2026-07-28 (SEP-2577). It remains functional during the deprecation window
// (at least twelve months). See
// https://modelcontextprotocol.io/seps/2577-deprecate-roots-sampling-and-logging.
type CreateMessageWithToolsResult struct { type CreateMessageWithToolsResult struct {
Meta `json:"_meta,omitempty"` Meta `json:"_meta,omitempty"`
Content []Content `json:"content"` Content []Content `json:"content"`
@ -1218,6 +1263,12 @@ type ListResourcesResult struct {
func (x *ListResourcesResult) isResult() {} func (x *ListResourcesResult) isResult() {}
func (x *ListResourcesResult) nextCursorPtr() *string { return &x.NextCursor } func (x *ListResourcesResult) nextCursorPtr() *string { return &x.NextCursor }
// ListRootsParams holds parameters for a roots/list request.
//
// Deprecated: the roots feature is deprecated as of protocol version
// 2026-07-28 (SEP-2577). It remains functional during the deprecation window
// (at least twelve months). See
// https://modelcontextprotocol.io/seps/2577-deprecate-roots-sampling-and-logging.
type ListRootsParams struct { type ListRootsParams struct {
// This property is reserved by the protocol to allow clients and servers to // This property is reserved by the protocol to allow clients and servers to
// attach additional metadata to their responses. // attach additional metadata to their responses.
@ -1233,6 +1284,11 @@ func (x *ListRootsParams) SetProgressToken(t any) { setProgressToken(x, t) }
// The client's response to a roots/list request from the server. This result // The client's response to a roots/list request from the server. This result
// contains an array of Root objects, each representing a root directory or file // contains an array of Root objects, each representing a root directory or file
// that the server can operate on. // that the server can operate on.
//
// Deprecated: the roots feature is deprecated as of protocol version
// 2026-07-28 (SEP-2577). It remains functional during the deprecation window
// (at least twelve months). See
// https://modelcontextprotocol.io/seps/2577-deprecate-roots-sampling-and-logging.
type ListRootsResult struct { type ListRootsResult struct {
// This property is reserved by the protocol to allow clients and servers to // This property is reserved by the protocol to allow clients and servers to
// attach additional metadata to their responses. // attach additional metadata to their responses.
@ -1277,8 +1333,20 @@ func (x *ListToolsResult) nextCursorPtr() *string { return &x.NextCursor }
// //
// These map to syslog message severities, as specified in RFC-5424: // These map to syslog message severities, as specified in RFC-5424:
// https://datatracker.ietf.org/doc/html/rfc5424#section-6.2.1 // https://datatracker.ietf.org/doc/html/rfc5424#section-6.2.1
//
// Deprecated: the logging feature is deprecated as of protocol version
// 2026-07-28 (SEP-2577). It remains functional during the deprecation window
// (at least twelve months). See
// https://modelcontextprotocol.io/seps/2577-deprecate-roots-sampling-and-logging.
type LoggingLevel string type LoggingLevel string
// LoggingMessageParams holds the parameters for a notifications/message
// notification.
//
// Deprecated: the logging feature is deprecated as of protocol version
// 2026-07-28 (SEP-2577). It remains functional during the deprecation window
// (at least twelve months). See
// https://modelcontextprotocol.io/seps/2577-deprecate-roots-sampling-and-logging.
type LoggingMessageParams struct { type LoggingMessageParams struct {
// This property is reserved by the protocol to allow clients and servers to // This property is reserved by the protocol to allow clients and servers to
// attach additional metadata to their responses. // attach additional metadata to their responses.
@ -1301,6 +1369,11 @@ func (x *LoggingMessageParams) SetProgressToken(t any) { setProgressToken(x, t)
// //
// Keys not declared here are currently left unspecified by the spec and are up // Keys not declared here are currently left unspecified by the spec and are up
// to the client to interpret. // to the client to interpret.
//
// Deprecated: the sampling feature is deprecated as of protocol version
// 2026-07-28 (SEP-2577). It remains functional during the deprecation window
// (at least twelve months). See
// https://modelcontextprotocol.io/seps/2577-deprecate-roots-sampling-and-logging.
type ModelHint struct { type ModelHint struct {
// A hint for a model name. // A hint for a model name.
// //
@ -1327,6 +1400,11 @@ type ModelHint struct {
// These preferences are always advisory. The client may ignore them. It is also // These preferences are always advisory. The client may ignore them. It is also
// up to the client to decide how to interpret these preferences and how to // up to the client to decide how to interpret these preferences and how to
// balance them against other considerations. // balance them against other considerations.
//
// Deprecated: the sampling feature is deprecated as of protocol version
// 2026-07-28 (SEP-2577). It remains functional during the deprecation window
// (at least twelve months). See
// https://modelcontextprotocol.io/seps/2577-deprecate-roots-sampling-and-logging.
type ModelPreferences struct { type ModelPreferences struct {
// How much to prioritize cost when selecting a model. A value of 0 means cost // How much to prioritize cost when selecting a model. A value of 0 means cost
// is not important, while a value of 1 means cost is the most important factor. // is not important, while a value of 1 means cost is the most important factor.
@ -1652,6 +1730,11 @@ type ResourceTemplate struct {
type Role string type Role string
// Represents a root directory or file that the server can operate on. // Represents a root directory or file that the server can operate on.
//
// Deprecated: the roots feature is deprecated as of protocol version
// 2026-07-28 (SEP-2577). It remains functional during the deprecation window
// (at least twelve months). See
// https://modelcontextprotocol.io/seps/2577-deprecate-roots-sampling-and-logging.
type Root struct { type Root struct {
// See [specification/2025-06-18/basic/index#general-fields] for notes on _meta // See [specification/2025-06-18/basic/index#general-fields] for notes on _meta
// usage. // usage.
@ -1666,6 +1749,13 @@ type Root struct {
URI string `json:"uri"` URI string `json:"uri"`
} }
// RootsListChangedParams holds parameters for a notifications/roots/list_changed
// notification.
//
// Deprecated: the roots feature is deprecated as of protocol version
// 2026-07-28 (SEP-2577). It remains functional during the deprecation window
// (at least twelve months). See
// https://modelcontextprotocol.io/seps/2577-deprecate-roots-sampling-and-logging.
type RootsListChangedParams struct { type RootsListChangedParams struct {
// This property is reserved by the protocol to allow clients and servers to // This property is reserved by the protocol to allow clients and servers to
// attach additional metadata to their responses. // attach additional metadata to their responses.
@ -1681,6 +1771,11 @@ func (x *RootsListChangedParams) SetProgressToken(t any) { setProgressToken(x, t
// below directly above ClientCapabilities. // below directly above ClientCapabilities.
// SamplingCapabilities describes the client's support for sampling. // SamplingCapabilities describes the client's support for sampling.
//
// Deprecated: the sampling feature is deprecated as of protocol version
// 2026-07-28 (SEP-2577). It remains functional during the deprecation window
// (at least twelve months). See
// https://modelcontextprotocol.io/seps/2577-deprecate-roots-sampling-and-logging.
type SamplingCapabilities struct { type SamplingCapabilities struct {
// Context indicates the client supports includeContext values other than "none". // Context indicates the client supports includeContext values other than "none".
Context *SamplingContextCapabilities `json:"context,omitempty"` Context *SamplingContextCapabilities `json:"context,omitempty"`
@ -1689,12 +1784,27 @@ type SamplingCapabilities struct {
} }
// SamplingContextCapabilities indicates the client supports context inclusion. // SamplingContextCapabilities indicates the client supports context inclusion.
//
// Deprecated: the sampling feature is deprecated as of protocol version
// 2026-07-28 (SEP-2577). It remains functional during the deprecation window
// (at least twelve months). See
// https://modelcontextprotocol.io/seps/2577-deprecate-roots-sampling-and-logging.
type SamplingContextCapabilities struct{} type SamplingContextCapabilities struct{}
// SamplingToolsCapabilities indicates the client supports tool use in sampling. // SamplingToolsCapabilities indicates the client supports tool use in sampling.
//
// Deprecated: the sampling feature is deprecated as of protocol version
// 2026-07-28 (SEP-2577). It remains functional during the deprecation window
// (at least twelve months). See
// https://modelcontextprotocol.io/seps/2577-deprecate-roots-sampling-and-logging.
type SamplingToolsCapabilities struct{} type SamplingToolsCapabilities struct{}
// ToolChoice controls how the model uses tools during sampling. // ToolChoice controls how the model uses tools during sampling.
//
// Deprecated: the sampling feature is deprecated as of protocol version
// 2026-07-28 (SEP-2577). It remains functional during the deprecation window
// (at least twelve months). See
// https://modelcontextprotocol.io/seps/2577-deprecate-roots-sampling-and-logging.
type ToolChoice struct { type ToolChoice struct {
// Mode controls tool invocation behavior: // Mode controls tool invocation behavior:
// - "auto": Model decides whether to use tools (default) // - "auto": Model decides whether to use tools (default)
@ -1721,6 +1831,11 @@ type URLElicitationCapabilities struct{}
// //
// For assistant messages, Content may be text, image, audio, or tool_use. // For assistant messages, Content may be text, image, audio, or tool_use.
// For user messages, Content may be text, image, audio, or tool_result. // For user messages, Content may be text, image, audio, or tool_result.
//
// Deprecated: the sampling feature is deprecated as of protocol version
// 2026-07-28 (SEP-2577). It remains functional during the deprecation window
// (at least twelve months). See
// https://modelcontextprotocol.io/seps/2577-deprecate-roots-sampling-and-logging.
type SamplingMessage struct { type SamplingMessage struct {
Content Content `json:"content"` Content Content `json:"content"`
Role Role `json:"role"` Role Role `json:"role"`
@ -1746,6 +1861,12 @@ func (m *SamplingMessage) UnmarshalJSON(data []byte) error {
return nil return nil
} }
// SetLoggingLevelParams holds parameters for a logging/setLevel request.
//
// Deprecated: the logging feature is deprecated as of protocol version
// 2026-07-28 (SEP-2577). It remains functional during the deprecation window
// (at least twelve months). See
// https://modelcontextprotocol.io/seps/2577-deprecate-roots-sampling-and-logging.
type SetLoggingLevelParams struct { type SetLoggingLevelParams struct {
// This property is reserved by the protocol to allow clients and servers to // This property is reserved by the protocol to allow clients and servers to
// attach additional metadata to their responses. // attach additional metadata to their responses.
@ -2071,6 +2192,11 @@ type Implementation struct {
type CompletionCapabilities struct{} type CompletionCapabilities struct{}
// LoggingCapabilities describes the server's support for sending log messages to the client. // LoggingCapabilities describes the server's support for sending log messages to the client.
//
// Deprecated: the logging feature is deprecated as of protocol version
// 2026-07-28 (SEP-2577). It remains functional during the deprecation window
// (at least twelve months). See
// https://modelcontextprotocol.io/seps/2577-deprecate-roots-sampling-and-logging.
type LoggingCapabilities struct{} type LoggingCapabilities struct{}
// PromptCapabilities describes the server's support for prompts. // PromptCapabilities describes the server's support for prompts.
@ -2114,6 +2240,11 @@ type ServerCapabilities struct {
// suggestions. // suggestions.
Completions *CompletionCapabilities `json:"completions,omitempty"` Completions *CompletionCapabilities `json:"completions,omitempty"`
// Logging is present if the server supports log messages. // Logging is present if the server supports log messages.
//
// Deprecated: the logging feature is deprecated as of protocol version
// 2026-07-28 (SEP-2577). It remains functional during the deprecation
// window (at least twelve months). See
// https://modelcontextprotocol.io/seps/2577-deprecate-roots-sampling-and-logging.
Logging *LoggingCapabilities `json:"logging,omitempty"` Logging *LoggingCapabilities `json:"logging,omitempty"`
// Prompts is present if the server supports prompts. // Prompts is present if the server supports prompts.
Prompts *PromptCapabilities `json:"prompts,omitempty"` Prompts *PromptCapabilities `json:"prompts,omitempty"`
@ -2196,6 +2327,11 @@ const (
// MetaKeyClientCapabilities carries the client's [ClientCapabilities]. // MetaKeyClientCapabilities carries the client's [ClientCapabilities].
MetaKeyClientCapabilities = "io.modelcontextprotocol/clientCapabilities" MetaKeyClientCapabilities = "io.modelcontextprotocol/clientCapabilities"
// MetaKeyLogLevel identifies the desired log level for the request. // MetaKeyLogLevel identifies the desired log level for the request.
//
// Deprecated: the logging feature is deprecated as of protocol version
// 2026-07-28 (SEP-2577). It remains functional during the deprecation
// window (at least twelve months). See
// https://modelcontextprotocol.io/seps/2577-deprecate-roots-sampling-and-logging.
MetaKeyLogLevel = "io.modelcontextprotocol/logLevel" MetaKeyLogLevel = "io.modelcontextprotocol/logLevel"
// MetaKeySubscriptionID identifies the subscriptions/listen request that an // MetaKeySubscriptionID identifies the subscriptions/listen request that an
// out-of-band notification belongs to. // out-of-band notification belongs to.

View file

@ -2,6 +2,8 @@
// Use of this source code is governed by an MIT-style // Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
//lint:file-ignore SA1019 tests exercise deprecated SEP-2577 sampling APIs.
package mcp package mcp
// TODO: move other sampling-related tests to this file. // TODO: move other sampling-related tests to this file.

View file

@ -73,6 +73,12 @@ type ServerOptions struct {
// If zero, defaults to [DefaultPageSize]. // If zero, defaults to [DefaultPageSize].
PageSize int PageSize int
// If non-nil, called when "notifications/roots/list_changed" is received. // If non-nil, called when "notifications/roots/list_changed" is received.
//
// Deprecated: the roots feature is deprecated as of protocol version
// 2026-07-28 (SEP-2577). It remains functional during the deprecation
// window (at least twelve months). Migrate to passing paths via tool
// parameters, resource URIs, or configuration. See
// https://modelcontextprotocol.io/seps/2577-deprecate-roots-sampling-and-logging.
RootsListChangedHandler func(context.Context, *RootsListChangedRequest) RootsListChangedHandler func(context.Context, *RootsListChangedRequest)
// If non-nil, called when "notifications/progress" is received. // If non-nil, called when "notifications/progress" is received.
ProgressNotificationHandler func(context.Context, *ProgressNotificationServerRequest) ProgressNotificationHandler func(context.Context, *ProgressNotificationServerRequest)
@ -1474,6 +1480,12 @@ func (ss *ServerSession) Ping(ctx context.Context, params *PingParams) error {
} }
// ListRoots lists the client roots. // ListRoots lists the client roots.
//
// Deprecated: the roots feature is deprecated as of protocol version
// 2026-07-28 (SEP-2577). It remains functional during the deprecation window
// (at least twelve months). Migrate to passing paths via tool parameters,
// resource URIs, or configuration. See
// https://modelcontextprotocol.io/seps/2577-deprecate-roots-sampling-and-logging.
func (ss *ServerSession) ListRoots(ctx context.Context, params *ListRootsParams) (*ListRootsResult, error) { func (ss *ServerSession) ListRoots(ctx context.Context, params *ListRootsParams) (*ListRootsResult, error) {
if err := ss.checkInitialized(methodListRoots); err != nil { if err := ss.checkInitialized(methodListRoots); err != nil {
return nil, err return nil, err
@ -1486,6 +1498,12 @@ func (ss *ServerSession) ListRoots(ctx context.Context, params *ListRootsParams)
// If the client returns multiple content blocks (e.g. parallel tool calls), // If the client returns multiple content blocks (e.g. parallel tool calls),
// CreateMessage returns an error. Use [ServerSession.CreateMessageWithTools] // CreateMessage returns an error. Use [ServerSession.CreateMessageWithTools]
// for tool-enabled sampling. // for tool-enabled sampling.
//
// Deprecated: the sampling feature is deprecated as of protocol version
// 2026-07-28 (SEP-2577). It remains functional during the deprecation window
// (at least twelve months). Migrate to calling LLM provider APIs directly
// from your server. See
// https://modelcontextprotocol.io/seps/2577-deprecate-roots-sampling-and-logging.
func (ss *ServerSession) CreateMessage(ctx context.Context, params *CreateMessageParams) (*CreateMessageResult, error) { func (ss *ServerSession) CreateMessage(ctx context.Context, params *CreateMessageParams) (*CreateMessageResult, error) {
if err := ss.checkInitialized(methodCreateMessage); err != nil { if err := ss.checkInitialized(methodCreateMessage); err != nil {
return nil, err return nil, err
@ -1523,6 +1541,12 @@ func (ss *ServerSession) CreateMessage(ctx context.Context, params *CreateMessag
// returning a [CreateMessageWithToolsResult] that supports array content // returning a [CreateMessageWithToolsResult] that supports array content
// (for parallel tool calls). Use this instead of [ServerSession.CreateMessage] // (for parallel tool calls). Use this instead of [ServerSession.CreateMessage]
// when the request includes tools. // when the request includes tools.
//
// Deprecated: the sampling feature is deprecated as of protocol version
// 2026-07-28 (SEP-2577). It remains functional during the deprecation window
// (at least twelve months). Migrate to calling LLM provider APIs directly
// from your server. See
// https://modelcontextprotocol.io/seps/2577-deprecate-roots-sampling-and-logging.
func (ss *ServerSession) CreateMessageWithTools(ctx context.Context, params *CreateMessageWithToolsParams) (*CreateMessageWithToolsResult, error) { func (ss *ServerSession) CreateMessageWithTools(ctx context.Context, params *CreateMessageWithToolsParams) (*CreateMessageWithToolsResult, error) {
if err := ss.checkInitialized(methodCreateMessage); err != nil { if err := ss.checkInitialized(methodCreateMessage); err != nil {
return nil, err return nil, err
@ -1609,28 +1633,21 @@ func (ss *ServerSession) Elicit(ctx context.Context, params *ElicitParams) (*Eli
return res, nil return res, nil
} }
// logLevelContextKey carries the per-request log level from
// [ServerSession.handle] to [ServerSession.Log] for new-protocol
// (>= 2026-07-28) requests. The level is scoped to a single in-flight request
// — including handler goroutines that call [ServerSession.Log] concurrently —
// rather than to the session, which avoids races between concurrent requests
// and aligns with SEP-2575's per-request opt-in model. The value type is
// [LoggingLevel]; an empty string means the request opted out of log messages.
type logLevelContextKey struct{}
// Log sends a log message to the client. // Log sends a log message to the client.
// //
// For new-protocol (>= 2026-07-28) requests, the level is taken from the // For new-protocol (>= 2026-07-28) requests, the level is taken from the
// originating request's `_meta` field (SEP-2575); an absent or empty value // originating request's `_meta` field (SEP-2575); an absent or empty value
// suppresses the message per spec. For old-protocol requests, the level is // suppresses the message per spec. For old-protocol requests, the level is
// taken from the session state set via `logging/setLevel`. // taken from the session state set via `logging/setLevel`.
//
// Deprecated: the logging feature is deprecated as of protocol version
// 2026-07-28 (SEP-2577). It remains functional during the deprecation window
// (at least twelve months). See
// https://modelcontextprotocol.io/seps/2577-deprecate-roots-sampling-and-logging.
func (ss *ServerSession) Log(ctx context.Context, params *LoggingMessageParams) error { func (ss *ServerSession) Log(ctx context.Context, params *LoggingMessageParams) error {
logLevel, ok := ctx.Value(logLevelContextKey{}).(LoggingLevel) ss.mu.Lock()
if !ok { logLevel := ss.state.LogLevel
ss.mu.Lock() ss.mu.Unlock()
logLevel = ss.state.LogLevel
ss.mu.Unlock()
}
if logLevel == "" { if logLevel == "" {
// The spec is unclear, but seems to imply that no log messages are sent until the client // The spec is unclear, but seems to imply that no log messages are sent until the client
// sets the level. // sets the level.
@ -1806,7 +1823,7 @@ func (ss *ServerSession) handle(ctx context.Context, req *jsonrpc.Request) (any,
ctx = context.WithValue(ctx, idContextKey{}, req.ID) ctx = context.WithValue(ctx, idContextKey{}, req.ID)
// For new-protocol requests, propagate the per-request log level. // For new-protocol requests, propagate the per-request log level.
if validatedMeta.usesNewProtocol { if validatedMeta.usesNewProtocol {
ctx = context.WithValue(ctx, logLevelContextKey{}, validatedMeta.logLevel) ss.setLevel(ctx, &SetLoggingLevelParams{Level: validatedMeta.logLevel})
} }
return handleReceive(ctx, ss, req) return handleReceive(ctx, ss, req)
} }

Some files were not shown because too many files have changed in this diff Show more