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

mcpclient

package
v1.6.1 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: AGPL-3.0 Imports: 9 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 {
	Transport  Transport
	Command    string
	Args       []string
	Env        map[string]string
	Endpoint   string
	HTTPClient *http.Client
}

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

type Transport

type Transport string

Transport 表示外部 MCP server 的连接方式。

const (
	TransportStdio          Transport = "stdio"
	TransportStreamableHTTP Transport = "streamable_http"
)

Jump to

Keyboard shortcuts

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