mcp

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2026 License: AGPL-3.0 Imports: 17 Imported by: 0

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

View Source
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.

View Source
var Global = &globalRegistry{
	regs: map[string]*Registry{},
}

Global is the process-wide cache of per-workspace registries.

Functions

func IsMCPTool

func IsMCPTool(toolName string) bool

IsMCPTool returns true when toolName was emitted by this registry.

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).

func (*Registry) Reload

func (r *Registry) Reload(ctx context.Context) error

Reload re-reads the workspace MCP config and reconnects all enabled servers. Existing connections are closed before reconnecting.

func (*Registry) Tools

func (r *Registry) Tools(ctx context.Context) []ai.ToolDef

Tools returns ai.ToolDef entries for all tools from all connected servers. Tool names are prefixed mcp__<server>__<tool> to avoid collisions.

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.

func (*SSEClient) Close

func (c *SSEClient) Close()

Close cancels the SSE stream.

func (*SSEClient) Connect

func (c *SSEClient) Connect(ctx context.Context) error

Connect opens the SSE stream and performs the MCP handshake.

func (*SSEClient) ListTools

func (c *SSEClient) ListTools(ctx context.Context) ([]MCPTool, error)

ListTools fetches the server's tool catalog.

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.

func (*StdioClient) Close

func (c *StdioClient) Close()

Close kills the child process.

func (*StdioClient) Connect

func (c *StdioClient) Connect(ctx context.Context) error

Connect spawns the server process and performs the MCP handshake.

func (*StdioClient) ListTools

func (c *StdioClient) ListTools(ctx context.Context) ([]MCPTool, error)

ListTools fetches the server's tool catalog.

Jump to

Keyboard shortcuts

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