client

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package client implements interfaces.MCPClient. Application code configures MCP using github.com/agenticenv/agent-sdk-go/pkg/mcp.MCPStdio or github.com/agenticenv/agent-sdk-go/pkg/mcp.MCPStreamableHTTP (see github.com/agenticenv/agent-sdk-go/pkg/agent.WithMCPConfig); this package performs the wire-up.

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
}

Client implements interfaces.MCPClient using a long-lived *sdkmcp.Client and a short-lived *sdkmcp.ClientSession per operation (Connect → RPC → Close), so no session is stored on this struct.

func NewClient

func NewClient(name string, transportCfg types.MCPTransportConfig, opts ...Option) (*Client, error)

NewClient returns a Client with name used for interfaces.MCPClient.Name. transportCfg is the same value you set on github.com/agenticenv/agent-sdk-go/pkg/agent.MCPConfig.Transport (e.g. github.com/agenticenv/agent-sdk-go/pkg/mcp.MCPStdio, github.com/agenticenv/agent-sdk-go/pkg/mcp.MCPStreamableHTTP). opts are optional [Option]s (e.g. WithLogger, WithLogLevel, WithToolFilter); see BuildConfig for defaults.

func (*Client) CallTool

func (c *Client) CallTool(ctx context.Context, tool string, input json.RawMessage) (json.RawMessage, error)

CallTool implements interfaces.MCPClient via tools/call.

func (*Client) Close

func (c *Client) Close() error

Close implements interfaces.MCPClient: clears the MCP client so further RPCs fail; there is no persistent session to tear down.

func (*Client) ListTools

func (c *Client) ListTools(ctx context.Context) ([]interfaces.ToolSpec, error)

ListTools implements interfaces.MCPClient via tools/list (paginated).

func (*Client) Name

func (c *Client) Name() string

Name implements interfaces.MCPClient.

func (*Client) Ping

func (c *Client) Ping(ctx context.Context) error

Ping implements interfaces.MCPClient: connect (full MCP handshake), protocol ping, then close the session.

type ClientConfig

type ClientConfig struct {
	Logger        logger.Logger
	LogLevel      string
	Timeout       time.Duration // per Ping/ListTools/CallTool: deadline for connect+RPC in one attempt
	RetryAttempts int           // max attempts per operation (connect+fn); default matches [types.DefaultMCPRetryAttempts]
	ToolFilter    mcp.MCPToolFilter
}

ClientConfig holds optional settings for NewClient. Logger and LogLevel mirror pkg/llm.LLMConfig; Timeout, RetryAttempts, and ToolFilter align with github.com/agenticenv/agent-sdk-go/pkg/agent.MCPConfig (same field semantics as github.com/agenticenv/agent-sdk-go/pkg/agent.MCPConfig.ToolFilter / mcp.MCPToolFilter).

func BuildConfig

func BuildConfig(opts ...Option) (*ClientConfig, error)

BuildConfig builds ClientConfig from options. Defaults when not set:

  • LogLevel: "error"
  • Logger: stderr slog logger at LogLevel

It returns an error if [ClientConfig.ToolFilter] fails mcp.MCPToolFilter.Validate.

type Option

type Option func(*ClientConfig)

Option mutates ClientConfig when passed to BuildConfig or NewClient.

func WithLogLevel

func WithLogLevel(level string) Option

WithLogLevel sets the level used when WithLogger is not set (same strings as logger.DefaultLogger: debug, info, warn, error). Empty defaults to "error" in BuildConfig.

func WithLogger

func WithLogger(l logger.Logger) Option

WithLogger sets diagnostics for this MCP client and, when l is *logger.SlogLogger, forwards the underlying *log/slog.Logger to the go-sdk MCP client for protocol-level logs.

func WithRetryAttempts

func WithRetryAttempts(n int) Option

WithRetryAttempts sets how many times Client may repeat connect+RPC after a failure (minimum 1 after BuildConfig). Zero means use types.DefaultMCPRetryAttempts in BuildConfig.

func WithTimeout

func WithTimeout(d time.Duration) Option

WithTimeout sets the per-operation deadline for each attempt (connect plus one RPC chain, e.g. full ListTools pagination). Zero means use types.DefaultMCPTimeout in BuildConfig.

func WithToolFilter

func WithToolFilter(f mcp.MCPToolFilter) Option

WithToolFilter sets allow/block lists (same semantics as github.com/agenticenv/agent-sdk-go/pkg/agent.MCPConfig.ToolFilter). BuildConfig validates the filter; Client.ListTools runs mcp.MCPToolFilter.Apply to restrict returned specs.

Jump to

Keyboard shortcuts

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