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 ¶
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 ¶
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 ¶
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.
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.