core

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2026 License: MIT Imports: 9 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"
	EventToolForbidden = "tool_forbidden"
	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.2"

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 toolhost__* control plane, which is dropped; everything else is namespaced backend__tool.

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

type SkippedTool struct {
	Backend string
	Tool    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"`
}

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.

Jump to

Keyboard shortcuts

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