upstream

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: Apache-2.0 Imports: 21 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

The linter of tool descriptions: a signal for the administrator who pins a tool, not a border (control M2). A description that passes can still be hostile, and a description that is flagged can be pinned on purpose (imperative only).

Two findings exist. tool_reference: the description names a tool of the gateway or of another upstream server, with or without its up.<server>. prefix; this is how a poisoned description steers the model to another tool, and it is never accepted. imperative: the description addresses the model in the imperative.

Description pins of upstream tools: the canonical form of a tool description, its SHA-256, and the ed25519 signature of the administrator over it (decision D6).

A pin says: "this exact description of this tool of this server was read and approved". The description is the object {name, description, inputSchema, outputSchema, annotations} that the upstream sent, written in the canonical form of RFC 8785. Any change to any of those five members changes the hash.

What passes between the agent and a pinned upstream tool: the check of the arguments against the pinned input schema, and the shaping of the result (control M4, TL-04).

Every result reaches the agent with the label {"edigate/taint": "upstream:<server>"} in _meta. For a server with quarantine_results the text of the result is kept in the table upstream_notes and the agent gets references ($up_N) that no tool opens; a structured result passes only if it fits the pinned output schema and holds no free string, that is, no string the schema does not fix by enum, const or format.

Package upstream lets the gateway pass the tools of other MCP servers to the agent without trusting them (flow P8, controls M2 and M4).

Input: the list of servers from the config, the public key of the administrator, and the pins in the table manifests. Output: for the agent, the tools of each server under the name up.<server>.<tool>, only those whose description is pinned and signed; for a call, the result of the upstream with the label {"edigate/taint": "upstream:<server>"} in _meta.

Every tools/list of the agent and every call reads tools/list of the upstream again and compares the SHA-256 of each description (canonical, RFC 8785) with its pin. No pin, a signature that does not verify, or another hash: the tool is switched off (not listed, a call answers manifest_drift) and the event is audited with both hashes. A server that does not answer lists nothing.

The gateway calls only the addresses of the config, never follows a redirect, and sends to an upstream only the header the config names. The token of the client of the gateway is never passed on: the upstream client is built from the config alone.

Index

Constants

View Source
const (
	ToolReference = "tool_reference"
	Imperative    = "imperative"
)

Finding kinds.

View Source
const (
	StateOK           = "ok"
	StateNoPin        = "no_pin"
	StateBadSignature = "bad_signature"
	StateChanged      = "changed"
)

States of a tool against its pin.

View Source
const Prefix = "up."

Prefix is put before every upstream tool name; the gateway chooses it, the server cannot.

View Source
const TaintKey = "edigate/taint"

TaintKey is the key in _meta of a result that came from an upstream.

Variables

This section is empty.

Functions

func CheckAll

func CheckAll(servers []Server) error

CheckAll validates the whole list: every entry and no repeated name.

func FetchTools

func FetchTools(ctx context.Context, srv Server, secret string) ([]*mcp.Tool, error)

FetchTools reads the live tool list of a server straight from the config; edigatectl uses it to pin. secret is the value of the auth header ("" when the server has none).

func GenerateKey

func GenerateKey() (pub, priv string, err error)

GenerateKey makes a new key pair and returns both halves in base64.

func HasKind

func HasKind(findings []Finding, kind string) bool

HasKind reports whether the findings hold one of the kind.

func Hash

func Hash(t *mcp.Tool) ([32]byte, error)

Hash returns the SHA-256 of the canonical description of a tool.

func ParsePrivateKey

func ParsePrivateKey(b64 string) (ed25519.PrivateKey, error)

ParsePrivateKey reads the base64 form of a private key: 64 bytes, or a 32 byte seed.

func ParsePublicKey

func ParsePublicKey(b64 string) (ed25519.PublicKey, error)

ParsePublicKey reads the base64 form of a public key (EDIGATE_MANIFEST_PUBKEY).

func Shape

func Shape(ctx context.Context, notes NoteSaver, actor Actor, t Tool, raw *mcp.CallToolResult) (*mcp.CallToolResult, [32]byte, error)

Shape turns the result of the upstream into the result for the agent and returns the SHA-256 of the result as the upstream sent it (for the audit row).

func Sign

func Sign(priv ed25519.PrivateKey, server string, hash [32]byte) []byte

Sign signs the pin of a tool of a server.

func SplitName

func SplitName(public string) (server, tool string, ok bool)

SplitName splits up.<server>.<tool> into server and tool. The tool name may hold dots.

func TaintLabel

func TaintLabel(server string) string

TaintLabel is the value under TaintKey for a server.

func Verify

func Verify(pub ed25519.PublicKey, server string, hash [32]byte, sig []byte) bool

Verify reports whether sig is the signature of the key owner over the pin.

Types

type Actor

type Actor struct {
	TenantID    string
	PrincipalID string
	TraceID     string
}

Actor is who triggered a read of the upstream; the audit rows carry it.

type AuthHeader

type AuthHeader struct {
	Name string `yaml:"name"`
	Env  string `yaml:"env"`
}

AuthHeader names a header the gateway sends to an upstream and the environment variable that holds its value. The value is not in the config file.

type Finding

type Finding struct {
	Kind   string `json:"kind"`
	Detail string `json:"detail"` // the name or the phrase that was found
}

Finding is one result of the linter.

func Lint

func Lint(description string, names []string) []Finding

Lint checks a description. names are the tool names it must not mention: those of the gateway and of the other upstream servers (bare, or with the up.<server>. prefix). Findings come in a fixed order: tool references by name, then phrases, then tags.

type Gateway

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

Gateway reads and calls the configured upstream servers.

func New

func New(servers []Server, pubKeyB64 string, st *store.Store, log *slog.Logger, getenv func(string) string) (*Gateway, error)

New builds the gateway. getenv reads the secrets named by auth_header.env. Without the public key no description can be verified, so the servers are switched off (a warning says so): nothing of an upstream reaches the agent. A key that is not a key, or a missing secret, is refused.

func (*Gateway) Call

func (g *Gateway) Call(ctx context.Context, t Tool, args json.RawMessage) (*mcp.CallToolResult, error)

Call runs the tool at the upstream and returns the result as it came.

func (*Gateway) Inspect

func (g *Gateway) Inspect(ctx context.Context, srv Server) ([]Tool, error)

Inspect reads tools/list of one server and compares each description with its pin.

func (*Gateway) Refresh

func (g *Gateway) Refresh(ctx context.Context, actor *Actor) []Tool

Refresh reads every server and returns all their tools with the verdict on each pin. A tool that is not ok is reported (audited when the actor is known, logged otherwise). A server that does not answer is skipped.

func (*Gateway) Resolve

func (g *Gateway) Resolve(ctx context.Context, publicName string, actor Actor) (Tool, error)

Resolve finds the upstream tool behind a name the agent used and checks its pin now. A server that is not in the config is forbidden, a tool the server does not have is not_found, and a tool that is not ok is manifest_drift.

func (*Gateway) Servers

func (g *Gateway) Servers() []Server

Servers returns the configured servers in the order of the config.

type NoteSaver

type NoteSaver interface {
	SaveUpstreamNote(ctx context.Context, tenantID, server, tool, traceID, body, label string) (int64, error)
}

NoteSaver keeps the text of a quarantined result.

type Server

type Server struct {
	Name              string      `yaml:"name"`
	URL               string      `yaml:"url"`
	AuthHeader        *AuthHeader `yaml:"auth_header"`
	QuarantineResults bool        `yaml:"quarantine_results"`
}

Server is one allowed upstream server.

func (Server) Check

func (s Server) Check() error

Check validates one entry of the config.

type Tool

type Tool struct {
	Server string
	Live   *mcp.Tool
	Hash   [32]byte
	Pin    *store.Manifest // nil: no pin
	State  string

	Quarantine bool // the server has quarantine_results
}

Tool is one tool as the upstream describes it now, with the verdict on its pin.

func (Tool) Enabled

func (t Tool) Enabled() bool

Enabled reports whether the agent may see and call the tool.

func (Tool) Public

func (t Tool) Public() *mcp.Tool

Public is the tool as the agent sees it: the prefixed name and the five members that the pin covers, nothing else of what the upstream sent.

For a server with quarantine_results the output schema is not shown: a structured result may be dropped (see Shape), and a client that expects one by the schema would fail.

func (Tool) PublicName

func (t Tool) PublicName() string

PublicName is the name the agent sees.

func (Tool) ValidateInput

func (t Tool) ValidateInput(args []byte) error

ValidateInput checks the arguments against the input schema that was pinned. Empty arguments count as an empty object.

Jump to

Keyboard shortcuts

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