Documentation
¶
Overview ¶
Package mcp provides MCP (Model Context Protocol) client support. MCP allows connecting to external tool servers.
Package mcp provides MCP (Model Context Protocol) client support.
Index ¶
- type Client
- type Content
- type Manager
- func (m *Manager) AllTools() []ToolWithServer
- func (m *Manager) CallTool(ctx context.Context, server, tool string, args map[string]interface{}) (*ToolCallResult, error)
- func (m *Manager) Close() error
- func (m *Manager) Connect(ctx context.Context, name string, config ServerConfig) error
- func (m *Manager) Disconnect(name string) error
- func (m *Manager) FindTool(name string) (server string, found bool)
- func (m *Manager) ServerCount() int
- func (m *Manager) Servers() []string
- func (m *Manager) SetDeniedTools(server string, tools []string)
- type RPCError
- type Request
- type Response
- type ServerConfig
- type Tool
- type ToolCallParams
- type ToolCallResult
- type ToolWithServer
- type ToolsListResult
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 is an MCP client that connects to tool servers.
func NewClient ¶
func NewClient(config ServerConfig) (*Client, error)
NewClient creates a new MCP client for a server.
func (*Client) CallTool ¶
func (c *Client) CallTool(ctx context.Context, name string, args map[string]interface{}) (*ToolCallResult, error)
CallTool invokes a tool on the server.
func (*Client) Initialize ¶
Initialize performs the MCP initialization handshake.
type Content ¶
type Content struct {
Type string `json:"type"`
Text string `json:"text,omitempty"`
Data string `json:"data,omitempty"` // base64 for images
}
Content represents content in a tool result.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager manages multiple MCP server connections.
func (*Manager) AllTools ¶
func (m *Manager) AllTools() []ToolWithServer
AllTools returns all tools from all connected servers, excluding denied tools.
func (*Manager) CallTool ¶
func (m *Manager) CallTool(ctx context.Context, server, tool string, args map[string]interface{}) (*ToolCallResult, error)
CallTool calls a tool on a specific server.
func (*Manager) Disconnect ¶
Disconnect disconnects from an MCP server.
func (*Manager) ServerCount ¶
ServerCount returns the number of connected servers.
func (*Manager) SetDeniedTools ¶
SetDeniedTools sets tools to exclude from a server's tool list. These tools will not be returned by AllTools() and won't be exposed to the LLM.
type Request ¶
type Request struct {
JSONRPC string `json:"jsonrpc"`
ID int64 `json:"id"`
Method string `json:"method"`
Params interface{} `json:"params,omitempty"`
}
Request is a JSON-RPC 2.0 request.
type Response ¶
type Response struct {
JSONRPC string `json:"jsonrpc"`
ID int64 `json:"id"`
Result json.RawMessage `json:"result,omitempty"`
Error *RPCError `json:"error,omitempty"`
}
Response is a JSON-RPC 2.0 response.
type ServerConfig ¶
type ServerConfig struct {
Command string `json:"command"`
Args []string `json:"args,omitempty"`
Env map[string]string `json:"env,omitempty"`
}
ServerConfig configures an MCP server connection.
type Tool ¶
type Tool struct {
Name string `json:"name"`
Description string `json:"description"`
InputSchema map[string]interface{} `json:"inputSchema"`
}
Tool represents an MCP tool definition.
type ToolCallParams ¶
type ToolCallParams struct {
Name string `json:"name"`
Arguments map[string]interface{} `json:"arguments,omitempty"`
}
ToolCallParams are the parameters for tools/call.
type ToolCallResult ¶
ToolCallResult is the result of tools/call.
type ToolWithServer ¶
ToolWithServer pairs a tool with its server name.
type ToolsListResult ¶
type ToolsListResult struct {
Tools []Tool `json:"tools"`
}
ToolsListResult is the result of tools/list.