mcp

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2026 License: MIT Imports: 11 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 MCP 客户端管理器

func NewClient

func NewClient() *Client

NewClient 创建 MCP 客户端

func (*Client) CallTool

func (c *Client) CallTool(ctx context.Context, serverName, toolName string, args json.RawMessage) (string, error)

CallTool 调用 MCP 工具

func (*Client) Close

func (c *Client) Close()

Close 关闭所有连接

func (*Client) Connect

func (c *Client) Connect(ctx context.Context, cfg ServerConfig) error

Connect 连接单个 MCP 服务器

func (*Client) ConnectAll

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

ConnectAll 连接所有配置的服务器

func (*Client) LoadConfigs

func (c *Client) LoadConfigs(configs []ServerConfig)

LoadConfigs 从配置加载 MCP 服务器列表

func (*Client) RegisterToRegistry

func (c *Client) RegisterToRegistry(registry *tool.Registry)

RegisterToRegistry 将 MCP 工具注册到 Xin Code 工具注册表

func (*Client) ToolCount

func (c *Client) ToolCount() int

ToolCount 返回已发现的 MCP 工具数量

type MCPTool

type MCPTool struct {
	ServerName  string         `json:"server_name"`
	Name        string         `json:"name"`
	Description string         `json:"description"`
	InputSchema map[string]any `json:"input_schema"`
}

MCPTool MCP 发现的工具

type ServerConfig

type ServerConfig struct {
	Name    string            `json:"name"`
	Command string            `json:"command"`
	Args    []string          `json:"args,omitempty"`
	Env     map[string]string `json:"env,omitempty"`
}

ServerConfig MCP 服务器配置

type StdioTransport

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

StdioTransport 通过子进程 stdin/stdout 的 MCP 传输

func NewStdioTransport

func NewStdioTransport(command string, args []string, env map[string]string) *StdioTransport

NewStdioTransport 创建 stdio 传输

func (*StdioTransport) Close

func (t *StdioTransport) Close()

Close 关闭连接

func (*StdioTransport) SendNotification

func (t *StdioTransport) SendNotification(method string, params any) error

SendNotification 发送 JSON-RPC 通知(不需要响应)

func (*StdioTransport) SendRequest

func (t *StdioTransport) SendRequest(ctx context.Context, method string, params any) (any, error)

SendRequest 发送 JSON-RPC 请求并等待响应

func (*StdioTransport) Start

func (t *StdioTransport) Start(ctx context.Context) error

Start 启动子进程

Jump to

Keyboard shortcuts

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