mcp

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2026 License: AGPL-3.0 Imports: 22 Imported by: 0

Documentation

Overview

Package mcp implements MCP client configuration and tool adapters.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EncodeToolName

func EncodeToolName(serverID, remoteName string) (string, error)

EncodeToolName makes a host-safe and reversible MCP tool name.

func ValidateServerConfig

func ValidateServerConfig(server config.MCPServerConfig) error

ValidateServerConfig validates one secret-free MCP server definition.

Types

type Manager

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

Manager owns one lazy client per configured MCP server.

func NewManager

func NewManager(cfg config.MCPConfig, opts ManagerOptions) (*Manager, error)

NewManager constructs a disconnected MCP manager.

func (*Manager) Close

func (m *Manager) Close() error

Close closes every connected MCP client. The manager mutex is held only for map bookkeeping: the closed flag is set and the clients are snapshotted under the lock, then each client's Close runs outside it, so a hung client close (bounded by mcpShutdownTimeout) can never stall the accessors, EnsureServers, or a concurrent Close. commitClaim's closed check still closes an in-flight connect's client instead of storing it, so no client leaks or double-closes (serializedRemoteClient.Close is idempotent).

func (*Manager) EnsureServers

func (m *Manager) EnsureServers(ctx context.Context, ids []string) ([]tools.Tool, error)

EnsureServers discovers tools for the requested server IDs once per session.

A server that fails to connect or to be discovered is contained: its failure is recorded and the other requested servers still get their tools. A server outage must never fail a session or a workflow start; the caller receives the tools of the healthy servers. Structural errors - a closed manager, MCP disabled, or an unknown server ID - still fail, because they are caller or configuration bugs, not server outages.

Concurrent calls for the same server ID single-flight on a per-server pending claim, so each server is connected and discovered once per session. The manager mutex is held only for map bookkeeping: connect, ListTools, and tool wrapping run without it, so Failures, OwnsTool, Close, and concurrent EnsureServers calls never block behind a network round trip.

func (*Manager) Failures

func (m *Manager) Failures() map[string]error

Failures reports the servers whose connection or discovery failed, keyed by server ID. A contained server outage never fails a session or a workflow start; callers use this accessor to surface which tools are absent and why.

func (*Manager) OwnsTool

func (m *Manager) OwnsTool(name string) bool

OwnsTool reports whether name is one wrapper this manager discovered.

type ManagerOptions

type ManagerOptions struct {
	Connect         func(context.Context, config.MCPServerConfig) (remoteClient, error)
	RedactionPolicy *redact.Policy
}

ManagerOptions supplies the transport constructor. Production wiring uses the MCP SDK constructor. Tests provide a deterministic fake.

Jump to

Keyboard shortcuts

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