mcp: Deprecate roots, sampling and logging (SEP-2577) (#1017)
Fixes #1013
This commit is contained in:
parent
cd7d80c591
commit
b6649db4f9
1 changed files with 320 additions and 25 deletions
|
|
@ -73,6 +73,12 @@ type ServerOptions struct {
|
|||
// If zero, defaults to [DefaultPageSize].
|
||||
PageSize int
|
||||
// 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)
|
||||
// If non-nil, called when "notifications/progress" is received.
|
||||
ProgressNotificationHandler func(context.Context, *ProgressNotificationServerRequest)
|
||||
|
|
@ -1474,6 +1480,12 @@ func (ss *ServerSession) Ping(ctx context.Context, params *PingParams) error {
|
|||
}
|
||||
|
||||
// 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) {
|
||||
if err := ss.checkInitialized(methodListRoots); err != nil {
|
||||
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),
|
||||
// CreateMessage returns an error. Use [ServerSession.CreateMessageWithTools]
|
||||
// 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) {
|
||||
if err := ss.checkInitialized(methodCreateMessage); err != nil {
|
||||
return nil, err
|
||||
|
|
@ -1523,6 +1541,12 @@ func (ss *ServerSession) CreateMessage(ctx context.Context, params *CreateMessag
|
|||
// returning a [CreateMessageWithToolsResult] that supports array content
|
||||
// (for parallel tool calls). Use this instead of [ServerSession.CreateMessage]
|
||||
// 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) {
|
||||
if err := ss.checkInitialized(methodCreateMessage); err != nil {
|
||||
return nil, err
|
||||
|
|
@ -1609,28 +1633,21 @@ func (ss *ServerSession) Elicit(ctx context.Context, params *ElicitParams) (*Eli
|
|||
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.
|
||||
//
|
||||
// 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
|
||||
// suppresses the message per spec. For old-protocol requests, the level is
|
||||
// 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 {
|
||||
logLevel, ok := ctx.Value(logLevelContextKey{}).(LoggingLevel)
|
||||
if !ok {
|
||||
ss.mu.Lock()
|
||||
logLevel = ss.state.LogLevel
|
||||
ss.mu.Unlock()
|
||||
}
|
||||
ss.mu.Lock()
|
||||
logLevel := ss.state.LogLevel
|
||||
ss.mu.Unlock()
|
||||
if logLevel == "" {
|
||||
// The spec is unclear, but seems to imply that no log messages are sent until the client
|
||||
// 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)
|
||||
// For new-protocol requests, propagate the per-request log level.
|
||||
if validatedMeta.usesNewProtocol {
|
||||
ctx = context.WithValue(ctx, logLevelContextKey{}, validatedMeta.logLevel)
|
||||
ss.setLevel(ctx, &SetLoggingLevelParams{Level: validatedMeta.logLevel})
|
||||
}
|
||||
return handleReceive(ctx, ss, req)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue