Documentation
¶
Index ¶
- type ClientCapabilities
- type ElicitationCapabilities
- type LogLevel
- type ProgressOption
- type Root
- type RootsCapabilities
- type SamplingCapabilities
- type Session
- func (s *Session) ClientCapabilities() *ClientCapabilities
- func (s *Session) Close() error
- func (s *Session) CreateMessage(ctx context.Context, messages []*sampling.Message, ...) (*sampling.MessageResult, error)
- func (s *Session) CreateMessageRaw(ctx context.Context, params *mcp.CreateMessageParams) (*mcp.CreateMessageResult, error)
- func (s *Session) Elicit(ctx context.Context, message string, requestedSchema any) (*mcp.ElicitResult, error)
- func (s *Session) ListRoots(ctx context.Context) ([]*Root, error)
- func (s *Session) Log(ctx context.Context, level LogLevel, message string, data map[string]any) error
- func (s *Session) LogAlert(ctx context.Context, message string, data map[string]any) error
- func (s *Session) LogCritical(ctx context.Context, message string, data map[string]any) error
- func (s *Session) LogDebug(ctx context.Context, message string, data map[string]any) error
- func (s *Session) LogEmergency(ctx context.Context, message string, data map[string]any) error
- func (s *Session) LogError(ctx context.Context, message string, data map[string]any) error
- func (s *Session) LogInfo(ctx context.Context, message string, data map[string]any) error
- func (s *Session) LogNotice(ctx context.Context, message string, data map[string]any) error
- func (s *Session) LogWarning(ctx context.Context, message string, data map[string]any) error
- func (s *Session) Logger() *slog.Logger
- func (s *Session) NotifyProgress(ctx context.Context, progress, total float64, opts ...ProgressOption) error
- func (s *Session) SessionID() string
- func (s *Session) SupportsElicitation() bool
- func (s *Session) SupportsRoots() bool
- func (s *Session) SupportsSampling() bool
- func (s *Session) Wait() error
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 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) 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 ¶
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) LogCritical ¶
LogCritical sends a critical-level log message to the client.
func (*Session) LogEmergency ¶
LogEmergency sends an emergency-level log message to the client.
func (*Session) LogWarning ¶
LogWarning sends a warning-level log message to the client.
func (*Session) 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) SupportsElicitation ¶
SupportsElicitation returns true if the client supports elicitation (user input requests).
func (*Session) SupportsRoots ¶
SupportsRoots returns true if the client supports filesystem roots.
func (*Session) SupportsSampling ¶
SupportsSampling returns true if the client supports LLM sampling (CreateMessage).