client

package
v1.2.6 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2025 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

func NewClient added in v1.2.0

func NewClient(info *ClientInfo, opts *ClientOptions) *Client

func (*Client) AddRoot added in v1.2.0

func (c *Client) AddRoot(root *protocol.Root)

AddRoot adds a root directory and notifies all sessions

func (*Client) Connect added in v1.2.0

Connect starts an MCP session via the given transport The returned session is initialized and ready to use

Typically, the client is responsible for closing the connection when no longer needed However, if the connection is closed by the server, calls or notifications will return errors wrapping ErrConnectionClosed

func (*Client) ListRoots added in v1.2.0

func (c *Client) ListRoots() []*protocol.Root

ListRoots lists all root directories

func (*Client) RemoveRoot added in v1.2.0

func (c *Client) RemoveRoot(uri string)

RemoveRoot removes a root directory and notifies all sessions

type ClientInfo added in v1.2.0

type ClientInfo struct {
	Name    string
	Version string
}

type ClientOptions added in v1.2.0

type ClientOptions struct {
	// CreateMessageHandler handles sampling/createMessage requests from the server
	//
	// Setting this to a non-nil value causes the client to declare sampling capability
	CreateMessageHandler func(context.Context, *protocol.CreateMessageRequest) (*protocol.CreateMessageResult, error)

	// ElicitationHandler handles elicitation/create requests from the server
	//
	// Setting this to a non-nil value causes the client to declare elicitation capability
	ElicitationHandler func(context.Context, *protocol.ElicitationCreateParams) (*protocol.ElicitationResult, error)

	// Notification handlers from server
	ToolListChangedHandler      func(context.Context, *protocol.ToolsListChangedNotification)
	PromptListChangedHandler    func(context.Context, *protocol.PromptListChangedParams)
	ResourceListChangedHandler  func(context.Context, *protocol.ResourceListChangedParams)
	ResourceUpdatedHandler      func(context.Context, *protocol.ResourceUpdatedNotificationParams)
	LoggingMessageHandler       func(context.Context, *protocol.LoggingMessageParams)
	ProgressNotificationHandler func(context.Context, *protocol.ProgressNotificationParams)

	// TaskStatusHandler handles notifications/tasks/status from the server (MCP 2025-11-25)
	TaskStatusHandler func(context.Context, *protocol.TaskStatusNotificationParams)

	// KeepAlive defines the interval for periodic "ping" requests
	// If the peer fails to respond to a keepalive-initiated ping, the session will automatically close
	KeepAlive time.Duration

	// Tasks capability options (MCP 2025-11-25)
	TasksEnabled bool // Enable tasks support for sampling and elicitation

	// SamplingToolsEnabled enables tool use in sampling requests (MCP 2025-11-25)
	SamplingToolsEnabled bool
}

ClientOptions configures client behavior

type ClientSession added in v1.2.0

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

ClientSession is a logical connection to an MCP server Can be used to send requests or notifications to the server Sessions are created by calling Client.Connect

Call ClientSession.Close to close the connection, or use ClientSession.Wait to wait for server termination

func (*ClientSession) CallTool added in v1.2.0

CallTool invokes a tool on the server

func (*ClientSession) CallToolAsTask added in v1.2.5

func (cs *ClientSession) CallToolAsTask(ctx context.Context, params *protocol.CallToolParams) (*protocol.CreateTaskResult, error)

CallToolAsTask invokes a tool on the server as a task (MCP 2025-11-25) This returns a CreateTaskResult instead of waiting for the tool to complete

func (*ClientSession) CancelTask added in v1.2.5

CancelTask cancels a task on the server (MCP 2025-11-25)

func (*ClientSession) Close added in v1.2.0

func (cs *ClientSession) Close() error

func (*ClientSession) Complete added in v1.2.0

Complete requests auto-completion

func (*ClientSession) GetPrompt added in v1.2.0

GetPrompt retrieves a prompt from the server

func (*ClientSession) GetTask added in v1.2.5

GetTask retrieves a task from the server (MCP 2025-11-25)

func (*ClientSession) GetTaskResult added in v1.2.5

func (cs *ClientSession) GetTaskResult(ctx context.Context, params *protocol.TaskResultParams, result interface{}) error

GetTaskResult retrieves the result of a task from the server (MCP 2025-11-25) Per spec, this returns the original request's result type (e.g., CallToolResult) The caller should unmarshal the result into the appropriate type

func (*ClientSession) ID added in v1.2.0

func (cs *ClientSession) ID() string

func (*ClientSession) InitializeResult added in v1.2.0

func (cs *ClientSession) InitializeResult() *protocol.InitializeResult

InitializeResult returns the initialization result

func (*ClientSession) ListPrompts added in v1.2.0

ListPrompts lists the currently available prompts on the server

func (*ClientSession) ListResourceTemplates added in v1.2.0

ListResourceTemplates lists the resource templates on the server

func (*ClientSession) ListResources added in v1.2.0

ListResources lists the currently available resources on the server

func (*ClientSession) ListTasks added in v1.2.5

ListTasks lists tasks from the server (MCP 2025-11-25)

func (*ClientSession) ListTools added in v1.2.0

ListTools lists the currently available tools on the server

func (*ClientSession) NotifyCancelled added in v1.2.0

func (cs *ClientSession) NotifyCancelled(ctx context.Context, params *protocol.CancelledNotificationParams) error

NotifyCancelled sends a cancellation notification

func (*ClientSession) NotifyProgress added in v1.2.0

func (cs *ClientSession) NotifyProgress(ctx context.Context, params *protocol.ProgressNotificationParams) error

NotifyProgress sends a progress notification

func (*ClientSession) NotifyRootsListChanged added in v1.2.0

func (cs *ClientSession) NotifyRootsListChanged(ctx context.Context) error

NotifyRootsListChanged notifies the server that the roots list has changed

func (*ClientSession) Ping added in v1.2.0

func (cs *ClientSession) Ping(ctx context.Context, params *protocol.PingParams) error

Ping sends a ping request to the server

func (*ClientSession) ReadResource added in v1.2.0

ReadResource reads a resource from the server

func (*ClientSession) SetLoggingLevel added in v1.2.0

func (cs *ClientSession) SetLoggingLevel(ctx context.Context, params *protocol.SetLoggingLevelParams) error

SetLoggingLevel sets the logging level on the server

func (*ClientSession) SubscribeResource added in v1.2.0

func (cs *ClientSession) SubscribeResource(ctx context.Context, params *protocol.SubscribeParams) error

SubscribeResource subscribes to resource updates

func (*ClientSession) UnsubscribeResource added in v1.2.0

func (cs *ClientSession) UnsubscribeResource(ctx context.Context, params *protocol.UnsubscribeParams) error

UnsubscribeResource unsubscribes from resource updates

func (*ClientSession) Wait added in v1.2.0

func (cs *ClientSession) Wait() error

Wait waits for the connection to be closed by the server. Typically, the client should be responsible for closing the connection

type ClientSessionOptions added in v1.2.0

type ClientSessionOptions struct{}

type CommandTransport added in v1.2.0

type CommandTransport struct {
	Command *exec.Cmd
	// TerminateDuration controls how long to wait for the process to exit after closing stdin before sending SIGTERM
	// If zero or negative, defaults to 5 seconds
	TerminateDuration time.Duration
}

CommandTransport is a Transport that runs a command and communicates with it via stdin/stdout using newline-delimited JSON

func NewCommandTransport added in v1.2.0

func NewCommandTransport(command string, args ...string) *CommandTransport

NewCommandTransport creates a new CommandTransport

func (*CommandTransport) Connect added in v1.2.0

Connect starts the command and connects to it via stdin/stdout

Jump to

Keyboard shortcuts

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