agentmcp

package
v2.37.0 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2026 License: AGPL-3.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const ToolNameSep = "__"

ToolNameSep separates the server name from the original tool name in prefixed tool names. Double underscore avoids collisions with tool names that may contain single underscores.

Variables

View Source
var (
	// ErrInvalidToolName is returned when the tool name format
	// is not "server__tool".
	ErrInvalidToolName = xerrors.New("invalid tool name format")
	// ErrUnknownServer is returned when no MCP server matches
	// the prefix in the tool name.
	ErrUnknownServer = xerrors.New("unknown MCP server")
	// ErrManagerClosed is returned by Reload and Tools after
	// Close. Close cancels the Manager's derived context, so this
	// sentinel keeps explicit Close distinguishable from parent
	// context cancellation.
	ErrManagerClosed = xerrors.New("manager closed")
)

Functions

This section is empty.

Types

type API

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

API exposes MCP tool-call proxying through the agent. Tool discovery is handled in-process by the agentcontext manager, which reads the shared Manager's catalog and pushes it to coderd as pinned context resources; this API serves only execution.

func NewAPI

func NewAPI(m *Manager) *API

NewAPI creates a new MCP API handler.

func (*API) Routes

func (api *API) Routes() http.Handler

Routes returns the HTTP handler for MCP-related routes.

type Manager

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

Manager manages connections to MCP servers discovered from a workspace's .mcp.json file. It caches the aggregated tool list and proxies tool calls to the appropriate server.

func NewManager

func NewManager(
	ctx context.Context,
	logger slog.Logger,
	execer agentexec.Execer,
	updateEnv func([]string) ([]string, error),
) *Manager

NewManager creates a new MCP client manager. The ctx bounds subprocess lifetime. The execer applies resource limits to MCP server subprocesses. The updateEnv callback enriches the subprocess environment to match interactive sessions.

func (*Manager) CallTool

CallTool proxies a tool call to the appropriate MCP server.

func (*Manager) Catalog added in v2.35.0

func (m *Manager) Catalog() []ServerStatus

Catalog returns a deep copy of the current per-server MCP snapshot. It never blocks on I/O: the agentcontext resolver calls it on every re-resolve to build KindMCPServer resources.

func (*Manager) Close

func (m *Manager) Close() error

Close terminates all MCP server connections and child processes, stops the config file watcher, and waits for any in-flight watcher-driven reload to complete.

func (*Manager) Reload added in v2.33.0

func (m *Manager) Reload(ctx context.Context, paths []string) error

Reload ensures the tool cache reflects the current config.

If config files differ from the last snapshot, a singleflight differential reconnect is driven and Reload waits for it. If the snapshot is current, Reload returns immediately.

Starting and running the reload is manager-scoped. Caller contexts may bound only that caller's wait for the reload result. They are never passed to, and must not suppress, the reload body.

func (*Manager) SetOnReload added in v2.35.0

func (m *Manager) SetOnReload(fn func())

SetOnReload registers a callback fired (outside the cache lock) after a reload changes the per-server catalog. The agent wires this to the agentcontext manager's Trigger so discovery re-resolves and re-pushes the updated KindMCPServer resources. It must be called before the first Reload.

func (*Manager) SnapshotChanged added in v2.33.0

func (m *Manager) SnapshotChanged(paths []string) bool

SnapshotChanged checks whether any config file has changed since the last reload by comparing os.Stat results against the stored snapshot.

type ServerConfig

type ServerConfig struct {
	Name      string            `json:"name"`
	Transport string            `json:"type"`
	Command   string            `json:"command"`
	Args      []string          `json:"args"`
	Env       map[string]string `json:"env"`
	URL       string            `json:"url"`
	Headers   map[string]string `json:"headers"`
}

ServerConfig describes a single MCP server parsed from a .mcp.json file.

func ParseConfig

func ParseConfig(path string) ([]ServerConfig, error)

ParseConfig reads a .mcp.json file at path and returns the declared MCP servers sorted by name. It returns an empty slice when the mcpServers key is missing or empty.

type ServerStatus added in v2.35.0

type ServerStatus struct {
	Name      string
	Connected bool
	Err       string
	Tools     []ToolInfo
}

ServerStatus is a point-in-time view of one MCP server's connection state and tools, used by the agentcontext resolver to build KindMCPServer resources. Tool names are exactly as the server reported them (no server prefix); the resource carries the server name separately.

type ToolInfo added in v2.35.0

type ToolInfo struct {
	Name        string
	Description string
	InputSchema map[string]any
}

ToolInfo is one tool exposed by an MCP server. InputSchema is the JSON-Schema-shaped object the server reported for the tool's arguments, or nil when the schema is empty.

Jump to

Keyboard shortcuts

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