mcp

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package mcp implements a minimal MCP client (JSON-RPC 2.0 over stdio, newline-delimited) so external MCP servers' tools mount directly into Factor's tool registry as <server>__<tool>.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewTools

func NewTools(m *Manager) []tools.Tool

NewTools returns the MCP self-management tool set.

Types

type Client

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

Client is one connected MCP server process.

func Connect

func Connect(ctx context.Context, name, command string, args []string, env map[string]string) (*Client, error)

Connect spawns the server, performs the initialize handshake, and returns a ready client.

func (*Client) Alive

func (c *Client) Alive() bool

Alive reports whether the server process is still running.

func (*Client) CallTool

func (c *Client) CallTool(ctx context.Context, name string, args map[string]any) (string, bool, error)

CallTool invokes one tool; returns the concatenated text content.

func (*Client) Close

func (c *Client) Close() error

Close terminates the server process.

func (*Client) ListTools

func (c *Client) ListTools(ctx context.Context) ([]ToolSpec, error)

ListTools fetches the server's tool catalog.

type Manager

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

Manager owns MCP server connections and mounts their tools into the registry as <server>__<tool>. It also persists server definitions to the config file so the agent can extend itself durably.

func NewManager

func NewManager(registry *tools.Registry, cfg *config.Config) *Manager

func (*Manager) CloseAll

func (m *Manager) CloseAll()

CloseAll disconnects everything (shutdown).

func (*Manager) Connect

func (m *Manager) Connect(ctx context.Context, name string, srv config.MCPServer) error

Connect spawns one server and mounts its tools. A reservation held for the whole connect prevents two concurrent adds of the same name from spawning a duplicate, orphaned server process.

func (*Manager) Disconnect

func (m *Manager) Disconnect(name string) error

Disconnect closes a server and unmounts its tools.

func (*Manager) StartAll

func (m *Manager) StartAll(ctx context.Context)

StartAll connects every enabled configured server; failures log and skip.

func (*Manager) Status

func (m *Manager) Status() map[string]int

Status lists connected servers and their tool counts.

type ToolSpec

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

ToolSpec is one tool advertised by a server.

Jump to

Keyboard shortcuts

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