Documentation
¶
Index ¶
- type CallToolResult
- type Client
- func (c *Client) Call(ctx context.Context, method string, params interface{}) (json.RawMessage, error)
- func (c *Client) CallTool(ctx context.Context, name string, args json.RawMessage) (CallToolResult, error)
- func (c *Client) Close() error
- func (c *Client) Done() <-chan struct{}
- func (c *Client) Initialize(ctx context.Context) error
- func (c *Client) IsClosed() bool
- func (c *Client) ListTools(ctx context.Context) ([]ToolInfo, error)
- func (c *Client) Notify(method string, params interface{}) error
- func (c *Client) SetRequestTimeout(d time.Duration)
- func (c *Client) Start() error
- type JSONRPCError
- type JSONRPCRequest
- type JSONRPCResponse
- type MCPTool
- type Manager
- func (m *Manager) AddServer(name string, cfg config.MCPServerConfig)
- func (m *Manager) CloseAll()
- func (m *Manager) EnsureClient(ctx context.Context, server string) (*Client, error)
- func (m *Manager) ListServers() map[string]config.MCPServerConfig
- func (m *Manager) RemoveServer(name string)
- func (m *Manager) StartAll(ctx context.Context, toolRegistry *tools.Registry) error
- type ToolContent
- type ToolInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CallToolResult ¶
type CallToolResult struct {
Content []ToolContent `json:"content"`
IsError bool `json:"isError"`
}
CallToolResult holds the result of a tools/call request.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client manages an MCP server process communicating via stdio JSON-RPC.
func NewClientWithEnvScrub ¶ added in v0.7.4
func NewClientWithEnvScrub(command string, args []string, env map[string]string, envScrub []string) *Client
NewClientWithEnvScrub creates a new MCP client whose child process environment excludes credential-shaped variables plus envScrub names.
func (*Client) Call ¶
func (c *Client) Call(ctx context.Context, method string, params interface{}) (json.RawMessage, error)
Call sends a JSON-RPC request and awaits the response.
func (*Client) CallTool ¶
func (c *Client) CallTool(ctx context.Context, name string, args json.RawMessage) (CallToolResult, error)
CallTool executes a specific tool on the MCP server.
func (*Client) Done ¶ added in v0.7.4
func (c *Client) Done() <-chan struct{}
Done is closed when the server process exits or Close is called.
func (*Client) Initialize ¶
Initialize performs the MCP protocol handshake.
func (*Client) IsClosed ¶ added in v0.7.4
IsClosed reports whether the client is unusable because the server process exited or Close was called.
func (*Client) SetRequestTimeout ¶ added in v0.7.4
SetRequestTimeout bounds a single JSON-RPC request. Non-positive values restore the 60s default.
type JSONRPCError ¶
type JSONRPCError struct {
Code int `json:"code"`
Message string `json:"message"`
Data json.RawMessage `json:"data,omitempty"`
}
JSONRPCError holds JSON-RPC error payload.
func (*JSONRPCError) Error ¶
func (e *JSONRPCError) Error() string
type JSONRPCRequest ¶
type JSONRPCRequest struct {
JSONRPC string `json:"jsonrpc"`
ID *uint64 `json:"id,omitempty"`
Method string `json:"method"`
Params json.RawMessage `json:"params,omitempty"`
}
JSONRPCRequest represents a standard JSON-RPC 2.0 request.
type JSONRPCResponse ¶
type JSONRPCResponse struct {
JSONRPC string `json:"jsonrpc"`
ID *uint64 `json:"id,omitempty"`
Result json.RawMessage `json:"result,omitempty"`
Error *JSONRPCError `json:"error,omitempty"`
}
JSONRPCResponse represents a standard JSON-RPC 2.0 response.
type MCPTool ¶
type MCPTool struct {
// contains filtered or unexported fields
}
MCPTool adapts an MCP tool to the tools.Tool interface.
func NewMCPTool ¶
NewMCPTool creates a tools.Tool adapter for an MCP tool.
func (*MCPTool) Preview ¶ added in v0.7.4
Preview shows the server, tool, and arguments awaiting approval.
func (*MCPTool) ReadOnly ¶ added in v0.7.4
ReadOnly reports the server's MCP readOnlyHint. The approval gate uses it only to honor an explicit "read-only tools this turn" choice; a server that lies about the hint is still gated by the per-call prompt otherwise.
func (*MCPTool) RequiresApproval ¶
type Manager ¶
type Manager struct {
// EnvScrub lists additional env var names or patterns to drop from every
// spawned MCP server, on top of the built-in credential patterns.
EnvScrub []string
// contains filtered or unexported fields
}
Manager coordinates all configured MCP clients.
func NewManager ¶
func NewManager(servers map[string]config.MCPServerConfig) *Manager
NewManager creates a new MCP Manager with server configurations.
func (*Manager) AddServer ¶
func (m *Manager) AddServer(name string, cfg config.MCPServerConfig)
AddServer saves a new server configuration.
func (*Manager) CloseAll ¶
func (m *Manager) CloseAll()
CloseAll closes all active MCP client connections. After CloseAll, servers are never restarted on demand.
func (*Manager) EnsureClient ¶ added in v0.7.4
EnsureClient returns a live client for server, restarting the server process when its previous client is closed. Concurrent callers share a single restart, and the restart is serialized against CloseAll. Tools stay registered across a restart; only the client pointer moves.
func (*Manager) ListServers ¶
func (m *Manager) ListServers() map[string]config.MCPServerConfig
ListServers returns all configured server names and configs.
func (*Manager) RemoveServer ¶
RemoveServer removes a server configuration.
type ToolContent ¶
ToolContent is a piece of output returned from an MCP tool call.
type ToolInfo ¶
type ToolInfo struct {
Name string `json:"name"`
Description string `json:"description"`
InputSchema json.RawMessage `json:"inputSchema"`
// Annotations carries MCP hints; readOnlyHint lets the approval gate offer
// "read-only tools this turn" for servers that declare safe tools.
Annotations *struct {
ReadOnlyHint bool `json:"readOnlyHint"`
} `json:"annotations,omitempty"`
}
ToolInfo describes an MCP tool definition.