Documentation
¶
Overview ¶
Package core holds the domain model and the ports that adapters implement.
The MCP protocol's own types (*mcp.Tool, *mcp.CallToolResult, json.RawMessage arguments) are the domain vocabulary: this is an MCP gateway, so the protocol model IS the model. Adapters translate the world into these types; the core never imports transport or storage code.
Index ¶
Constants ¶
const ( EventToolCall = "tool_call" EventAuthFailed = "auth_failed" EventBackendError = "backend_error" EventToolForbidden = "tool_forbidden" EventReload = "reload" EventGovern = "govern" )
Event kinds.
Variables ¶
var ErrNotApproved = errors.New("tool is not approved or does not exist")
ErrNotApproved is the fail-closed default for any name Resolve did not produce — including never-discovered and malformed names.
var Version = "0.0.1"
Version is the single source for what the binary reports to MCP clients. Release builds stamp it: -ldflags "-X .../internal/core.Version=vX.Y.Z".
Functions ¶
func IsQualified ¶
IsQualified reports whether s parses as a qualified tool name.
Types ¶
type AuditSink ¶
type AuditSink interface {
Record(Event)
}
AuditSink receives every Event (driven port). Implementations must not block the call path meaningfully — append-and-go.
type Event ¶
type Event struct {
TS time.Time `json:"ts"`
Kind string `json:"kind"` // tool_call | auth_failed | backend_error | reload
Backend string `json:"backend,omitempty"`
Tool string `json:"tool,omitempty"`
MS int64 `json:"ms,omitempty"`
Err string `json:"err,omitempty"`
Remote string `json:"remote,omitempty"`
}
Event is one governed action's evidence — the driven audit port.
type Passthrough ¶
type Passthrough interface {
Passthrough() bool
}
Passthrough marks an upstream whose tool names are already qualified — a federated toolhost gateway. Resolve trusts the names instead of re-namespacing.
type Resolution ¶
type Resolution struct {
Tools []ResolvedTool // qualified-name sorted
Skipped []SkippedTool
}
Resolution is the output of the one place visibility is decided.
func Resolve ¶
func Resolve(upstreams []Upstream, approved, enabled map[string]bool) (*Resolution, error)
Resolve answers "what can be seen and called" — the ONLY place that question is answered. A tool is exposed iff it is discovered AND approved AND enabled: discovered ≠ approved ≠ enabled. A nil enabled set means "no allowlist configured" — every approved tool is enabled. A non-nil enabled set intersects: the live surface is enabled ∩ approved.
A duplicate qualified name is a hard error: two upstreams claiming one wire name is a routing ambiguity, and ambiguity denies.
type ResolvedTool ¶
type ResolvedTool struct {
Qualified string // "fs__read_file" — the wire name
Origin string // "read_file" — the upstream's own name
Upstream Upstream // session to dispatch to
Tool *mcp.Tool // namespaced copy registered on the front door
}
ResolvedTool is one upstream tool that is BOTH visible and callable under its qualified name. The pair cannot come apart: the front door registers exactly these, and dispatch closes over Upstream+Origin directly.
type SkippedTool ¶
SkippedTool is a discovered tool that cannot be exposed — with the reason. Skipping is per-tool: one bad upstream name must never darken a backend.
type ToolInfo ¶
type ToolInfo struct {
Qualified string `json:"qualified"`
Description string `json:"description,omitempty"`
Approved bool `json:"approved"`
Enabled bool `json:"enabled"`
// Requested marks an agent-filed approval request still waiting on a
// human — visible so the agent knows it already asked.
Requested bool `json:"requested,omitempty"`
}
ToolInfo is one catalog entry — a discovered tool plus its governance state, as reported by the gateway's own toolhost__* meta-tools.
type Upstream ¶
type Upstream interface {
// Namespace is the backend's short lowercase name ("fs", "github").
Namespace() string
// Tools is the discovered inventory, original upstream names.
Tools() []*mcp.Tool
// Call invokes one discovered tool by its ORIGINAL name.
Call(ctx context.Context, tool string, args json.RawMessage) (*mcp.CallToolResult, error)
// Close releases the session (subprocess or HTTP connection).
Close() error
}
Upstream is one connected backend MCP server — the driven port every backend adapter implements.