Documentation
¶
Overview ¶
Package mcp implements a Model Context Protocol client. Spec: https://spec.modelcontextprotocol.io/specification/2024-11-05/
Index ¶
Constants ¶
This section is empty.
Variables ¶
var EnableAutoDiscovery bool
EnableAutoDiscovery gates zero-config detection of locally-running MCP backends (currently Blender and Unity). The lite desktop (stdio.Run) and lite web (webmode.Run) entrypoints set it true so the sidecar connects a backend the moment its editor plugin is reachable — no hand-editing of .agent/mcp.json. The pure CLI leaves it false so it never pays the probe cost.
var Global = &globalRegistry{ regs: map[string]*Registry{}, }
Global is the process-wide cache of per-workspace registries.
Functions ¶
func SaveConfig ¶
func SaveConfig(workspace string, cfgs []ServerConfig) error
SaveConfig writes the MCP server list to disk.
func SaveCustomTools ¶
func SaveCustomTools(workspace string, tools []CustomTool) error
SaveCustomTools writes custom tool definitions to disk.
Types ¶
type CustomTool ¶
type CustomTool struct {
Name string `json:"name"`
Description string `json:"description"`
InputSchema map[string]any `json:"inputSchema"`
Command string `json:"command"`
Env map[string]string `json:"env,omitempty"`
Enabled bool `json:"enabled"`
}
CustomTool defines a workspace-local tool backed by a shell command. Template variables {{param_name}} in Command are replaced with argument values.
func LoadCustomTools ¶
func LoadCustomTools(workspace string) ([]CustomTool, error)
LoadCustomTools reads custom tool definitions from <workspace>/.agent/tools.json.
type MCPTool ¶
type MCPTool struct {
Name string `json:"name"`
Description string `json:"description"`
InputSchema map[string]any `json:"inputSchema"`
}
MCPTool is one tool advertised by an MCP server.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry manages MCP server connections for one workspace.
func (*Registry) Dispatch ¶
func (r *Registry) Dispatch(ctx context.Context, qualifiedName string, args map[string]any) (string, bool)
Dispatch routes an mcp__<server>__<tool> call to the appropriate server. Returns (output, isError).
type SSEClient ¶
type SSEClient struct {
// contains filtered or unexported fields
}
SSEClient connects to an MCP server via HTTP + Server-Sent Events. Implements the MCP 2024-11-05 SSE transport.
func NewSSEClient ¶
func NewSSEClient(cfg ServerConfig) *SSEClient
NewSSEClient creates (but does not connect) an SSE MCP client.
func (*SSEClient) CallTool ¶
func (c *SSEClient) CallTool(ctx context.Context, name string, args map[string]any) (string, bool, error)
CallTool invokes a named tool.
type ServerConfig ¶
type ServerConfig struct {
Name string `json:"name"`
Type string `json:"type"` // "stdio" | "sse"
Command string `json:"command,omitempty"`
Args []string `json:"args,omitempty"`
Env map[string]string `json:"env,omitempty"`
URL string `json:"url,omitempty"` // for "sse" type
Enabled bool `json:"enabled"`
}
ServerConfig describes one MCP server entry in mcp.json.
func LoadConfig ¶
func LoadConfig(workspace string) ([]ServerConfig, error)
LoadConfig reads the MCP server list from <workspace>/.agent/mcp.json. Returns an empty slice (not an error) when the file doesn't exist yet.
type StdioClient ¶
type StdioClient struct {
// contains filtered or unexported fields
}
StdioClient connects to an MCP server via a child process.
func NewStdioClient ¶
func NewStdioClient(cfg ServerConfig) *StdioClient
NewStdioClient creates (but does not connect) a stdio MCP client.
func (*StdioClient) CallTool ¶
func (c *StdioClient) CallTool(ctx context.Context, name string, args map[string]any) (string, bool, error)
CallTool invokes a named tool and returns its text output and isError flag.