Documentation
¶
Overview ¶
Package mcpmanager manages MCP server resources declared in agent policy.
Index ¶
- Constants
- Variables
- func AuditToolCall(appender audit.AuditAppender, ...)
- func AuditToolDenied(appender audit.AuditAppender, ...)
- func IsHostAffecting(toolName string) bool
- func MCPStatusJSON(ctx context.Context, manager *Manager, lifecycle *Lifecycle, ...) ([]byte, error)
- func RedactToolOutput(output any) string
- func RedactToolOutputHash(output any) string
- type CrashContext
- type EgressPolicy
- type HTTPDoer
- type HostAffectingCapability
- type Lifecycle
- func (lc *Lifecycle) CheckReadiness(ctx context.Context, serverID string, timeout time.Duration) error
- func (lc *Lifecycle) CrashContext(serverID string) *CrashContext
- func (lc *Lifecycle) IsRunning(serverID string) bool
- func (lc *Lifecycle) Start(ctx context.Context, serverID, agentID, runID string) error
- func (lc *Lifecycle) StdioPipes(serverID string) (io.Writer, <-chan stdioLine, error)
- func (lc *Lifecycle) Stop(ctx context.Context, serverID string) error
- func (lc *Lifecycle) StopAll(ctx context.Context) error
- type MCPSidecarInfo
- type Manager
- func (m *Manager) ConfirmTool(serverID, tool string)
- func (m *Manager) DenyToolCall(appender audit.AuditAppender, ...)
- func (m *Manager) IsToolAllowed(serverID, tool string) bool
- func (m *Manager) IsToolConfirmed(serverID, tool string) bool
- func (m *Manager) Register(servers []policy.MCPServer, agentID, runID string)
- func (m *Manager) RequiresConfirmation(serverID, tool string) bool
- func (m *Manager) Status() []Resource
- func (m *Manager) Validate(servers []policy.MCPServer) error
- type Resource
- type Router
- type StatusReport
Constants ¶
const ( ReadinessStopped = "stopped" ReadinessStarting = "starting" ReadinessReady = "ready" ReadinessUnhealthy = "unhealthy" )
Readiness states for MCP servers.
const ( HealthUnknown = "unknown" HealthHealthy = "healthy" HealthFailed = "failed" )
Health states for MCP servers.
Variables ¶
var ErrServerCrashed = errors.New("mcp server crashed")
ErrServerCrashed indicates a stopped MCP server has crash context.
Functions ¶
func AuditToolCall ¶
func AuditToolCall(appender audit.AuditAppender, serverID, tool, agentID, runID, decision, policyRuleID, credentialID string, inputHash, outputHash string, timingMS int64)
AuditToolCall records an MCP tool call audit event. decision: "allowed" or "denied" policyRuleID: the policy rule that authorized the call (or "undeclared" if denied) credentialID: the credential used (empty if none)
func AuditToolDenied ¶
func AuditToolDenied(appender audit.AuditAppender, serverID, tool, agentID, runID, reason, policyRuleID string, metadata ...any)
AuditToolDenied records an MCP tool denial audit event with full metadata.
func IsHostAffecting ¶
IsHostAffecting returns true if the tool name matches a host-affecting pattern.
func MCPStatusJSON ¶
func MCPStatusJSON(ctx context.Context, manager *Manager, lifecycle *Lifecycle, driver runtime.RuntimeDriver) ([]byte, error)
MCPStatusJSON returns an encoded MCP status payload suitable for CLI status output.
func RedactToolOutput ¶
RedactToolOutput sanitizes MCP tool output for safe display/audit. It:
- Escapes control characters (prevents terminal escape injection)
- Redacts sentinel secret patterns
- Truncates excessively long output
Returns the redacted string.
func RedactToolOutputHash ¶
RedactToolOutputHash returns a hash of the redacted output (for audit). Uses the same hashJSONValue function from router.go.
Types ¶
type CrashContext ¶
type CrashContext struct {
ServerID string
Transport string
ExitCode int
ExitTime time.Time
Error string
Recoverable bool
}
CrashContext is structured failure context for a crashed MCP server.
type EgressPolicy ¶
type EgressPolicy struct {
// contains filtered or unexported fields
}
EgressPolicy enforces default-deny outbound network access for MCP servers. MCP servers are separate managed workloads; outbound HTTP requests must be gateway-mediated and policy-checked.
func NewEgressPolicy ¶
func NewEgressPolicy(rules []policy.EgressRule, appender audit.AuditAppender) *EgressPolicy
NewEgressPolicy creates an EgressPolicy from declared policy egress rules. Rules come from policy.EgressRule entries that reference MCP server IDs.
func (*EgressPolicy) AuditEgress ¶
func (ep *EgressPolicy) AuditEgress(serverID, destination, method, credentialID, policyRuleID, decision string)
AuditEgress emits an audit event for an egress decision (allowed or denied).
func (*EgressPolicy) CheckEgress ¶
func (ep *EgressPolicy) CheckEgress(ctx context.Context, serverID, destination, method string) (bool, string, string, error)
CheckEgress validates whether an MCP server may make an outbound request to the given destination with the given method.
type HTTPDoer ¶
HTTPDoer is an interface for making HTTP requests. http.Client satisfies this interface.
type HostAffectingCapability ¶
type HostAffectingCapability string
HostAffectingCapability classifies tools that can affect the host system.
const ( // CapabilityNone means the tool has no host-affecting capability. CapabilityNone HostAffectingCapability = "none" // CapabilityHostAffecting means the tool can control the host // (browser, shell, filesystem, AppleScript, desktop automation). CapabilityHostAffecting HostAffectingCapability = "host_affecting" )
func ClassifyTool ¶
func ClassifyTool(toolName string) HostAffectingCapability
ClassifyTool returns the host-affecting capability for a tool name. A tool is host-affecting if its name contains any of the hostAffectingToolPatterns substrings (case-insensitive).
type Lifecycle ¶
type Lifecycle struct {
// contains filtered or unexported fields
}
Lifecycle manages the start/stop/readiness of declared MCP servers. Stdio servers run as child processes; HTTP servers run as Docker sidecar containers. No host networking is used for MCP sidecars.
func NewLifecycle ¶
func NewLifecycle(manager *Manager, driver runtime.RuntimeDriver, netID string) *Lifecycle
NewLifecycle creates a Lifecycle bound to the given Manager. driver may be nil if only stdio MCP servers will be used. netID is the Docker network ID for MCP sidecars (must NOT be host network).
func (*Lifecycle) CheckReadiness ¶
func (lc *Lifecycle) CheckReadiness(ctx context.Context, serverID string, timeout time.Duration) error
CheckReadiness polls the MCP server until it is ready or timeout.
func (*Lifecycle) CrashContext ¶
func (lc *Lifecycle) CrashContext(serverID string) *CrashContext
CrashContext returns structured failure context for a crashed MCP server.
func (*Lifecycle) StdioPipes ¶
StdioPipes returns the stdin writer and stdout reader for a running stdio MCP server.
type MCPSidecarInfo ¶
type MCPSidecarInfo struct {
ServerID string `json:"server_id"`
ContainerID string `json:"container_id,omitempty"`
ImageDigest string `json:"image_digest,omitempty"`
Labels map[string]string `json:"labels"`
Networks []string `json:"networks"`
Health string `json:"health"`
Readiness string `json:"readiness"`
RestartCount int `json:"restart_count"`
MemoryBytes int64 `json:"memory_bytes,omitempty"`
CPUPercent float64 `json:"cpu_percent,omitempty"`
LastError string `json:"last_error,omitempty"`
}
MCPSidecarInfo contains Docker artifact metadata for an MCP sidecar.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager manages declared MCP server resources.
func (*Manager) ConfirmTool ¶
ConfirmTool marks a host-affecting tool as confirmed for use. This is the confirmation protocol: host-affecting tools cannot be called until confirmed.
func (*Manager) DenyToolCall ¶
func (m *Manager) DenyToolCall(appender audit.AuditAppender, serverID, tool, agentID, runID, policyRuleID string)
DenyToolCall records a denied tool call and emits an audit event.
func (*Manager) IsToolAllowed ¶
IsToolAllowed returns true if the server exists and the tool is in its allowed list. Empty allowed list denies all tools.
func (*Manager) IsToolConfirmed ¶
IsToolConfirmed returns true if a host-affecting tool has been confirmed.
func (*Manager) RequiresConfirmation ¶
RequiresConfirmation returns true if a tool is host-affecting and has not yet been confirmed.
type Resource ¶
type Resource struct {
ResourceType string `json:"resource_type"`
AgentID string `json:"agent_id,omitempty"`
RunID string `json:"run_id,omitempty"`
ServerID string `json:"server_id"`
Transport string `json:"transport"`
AllowedTools []string `json:"allowed_tools"`
Readiness string `json:"readiness"`
Health string `json:"health"`
LastError string `json:"last_error,omitempty"`
PolicyDigest string `json:"policy_digest"`
}
Resource represents a managed MCP server resource.
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router forwards MCP tool calls from the agent to the appropriate local MCP server. Stdio servers receive JSON-RPC over stdin/stdout. HTTP servers receive POST requests to their declared endpoint.
type StatusReport ¶
type StatusReport struct {
Resources []Resource `json:"resources"`
Sidecars []MCPSidecarInfo `json:"sidecars,omitempty"`
Generated time.Time `json:"generated_at"`
}
StatusReport aggregates MCP resource status for operator visibility. This is the data model included in `agent status --json` and dashboard.
func GenerateStatusReport ¶
func GenerateStatusReport(ctx context.Context, manager *Manager, lifecycle *Lifecycle, driver runtime.RuntimeDriver) (*StatusReport, error)
GenerateStatusReport produces a StatusReport from the Manager and optionally from Docker runtime data (if driver is provided). If driver is nil, sidecar info is omitted (stdio-only deployments).