Help us shape the future of Go! Take the 2026 Go Developer Survey

mcpclient

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: AGPL-3.0 Imports: 16 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
}

Client 持有 SDK 返回的连接对象。Close 会释放传输连接, 使用 stdio 时也会关闭子进程。

func Connect

func Connect(ctx context.Context, config Config) (*Client, error)

Connect 与外部 server 建立连接并协商协议版本。ctx 只限制此过程; 后续请求使用各自传入的 context。

func (*Client) CallTool

func (c *Client) CallTool(ctx context.Context, name string, args map[string]any) (*mcp.CallToolResult, error)

CallTool 保留完整 MCP 结果,包括结构化内容和 IsError。 工具自身失败仍是调用结果,不当作传输错误。

func (*Client) Close

func (c *Client) Close() error

Close 结束 MCP 会话,并在使用 stdio 时停止子进程。

func (*Client) ListTools

func (c *Client) ListTools(ctx context.Context) ([]*mcp.Tool, error)

ListTools 读取所有 tools/list 分页,并保留 server 返回的 schema。

type Config

type Config struct {
	clientcfg.TransportSettings
	Env        map[string]string
	HTTPClient *http.Client
}

Config 提供单个连接的运行时参数。调用方可通过 HTTPClient 注入认证能力; 持久化配置和凭据管理不属于本包。

type ConnectionInput added in v1.7.0

type ConnectionInput struct {
	clientcfg.ConnectionSettings
	// nil 保留现有凭据;非 nil 整体替换,空对象显式清除凭据。
	Credentials *clientcfg.Secrets `json:"credentials"`
}

type ConnectionStatus added in v1.7.0

type ConnectionStatus struct {
	Connected bool   `json:"connected"`
	ToolCount int    `json:"tool_count"`
	LastError string `json:"last_error"`
}

type ConnectionView added in v1.7.0

type ConnectionView struct {
	Config         clientcfg.Connection `json:"config"`
	EnvKeys        []string             `json:"env_keys"`
	HasBearerToken bool                 `json:"has_bearer_token"`
	Status         ConnectionStatus     `json:"status"`
}

type Manager added in v1.7.0

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

Manager 按 server 隔离连接与请求。配置替换立即取消旧连接的请求,旧刷新结果不会回填新目录。

func NewManager added in v1.7.0

func NewManager() *Manager

func (*Manager) CallTool added in v1.7.0

func (m *Manager) CallTool(ctx context.Context, id, name string, args map[string]any) (*mcp.CallToolResult, error)

CallTool 在发送前重新核对当前配置与许可;新发现的工具默认不可调用。

func (*Manager) Close added in v1.7.0

func (m *Manager) Close(ctx context.Context) error

func (*Manager) Configure added in v1.7.0

func (m *Manager) Configure(config clientcfg.Connection, secret clientcfg.Secrets)

Configure 接收后端私有快照,不接受前端直接传入的运行时连接对象。

func (*Manager) Refresh added in v1.7.0

func (m *Manager) Refresh(ctx context.Context, id string) ([]*mcp.Tool, error)

Refresh 也用于手动连接测试:允许用户测试已保存但尚未启用的配置。 测试不会修改启用状态或逐工具许可。

func (*Manager) Remove added in v1.7.0

func (m *Manager) Remove(id string)

func (*Manager) SetAccess added in v1.7.0

func (m *Manager) SetAccess(config clientcfg.Connection)

SetAccess 保留管理员已发现的工具列表,但撤销旧连接及其在途请求。

func (*Manager) Status added in v1.7.0

func (m *Manager) Status(id string) ConnectionStatus

func (*Manager) Tools added in v1.7.0

func (m *Manager) Tools(id string) []*mcp.Tool

type Repository added in v1.7.0

type Repository interface {
	Load() (clientcfg.State, error)
	Save(clientcfg.State) error
}

type Service added in v1.7.0

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

Service 编排持久授权和运行时连接;磁盘更新失败不会发布新外部配置。 网络请求在 client Manager 中执行,不占用配置锁或数据库事务。

func NewService added in v1.7.0

func NewService(store Repository, client *Manager) (*Service, error)

New 加载失败时仍返回停用的 Service,供应用展示错误并统一关闭;异常配置不会被覆盖。

func (*Service) Close added in v1.7.0

func (s *Service) Close(ctx context.Context) error

func (*Service) DeleteConnection added in v1.7.0

func (s *Service) DeleteConnection(id string) error

func (*Service) ListConnections added in v1.7.0

func (s *Service) ListConnections() []ConnectionView

func (*Service) Refresh added in v1.7.0

func (s *Service) Refresh(ctx context.Context, id string) ([]ToolView, error)

func (*Service) SaveConnection added in v1.7.0

func (s *Service) SaveConnection(input ConnectionInput) (ConnectionView, error)

func (*Service) SetConnectionEnabled added in v1.7.0

func (s *Service) SetConnectionEnabled(id string, enabled bool) error

func (*Service) SetToolAllowed added in v1.7.0

func (s *Service) SetToolAllowed(id, tool string, allowed bool) error

func (*Service) Tools added in v1.7.0

func (s *Service) Tools(id string) ([]ToolView, error)

type ToolView added in v1.7.0

type ToolView struct {
	Name        string `json:"name"`
	Description string `json:"description"`
	Allowed     bool   `json:"allowed"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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