agentmcp

package
v2.33.5 Latest Latest
Warning

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

Go to latest
Published: May 19, 2026 License: AGPL-3.0 Imports: 28 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")
)

Functions

This section is empty.

Types

type API

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

API exposes MCP tool discovery and call proxying through the agent.

func NewAPI

func NewAPI(
	logger slog.Logger,
	manager *Manager,
	mcpConfigFiles func() []string,
) *API

NewAPI creates a new MCP API handler backed by the given manager. The mcpConfigFiles callback returns the current resolved config file paths; it is called on every tool-list request to detect config changes.

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

func (m *Manager) Close() error

Close terminates all MCP server connections and child processes.

func (*Manager) RefreshTools

func (m *Manager) RefreshTools(ctx context.Context) error

RefreshTools re-fetches tool lists from all connected servers in parallel and rebuilds the cache. On partial failure, tools from servers that responded successfully are merged with the existing cached tools for servers that failed, so a single dead server doesn't block updates from healthy ones.

func (*Manager) Reload added in v2.33.0

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

Reload checks whether config files have changed and, if so, performs a differential reconnect. Concurrent callers are coalesced via singleflight; the reload body runs under the Manager's lifetime context so it survives caller cancellation.

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.

func (*Manager) Tools

func (m *Manager) Tools() []workspacesdk.MCPToolInfo

Tools returns the cached tool list. Thread-safe.

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.

Jump to

Keyboard shortcuts

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