core

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: MIT Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const (
	EventToolCall      = "tool_call"
	EventAuthFailed    = "auth_failed"
	EventBackendError  = "backend_error"
	EventBackendUp     = "backend_up"
	EventToolForbidden = "tool_forbidden"
	EventSchemaDrift   = "schema_drift"
	EventReload        = "reload"
	EventGovern        = "govern"
)

Event kinds.

Variables

View Source
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.

View Source
var Version = "0.0.4"

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

func IsQualified(s string) bool

IsQualified reports whether s parses as a qualified tool name.

func Qualify

func Qualify(up Upstream, name string) (string, error)

Qualify is the one name-mapping rule shared by Resolve and the meta catalog: passthrough upstreams keep their (already qualified) names — except the inner gateway's own gateway__* (or legacy toolhost__*) control plane, which is dropped; everything else is namespaced backend__tool.

func SchemaHash added in v0.0.3

func SchemaHash(t *mcp.Tool) string

SchemaHash fingerprints the contract a tool is approved against: input and output schemas as canonical JSON. The unmarshal/remarshal round-trip normalizes whitespace and map order, so transport formatting can't false-positive as drift — only a real schema change lapses an approval.

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
	// Drifted holds approved tools whose schema no longer matches the hash
	// recorded at approve time — approval is bound to the contract that was
	// reviewed, so drift lapses it until a human re-approves.
	Drifted []SkippedTool
}

Resolution is the output of the one place visibility is decided.

func Resolve

func Resolve(upstreams []Upstream, approved, enabled map[string]bool, schemas map[string]string) (*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.

schemas binds approvals to the contract reviewed at approve time: qualified name → SchemaHash. An approved tool whose hash mismatches is drifted — it drops off the surface (audited) until re-approved. An approved name with no recorded hash is unbound (pre-binding approvals) and enforced as before.

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 ServerSpec added in v0.0.4

type ServerSpec struct {
	Name      string   `json:"name"`
	Transport string   `json:"transport"` // "stdio" | "http"
	URL       string   `json:"url,omitempty"`
	Command   string   `json:"command,omitempty"`
	Args      []string `json:"args,omitempty"`
}

ServerSpec is an agent-proposed backend — the petition payload gateway__request files for a human to materialize into config. Topology only, never credentials: a proposal can't smuggle secrets into the envelope.

type SkippedTool

type SkippedTool struct {
	Backend   string
	Tool      string
	Qualified string
	Reason    string
}

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"`
	// Drifted marks an approved tool whose upstream schema no longer
	// matches the schema hash recorded at approve time — the approval
	// lapsed; re-approving pins the new schema.
	Drifted bool `json:"drifted,omitempty"`
	// Denied marks a petition a human refused — the agent sees the verdict
	// rather than re-asking into a silent wall.
	Denied       bool   `json:"denied,omitempty"`
	DeniedReason string `json:"denied_reason,omitempty"`
}

ToolInfo is one catalog entry — a discovered tool plus its governance state, as reported by the gateway's own gateway__* verbs.

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.

Jump to

Keyboard shortcuts

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