catalog

package
v1.0.310 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: MIT Imports: 10 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 catalog is the listener-independent tool catalog for the MCP Security Gateway (PR-2, Capability B only). It ingests an ALREADY-RECEIVED tools/list discovery result (never a network fetch), computes a deterministic per-tool fingerprint, classifies drift against the last known fingerprint, and records quarantine / review / server-disabled dispositions in immutable snapshots.

It decides nothing about policy and executes no tool: PR-2 classifies and records (MCP-TOOL-001/002/003/005); the QUARANTINE/ALLOW enforcement of MCP-TOOL-004/006 is PR-6. There is deliberately NO API that turns an unknown-tool or privilege-expansion observation into a usable/allowed state.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Classify

func Classify(prior, observed *ToolRecord) (DriftClass, []FieldDiff)

Classify assigns exactly one DriftClass to observed relative to prior, and returns the field-level differences in deterministic order. The precedence is explicit and total, so simultaneous changes never resolve by field-visit order:

  1. prior == nil → UnknownTool
  2. identity differs → IdentityChange
  3. any proven privilege broadening → PrivilegeExpansion
  4. any inconsistent behavioral change → SemanticDrift
  5. only provably restrictive changes → SafeNarrowing
  6. fingerprints equal → NoMaterialChange

It is a pure function; a nil observed is treated as an empty (all-changed) diff.

Types

type Catalog

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

Catalog owns the live catalog state. It is lock-free: reads load the atomic snapshot pointer; writes build a new snapshot from a captured base and install it with a single CAS (retrying against the newer base on conflict). A failed or stale publish leaves the current snapshot byte-for-byte unchanged, and no ABBA is possible because no lock is ever held.

func New

func New(lim limits.CatalogLimits) *Catalog

New returns an empty Catalog bounded by lim.

func (*Catalog) Current

func (c *Catalog) Current() *Snapshot

Current returns the current immutable snapshot (lock-free).

func (*Catalog) Demote added in v1.0.218

func (c *Catalog) Demote(key ToolKey) (*Snapshot, error)

Demote is the trust-withdrawal writer (ADR-0034 D7): it returns a Usable tool to the sticky Quarantined floor so it re-enters review, used when a grant is revoked or expires. It is conservative by design — it never tries to reconstruct the tool's observed drift disposition; the next ingestion re-classifies it, and the sticky floor keeps it Quarantined until a fresh fingerprint-bound approval.

Only a Usable record is touched: a tool that is already Quarantined/ReviewRequired /ServerDisabled, or absent, is a no-op (no new revision). Like DisableServer this is a security-relevant transition, so it uses the bounded CAS and returns ReasonStaleSnapshot on contention rather than failing open.

func (*Catalog) DisableServer

func (c *Catalog) DisableServer(serverID registry.ServerID) (*Snapshot, error)

DisableServer marks every catalog entry behind serverID unusable (ServerDisabled) in a single new snapshot. It is the catalog side of a server-identity change: called after registry.VerifyIdentity reports a mismatch, it makes the whole server's tools unusable atomically — no partial mutation, and the mismatch is never expressible as per-tool drift. It is a no-op (no new revision) if nothing changes. Because this is a SECURITY transition that must not be silently dropped, it returns ReasonStaleSnapshot if contention exhausts the retry bound (mirroring Ingest) so the caller retries — it never fails open by returning a snapshot in which the tools are still usable.

func (*Catalog) Ingest

func (c *Catalog) Ingest(reg *registry.Registry, in DiscoveryInput) (*Snapshot, *Report, error)

Ingest validates and classifies a discovery result for one server and publishes a new catalog snapshot. The server record is read from the LIVE registry snapshot (never trusted from the caller), so a stale record captured before a VerifyIdentity mismatch — or a record fabricated without registration — can never bypass the registered-and-usable gate. It is fail-closed at every server-level gate BEFORE any tool is processed, so a server-identity problem can never be laundered into a tool-schema verdict, and it is all-or-nothing (a validation error publishes NOTHING, leaving the previous snapshot unchanged):

  • the server must be registered and usable in the CURRENT registry snapshot (else unregistered/mismatch error);
  • the supplied verified identity must EXACTLY match the live pin (else a server-identity mismatch — discovery is not processed);
  • the whole result parses and validates strictly (else malformed/limit error).

Each tool is classified against its last-known record and written with a disposition that never yields Usable and never auto-clears an existing quarantine. It is the OPERATOR-SEEDED entrypoint: records it writes carry NO peer observation, so their Provenance() is OperatorSeeded. That is not a property of the bytes — a seeded result is deliberately shaped exactly like a real tools/list — it is a property of WHICH ENTRYPOINT was used, which is why the two are separate functions over one implementation rather than one function with a caller-supplied flag. A flag is an assertion the caller makes; an entrypoint is a statement about how the caller got here.

Re-seeding an already peer-observed tool DOWNGRADES it to operator-seeded, even when the fingerprint is byte-identical. That is the point: an operator re-running provisioning is not a new sighting of the peer, and if a reseed preserved the prior observation an operator could keep a long-dead peer's freshness alive indefinitely without the peer ever answering again.

func (*Catalog) IngestObserved added in v1.0.272

func (c *Catalog) IngestObserved(reg *registry.Registry, in DiscoveryInput, obs PeerObservation) (*Snapshot, *Report, error)

IngestObserved is the AUTHENTICATED PEER-OBSERVED entrypoint: it records the same tools with the observation attached, so their Provenance() is PeerObserved and their freshness can be evaluated against a clock.

It is reachable in production from exactly one path — execution.Discovery.Discover, which has already dialed the peer over the supported authenticated transport — and that is enforced structurally rather than by convention, because "only the right caller uses this" is precisely the kind of claim that rots silently.

The observation is validated here, at the boundary, rather than filtered downstream:

  • it must be PRESENT (both a timestamp and a verified identity), else there is nothing to be fresh about and nobody to have been observed;
  • its identity must equal the identity this ingest is being performed under, which the common path then checks against the LIVE registry pin. Letting the two differ would allow an observation of one peer to be filed as evidence about another.

Re-observing an unchanged tool REFRESHES its timestamp: the peer answering again is a new sighting, and the fingerprint being identical is what makes it good news rather than drift.

func (*Catalog) Promote added in v1.0.218

func (c *Catalog) Promote(key ToolKey, expected Fingerprint) (*Snapshot, error)

Promote is the trust-projection writer (ADR-0034 D2): it flips exactly ONE tool's eligibility to Usable, and only when the CURRENT record still matches the exact reviewed fingerprint. It is the catalog side of a human trust grant — the coordinator (package main) calls it AFTER durably persisting an active ToolApproval, so a crash between the two is repaired by startup Recover.

It fails closed at every gate and never fabricates trust:

  • the tool must exist in the current snapshot (else ReasonToolNotFound);
  • a ServerDisabled record is NEVER promoted — the server-identity security override wins over any approval (ReasonToolNotApprovable);
  • the record's fingerprint must EXACTLY equal expected — the rug-pull guard. A tool that drifted away from the reviewed capability is never promoted (ReasonToolFingerprintMismatch);
  • if the tool is already Usable at the same fingerprint the call is an idempotent no-op (no new revision).

Like DisableServer it uses a bounded optimistic CAS and returns ReasonToolApprovalStale on contention (the catalog advanced under the decision), so the caller re-reads and re-decides — it never fails open.

type DestinationClass

type DestinationClass uint8

DestinationClass is the empirically OBSERVED network/resource breadth of a tool, supplied to ingestion as an explicit input (PR-2 makes no observation over the network). It is ORDERED for narrowing/broadening comparison, with DestUnknown standing outside the order (a change to/from it is ambiguous).

const (
	// DestUnknown — not observed. Outside the narrowing/broadening order.
	DestUnknown DestinationClass = iota
	// DestNone — no external destination.
	DestNone
	// DestApproved — a single approved upstream service.
	DestApproved
	// DestInternal — the internal network.
	DestInternal
	// DestArbitrary — arbitrary network / any URL (the broadest).
	DestArbitrary
)

func (DestinationClass) String

func (d DestinationClass) String() string

String returns the destination-class label.

type DiscoveryInput

type DiscoveryInput struct {
	ServerID     registry.ServerID
	Identity     registry.Identity
	Raw          []byte
	Destinations map[string]DestinationClass
}

DiscoveryInput is the explicit, already-received input to Ingest. Raw is one decoded-on-the-wire-elsewhere tools/list result's exact bytes; Identity is the freshly VERIFIED upstream identity for this discovery cycle (compared against the registry pin); Destinations carries the empirically observed per-tool destination class (a tool absent from the map is DestUnknown). PR-2 fetches none of this over the network.

type DriftClass

type DriftClass uint8

DriftClass is the single primary class assigned to a tool observation. Values are listed in the accepted-design order (TOOL-DISCOVERY-AND-DRIFT §2); the CLASSIFICATION PRECEDENCE is a separate, explicit ordering encoded in Classify.

const (
	// NoMaterialChange — the canonical fingerprint is unchanged.
	NoMaterialChange DriftClass = iota
	// SafeNarrowing — every change is MECHANICALLY PROVEN restrictive.
	SafeNarrowing
	// PrivilegeExpansion — a proven, or conservatively-classified ambiguous
	// security-relevant, broadening. Quarantine-required; never auto-allowed.
	PrivilegeExpansion
	// SemanticDrift — a behavioral/description change that is neither proven safe
	// narrowing nor proven expansion. Review-required.
	SemanticDrift
	// IdentityChange — the observed identity differs from the recorded one. A
	// server-level control; every tool behind the server is affected.
	IdentityChange
	// UnknownTool — no prior record for this (server,tool). Quarantine-required.
	UnknownTool
)

func (DriftClass) String

func (d DriftClass) String() string

String returns the stable drift-class code.

type Eligibility

type Eligibility uint8

Eligibility is a catalog entry's usability state. The states make it IMPOSSIBLE to confuse a quarantined/disabled tool with an approved one: no PR-2 ingestion path ever produces Usable (approval is a later slice), and Quarantined is a sticky floor that repeated discovery never auto-clears.

const (
	// Quarantined — unknown tool or privilege expansion. NEVER auto-allowed; only a
	// (future) human approval action clears it. Survives repeated ingestion.
	Quarantined Eligibility = iota
	// ReviewRequired — semantic drift; routed to human review.
	ReviewRequired
	// PendingNarrowing — safe narrowing; pending notification/review disposition.
	PendingNarrowing
	// ServerDisabled — the server's identity changed; every tool behind it is
	// unusable until the server is re-verified (re-registered).
	ServerDisabled
	// Usable — an approved, known tool with no material change. UNREACHABLE through
	// PR-2 ingestion; only a later approval slice can set it. Present so the model
	// and the no-material-change preservation rule are complete.
	Usable
)

func (Eligibility) String

func (e Eligibility) String() string

String returns the eligibility label.

type FieldDiff

type FieldDiff struct {
	Field  string // input_schema | output_schema | description | destination | credential_profile | identity
	Change string // expansion | narrowing | semantic | changed
	Detail string
}

FieldDiff is one field-level difference. Detail is a FIXED, developer-authored phrase — never raw hostile schema/description content.

type Fingerprint

type Fingerprint struct {
	Server            registry.ServerID
	Identity          registry.Identity // canonical verified TLS/workload identity (pinned upstream identity)
	Name              string
	InputSchemaHash   [32]byte
	OutputSchemaHash  [32]byte // meaningful only when HasOutputSchema
	HasOutputSchema   bool
	DescriptiveHash   [32]byte // normalized description + canonical annotations + title
	CredentialProfile registry.CredentialProfile
	Destination       DestinationClass
	FormatVersion     uint16
}

Fingerprint is the deterministic composite identity of a tool observation (MCP-TOOL-001). It carries the eight fingerprint fields plus the format version. Output-schema PRESENCE is explicit (HasOutputSchema) so an absent output schema is distinguishable from a present-but-empty one — they never hash the same.

func (Fingerprint) Equal

func (f Fingerprint) Equal(o Fingerprint) bool

Equal reports byte-exact equality of two fingerprints across every field (including the output-schema presence marker and format version).

func (Fingerprint) Sum

func (f Fingerprint) Sum() [32]byte

Sum returns the SHA-256 composite hash over every fingerprint field in a fixed order with length-prefixed segments (so no two distinct field layouts can collide). Two tools with the same name but different server id or identity necessarily hash differently.

type Observation

type Observation struct {
	Key         ToolKey
	Class       DriftClass
	Diffs       []FieldDiff
	Eligibility Eligibility
}

Observation is the per-tool outcome of an ingestion: its key, drift class, the deterministic field diffs, and the resulting eligibility.

type PeerObservation added in v1.0.272

type PeerObservation struct {
	// At is when the authenticated observation completed, on the observer's clock.
	At time.Time
	// Identity is the server identity the transport verified for that observation.
	Identity registry.Identity
}

PeerObservation is the bounded evidence that an AUTHENTICATED peer advertised a record.

The ZERO VALUE means NO observation, and it is what every operator-seeded record carries. That is the fail-closed default in the only direction that matters: a record whose evidence was never gathered can never read as observed.

Identity is the identity VERIFIED ON THE OBSERVATION'S TRANSPORT — not a value read out of the MCP payload, which the peer writes and could therefore choose. A tools/list response from a peer whose identity was not verified is not freshness evidence at all, so an observation carrying no identity is refused at the ingest boundary rather than stored and filtered later.

There is deliberately no Source/kind field here. Presence IS the claim: Provenance is derived from Present(), so there is no second value that could disagree with the evidence beside it.

func (PeerObservation) Present added in v1.0.272

func (o PeerObservation) Present() bool

Present reports whether this value carries a usable observation. BOTH halves are required: a timestamp with no verified identity does not say WHO was observed, and an identity with no timestamp does not say WHEN — and freshness is meaningless without both.

type Provenance added in v1.0.272

type Provenance uint8

Provenance records HOW a catalog record's fingerprint came to be known.

It exists because the two ways a record can appear are NOT equally good evidence and were, until this type, indistinguishable. `seedTools` (mcp_inventory.go) re-encodes operator-declared JSON into a synthetic tools/list result and feeds it through the SAME ingest path a real discovery uses, so a seeded record and a genuinely peer-observed one were byte-identical in the catalog. Nothing downstream — `ToolStillCurrent`, the activation preflight, the reviewed binding — could tell "the operator says the peer offers F1" from "an authenticated peer was observed advertising F1" (blocker 11).

The distinction is NOT a caller-supplied flag. It is DERIVED from whether the record carries a PeerObservation, and a PeerObservation can only be attached by the dedicated observed-ingest entrypoint. A caller that wants peer provenance must therefore produce the evidence, not assert the conclusion.

const (
	// OperatorSeeded — the record's fingerprint was computed from operator-declared inventory.
	// It is the ZERO VALUE, and that is deliberate: any record built without an explicit
	// authenticated observation is seeded, so a new construction path cannot default into
	// claiming peer evidence it never gathered.
	OperatorSeeded Provenance = iota
	// PeerObserved — the record's fingerprint was computed from a tools/list result returned by
	// an AUTHENTICATED peer over the supported transport, at PeerObservation.At.
	PeerObserved
)

func (Provenance) String added in v1.0.272

func (p Provenance) String() string

String returns the provenance label used on operator-facing surfaces and in bounded reasons.

type Report

type Report struct {
	ServerID     registry.ServerID
	Observations []Observation
	Revision     uint64
	// Complete reports whether the ingested result was the server's COMPLETE tool set — i.e. it
	// carried no MCP `nextCursor` continuation token.
	//
	// It is surfaced because a caller cannot otherwise tell a whole-server observation from a
	// FIRST PAGE. Discovery fetches one page, so on a paginated server every tool beyond that
	// page receives no peer observation at all, while the call itself succeeds: an operator
	// refreshing to satisfy the First-Canary freshness fact would be told it worked and find the
	// fact still false, with nothing pointing at why (Codex round 5, P2).
	//
	// The withdrawal gate has consulted this value since before it was exported — a tool absent
	// from a PARTIAL page has not been proven withdrawn — so nothing about that behaviour changes
	// here. What changes is that the fact stops being private to this package.
	Complete bool
}

Report is the outcome of a whole discovery ingestion.

type Snapshot

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

Snapshot is an immutable catalog view; its map is never mutated after publication, so any number of readers may use it lock-free while writers publish newer ones (copy-on-write).

func (*Snapshot) Get

func (s *Snapshot) Get(key ToolKey) (ToolRecord, bool)

Get returns a copy of the record for key and whether it is present. The schema trees are DEEP-COPIED so a caller cannot mutate the immutable stored nodes that lock-free readers and later classifications rely on.

func (*Snapshot) Len

func (s *Snapshot) Len() int

Len returns the number of catalog entries.

func (*Snapshot) Records

func (s *Snapshot) Records() []ToolRecord

Records returns copies of all entries in deterministic (server, name) order, with deep-copied schema trees (see Get).

func (*Snapshot) Revision

func (s *Snapshot) Revision() uint64

Revision returns the monotonically increasing snapshot revision.

type ToolKey

type ToolKey struct {
	Server registry.ServerID
	Name   string
}

ToolKey identifies a tool by (server registry id, tool name). Name ALONE is never identity: the same name behind two different server ids is two tools.

type ToolRecord

type ToolRecord struct {
	Key          ToolKey
	Fingerprint  Fingerprint
	InputSchema  *canonical.Node
	OutputSchema *canonical.Node // nil when the tool declares no output schema
	Eligibility  Eligibility
	Revision     uint64
	// Observed is the authenticated peer evidence behind this record, or the zero value when
	// there is none. Provenance() derives operator-seeded vs peer-observed from it; see
	// provenance.go for why the distinction is derived rather than declared.
	//
	// It is carried by VALUE through Promote/Demote/DisableServer, which copy the record and
	// change only Eligibility. That is correct in both directions: those are trust and
	// lifecycle actions, not observations, so they must not MINT evidence — and the peer did
	// advertise this record at that time, so they must not DESTROY it either.
	Observed PeerObservation
}

ToolRecord is one immutable catalog entry: the tool key, its last-known fingerprint, the schema-canonical schema trees (retained for the next diff), its eligibility, and the catalog revision at which it was written. Callers receive copies; records are never mutated in place.

func (ToolRecord) Provenance added in v1.0.272

func (r ToolRecord) Provenance() Provenance

Provenance reports how this record's fingerprint came to be known. It is DERIVED from the observation rather than stored beside it, so it is structurally impossible for a record to claim PeerObserved while carrying no evidence — the shape that would otherwise let a seeded record satisfy a peer-freshness gate.

Jump to

Keyboard shortcuts

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