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 ¶
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 ¶
Close implements interfaces.MCPClient: clears the MCP client so further RPCs fail; there is no persistent session to tear down.
func (*Client) ListTools ¶
ListTools implements interfaces.MCPClient via tools/list (paginated).
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 ¶
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 ¶
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 ¶
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 ¶
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.