mcp

package
v0.5.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CallResult

type CallResult struct {
	Output  string
	IsError bool
}

CallResult is the outcome of a tools/call request.

type Pool

type Pool struct {
	// contains filtered or unexported fields
}

Pool manages MCP server connections for a single session. It is created in session.initBrain and torn down when the session context is cancelled (stdio child processes are killed via their exec.CommandContext).

func NewPool

func NewPool(ctx context.Context, configs []ServerConfig) *Pool

NewPool connects to all configured MCP servers, runs the initialize+tools/list handshake for each, and returns a ready pool.

Servers that fail to start are logged and skipped so a single broken server does not prevent the rest from working.

The caller is responsible for deny-list URL filtering before passing configs; see session.initBrain which calls isURLDenied before adding an entry.

func (*Pool) Call

func (p *Pool) Call(qualifiedName string, args map[string]any) (string, bool, error)

Call dispatches a tool call to the appropriate MCP server and returns the result. qualifiedName must be of the form "mcp__<server>__<tool>". Internal vix params (cwd, allowed_dirs, headless, _session, confirmed) are stripped before forwarding to the server.

func (*Pool) RequiresConfirmation

func (p *Pool) RequiresConfirmation(qualifiedName string) bool

RequiresConfirmation reports whether the server that owns qualifiedName has require_confirmation: true.

func (*Pool) ServerCount

func (p *Pool) ServerCount() int

ServerCount returns the number of successfully connected MCP servers.

func (*Pool) Shutdown

func (p *Pool) Shutdown()

Shutdown closes all MCP server connections.

func (*Pool) ToolCount

func (p *Pool) ToolCount() int

ToolCount returns the total number of MCP tools available in the pool.

func (*Pool) ToolSchemas

func (p *Pool) ToolSchemas() []llm.ToolParam

ToolSchemas returns neutral llm.ToolParam definitions for every MCP tool in the pool. Tool names are the qualified form "mcp__<server>__<tool>".

type ServerConfig

type ServerConfig struct {
	// Name is a unique identifier used to prefix tool names: mcp__<name>__<tool>.
	Name string `json:"name"`
	// Type is the transport: "stdio" (default) or "url".
	Type string `json:"type,omitempty"`
	// Command and Args are used for stdio servers.
	Command string   `json:"command,omitempty"`
	Args    []string `json:"args,omitempty"`
	// Env adds extra environment variables for the stdio child process.
	Env map[string]string `json:"env,omitempty"`
	// URL is used for HTTP/SSE servers.
	URL string `json:"url,omitempty"`
	// Headers are sent with every HTTP request (e.g. Authorization).
	// Values of the form "${VAR}" are expanded from the environment at connect time.
	Headers map[string]string `json:"headers,omitempty"`
	// AllowedTools, when non-empty, restricts which tools from this server are
	// exposed to the LLM. Unlisted tools are silently dropped after tools/list.
	AllowedTools []string `json:"allowed_tools,omitempty"`
	// RequireConfirmation makes every tool call from this server require explicit
	// user approval via the standard confirm_request / session.confirm flow.
	RequireConfirmation bool `json:"require_confirmation,omitempty"`
}

ServerConfig describes a single MCP server entry from settings.json.

type ToolDef

type ToolDef struct {
	Name        string         `json:"name"`
	Description string         `json:"description"`
	InputSchema map[string]any `json:"inputSchema"`
}

ToolDef is a tool discovered from an MCP server via tools/list.

Jump to

Keyboard shortcuts

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