Documentation
¶
Index ¶
- type ConnectionType
- type MCPHost
- func (h *MCPHost) ConnectInProcess(ctx context.Context, serverID string, server *server.MCPServer) (*ServerConnection, error)
- func (h *MCPHost) ConnectSSE(ctx context.Context, serverID string, baseURL string, ...) (*ServerConnection, error)
- func (h *MCPHost) ConnectStdio(ctx context.Context, serverID string, command string, env []string, ...) (*ServerConnection, error)
- func (h *MCPHost) DisconnectAll()
- func (h *MCPHost) DisconnectServer(serverID string) error
- func (h *MCPHost) EnsureConnection(ctx context.Context, serverID string) (*ServerConnection, error)
- func (h *MCPHost) ExecuteTool(ctx context.Context, serverID string, toolName string, args map[string]any) (*mcp.CallToolResult, error)
- func (h *MCPHost) GetAllConnections() map[string]*ServerConnection
- func (h *MCPHost) GetConnection(serverID string) (*ServerConnection, bool)
- func (h *MCPHost) ListResources(ctx context.Context, serverID string) (*mcp.ListResourcesResult, error)
- func (h *MCPHost) ListTools(ctx context.Context, serverID string) (*mcp.ListToolsResult, error)
- func (h *MCPHost) ReadResource(ctx context.Context, serverID string, uri string) (*mcp.ReadResourceResult, error)
- func (h *MCPHost) SetGlobalNotificationHandler(handler func(serverID string, notification mcp.JSONRPCNotification))
- func (h *MCPHost) SetNotificationHandler(serverID string, handler func(mcp.JSONRPCNotification)) error
- type ServerConnection
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConnectionType ¶ added in v0.2.9
type ConnectionType string
const ( SSEConnectionType ConnectionType = "SSE" StdioConnectionType ConnectionType = "Stdio" InProcessConnectionType ConnectionType = "InProcess" )
type MCPHost ¶
type MCPHost struct {
// contains filtered or unexported fields
}
MCPHost 管理多个MCP服务器连接
func (*MCPHost) ConnectInProcess ¶
func (h *MCPHost) ConnectInProcess(ctx context.Context, serverID string, server *server.MCPServer) (*ServerConnection, error)
ConnectInProcess 使用进程内传输方式连接到MCP服务器
func (*MCPHost) ConnectSSE ¶
func (h *MCPHost) ConnectSSE(ctx context.Context, serverID string, baseURL string, options ...transport.ClientOption) (*ServerConnection, error)
ConnectSSE 使用SSE传输连接到MCP服务器
func (*MCPHost) ConnectStdio ¶
func (h *MCPHost) ConnectStdio(ctx context.Context, serverID string, command string, env []string, args ...string) (*ServerConnection, error)
ConnectStdio 使用Stdio传输连接到MCP服务器
func (*MCPHost) DisconnectServer ¶
DisconnectServer 关闭到指定服务器的连接并将其从映射中移除
func (*MCPHost) EnsureConnection ¶ added in v0.2.9
func (*MCPHost) ExecuteTool ¶
func (h *MCPHost) ExecuteTool(ctx context.Context, serverID string, toolName string, args map[string]any) (*mcp.CallToolResult, error)
ExecuteTool 在指定服务器上执行工具
func (*MCPHost) GetAllConnections ¶
func (h *MCPHost) GetAllConnections() map[string]*ServerConnection
GetAllConnections 返回所有服务器连接的映射副本
func (*MCPHost) GetConnection ¶
func (h *MCPHost) GetConnection(serverID string) (*ServerConnection, bool)
GetConnection 通过ID获取服务器连接
func (*MCPHost) ListResources ¶
func (h *MCPHost) ListResources(ctx context.Context, serverID string) (*mcp.ListResourcesResult, error)
ListResources 列出指定服务器上的所有资源
func (*MCPHost) ReadResource ¶
func (h *MCPHost) ReadResource(ctx context.Context, serverID string, uri string) (*mcp.ReadResourceResult, error)
ReadResource 从指定服务器读取资源
func (*MCPHost) SetGlobalNotificationHandler ¶
func (h *MCPHost) SetGlobalNotificationHandler(handler func(serverID string, notification mcp.JSONRPCNotification))
SetGlobalNotificationHandler 为所有服务器设置通知处理程序
func (*MCPHost) SetNotificationHandler ¶
func (h *MCPHost) SetNotificationHandler(serverID string, handler func(mcp.JSONRPCNotification)) error
SetNotificationHandler 为特定服务器设置通知处理程序
type ServerConnection ¶
type ServerConnection struct {
Type ConnectionType
Client *client.Client
ServerID string
Options []transport.ClientOption
BaseURL string
ServerInfo *mcp.InitializeResult
Capabilities mcp.ServerCapabilities
Connected bool
}
ServerConnection 到单个MCP服务器的连接
Click to show internal directories.
Click to hide internal directories.