capabilities

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 23, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientCapabilities

type ClientCapabilities struct {
	Elicitation *ElicitationCapabilities
	Sampling    *SamplingCapabilities
	Roots       *RootsCapabilities
}

ClientCapabilities represents the capabilities declared by the client.

type ElicitationCapabilities

type ElicitationCapabilities struct{}

ElicitationCapabilities indicates the client supports elicitation.

type LogLevel

type LogLevel string

LogLevel represents logging severity levels.

const (
	LogLevelDebug     LogLevel = "debug"
	LogLevelInfo      LogLevel = "info"
	LogLevelNotice    LogLevel = "notice"
	LogLevelWarning   LogLevel = "warning"
	LogLevelError     LogLevel = "error"
	LogLevelCritical  LogLevel = "critical"
	LogLevelAlert     LogLevel = "alert"
	LogLevelEmergency LogLevel = "emergency"
)

type ProgressOption

type ProgressOption func(*progressConfig)

ProgressOption configures optional fields for progress notifications.

func WithProgressMessage

func WithProgressMessage(message string) ProgressOption

WithProgressMessage adds a descriptive message to the progress notification. The message provides user-facing context about what's being processed.

func WithProgressMeta

func WithProgressMeta(meta map[string]any) ProgressOption

WithProgressMeta adds custom metadata to the progress notification. Use this for application-specific information that extends the MCP protocol.

func WithProgressToken

func WithProgressToken(token any) ProgressOption

WithProgressToken associates the progress notification with a specific request. See RequestContext.GetProgressToken() for details on token semantics.

type Root

type Root struct {
	URI  string // file:// URI identifying the root location
	Name string // Optional human-readable name for display purposes
}

Root represents a filesystem root that defines the boundaries of where servers can operate. The URI must be a file:// URI pointing to an accessible filesystem location.

type RootsCapabilities

type RootsCapabilities struct {
	// ListChanged indicates whether the client supports notifications for changes to the roots list.
	ListChanged bool
}

RootsCapabilities indicates the client supports roots.

type SamplingCapabilities

type SamplingCapabilities struct{}

SamplingCapabilities indicates the client supports LLM sampling.

type Session

type Session struct {
	// contains filtered or unexported fields
}

Session provides access to all MCP session features. It is automatically provided to handlers via the RequestContext parameter. Access it using reqCtx.GetSession() or toolCtx.GetSession().

Example:

func myTool(ctx context.Context, toolCtx mcpio.RequestContext, input Input) (Output, error) {
    session := toolCtx.GetSession()
    if session.SupportsSampling() {
        result, _ := session.CreateMessage(ctx, messages, 1000)
    }
    return output, nil
}

Session wraps mcp.ServerSession and provides ergonomic access to session capabilities.

func NewSession

func NewSession(session serverSession) *Session

NewSession creates a Session from a serverSession interface. In production, pass *mcp.ServerSession. In tests, pass a mock implementing serverSession.

func (*Session) ClientCapabilities

func (s *Session) ClientCapabilities() *ClientCapabilities

ClientCapabilities returns the capabilities the client declared during initialization.

func (*Session) Close

func (s *Session) Close() error

Close closes this session and the underlying connection.

func (*Session) CreateMessage

func (s *Session) CreateMessage(ctx context.Context, messages []*sampling.Message, opts ...sampling.MessageOption) (*sampling.MessageResult, error)

CreateMessage asks the client's LLM to generate a response to the provided messages. This enables servers to use the client's LLM for analysis, suggestions, or processing. Options can be provided to configure the sampling behavior (maxTokens, temperature, model preferences, etc). If maxTokens is not specified via WithMaxTokens, defaults to 1000. Returns nil error and empty result if the client doesn't support sampling.

func (*Session) CreateMessageRaw

func (s *Session) CreateMessageRaw(ctx context.Context, params *mcp.CreateMessageParams) (*mcp.CreateMessageResult, error)

CreateMessageRaw provides direct access to the MCP CreateMessage API with full control over parameters. Use this when you need advanced control beyond what the options provide, or when working with raw MCP types directly.

func (*Session) Elicit

func (s *Session) Elicit(ctx context.Context, message string, requestedSchema any) (*mcp.ElicitResult, error)

Elicit sends an elicitation request to the client asking for user input. Returns an ElicitResult containing the user's action and optionally submitted data.

func (*Session) ListRoots

func (s *Session) ListRoots(ctx context.Context) ([]*Root, error)

ListRoots retrieves the filesystem roots exposed by the client. Roots define the boundaries of where servers can operate within the filesystem, allowing servers to understand which directories and files they have access to.

func (*Session) Log

func (s *Session) Log(ctx context.Context, level LogLevel, message string, data map[string]any) error

Log sends a structured log message to the client. The message will only be sent if it meets the client's minimum log level.

func (*Session) LogAlert

func (s *Session) LogAlert(ctx context.Context, message string, data map[string]any) error

LogAlert sends an alert-level log message to the client.

func (*Session) LogCritical

func (s *Session) LogCritical(ctx context.Context, message string, data map[string]any) error

LogCritical sends a critical-level log message to the client.

func (*Session) LogDebug

func (s *Session) LogDebug(ctx context.Context, message string, data map[string]any) error

LogDebug sends a debug-level log message to the client.

func (*Session) LogEmergency

func (s *Session) LogEmergency(ctx context.Context, message string, data map[string]any) error

LogEmergency sends an emergency-level log message to the client.

func (*Session) LogError

func (s *Session) LogError(ctx context.Context, message string, data map[string]any) error

LogError sends an error-level log message to the client.

func (*Session) LogInfo

func (s *Session) LogInfo(ctx context.Context, message string, data map[string]any) error

LogInfo sends an info-level log message to the client.

func (*Session) LogNotice

func (s *Session) LogNotice(ctx context.Context, message string, data map[string]any) error

LogNotice sends a notice-level log message to the client.

func (*Session) LogWarning

func (s *Session) LogWarning(ctx context.Context, message string, data map[string]any) error

LogWarning sends a warning-level log message to the client.

func (*Session) Logger

func (s *Session) Logger() *slog.Logger

Logger returns a slog.Logger that sends logs to the client. This provides standard Go logging integration with MCP client logging.

func (*Session) NotifyProgress

func (s *Session) NotifyProgress(ctx context.Context, progress, total float64, opts ...ProgressOption) error

NotifyProgress sends a progress update for long-running operations. Progress should be between 0.0 and total, where total represents completion.

Basic usage:

session.NotifyProgress(ctx, 5, 10)

With options:

session.NotifyProgress(ctx, 5, 10,
    WithProgressToken(reqCtx.GetProgressToken()),
    WithProgressMessage("Processing file 5 of 10"))

See README.md Progress Notifications section for complete examples.

func (*Session) SessionID

func (s *Session) SessionID() string

SessionID returns the unique identifier for this session.

func (*Session) SupportsElicitation

func (s *Session) SupportsElicitation() bool

SupportsElicitation returns true if the client supports elicitation (user input requests).

func (*Session) SupportsRoots

func (s *Session) SupportsRoots() bool

SupportsRoots returns true if the client supports filesystem roots.

func (*Session) SupportsSampling

func (s *Session) SupportsSampling() bool

SupportsSampling returns true if the client supports LLM sampling (CreateMessage).

func (*Session) Wait

func (s *Session) Wait() error

Wait blocks until the client disconnects or the session is closed.

Directories

Path Synopsis
Package sampling provides options for configuring LLM sampling requests.
Package sampling provides options for configuring LLM sampling requests.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL