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
- func CheckAll(servers []Server) error
- func FetchTools(ctx context.Context, srv Server, secret string) ([]*mcp.Tool, error)
- func GenerateKey() (pub, priv string, err error)
- func HasKind(findings []Finding, kind string) bool
- func Hash(t *mcp.Tool) ([32]byte, error)
- func ParsePrivateKey(b64 string) (ed25519.PrivateKey, error)
- func ParsePublicKey(b64 string) (ed25519.PublicKey, error)
- func Shape(ctx context.Context, notes NoteSaver, actor Actor, t Tool, ...) (*mcp.CallToolResult, [32]byte, error)
- func Sign(priv ed25519.PrivateKey, server string, hash [32]byte) []byte
- func SplitName(public string) (server, tool string, ok bool)
- func TaintLabel(server string) string
- func Verify(pub ed25519.PublicKey, server string, hash [32]byte, sig []byte) bool
- type Actor
- type AuthHeader
- type Finding
- type Gateway
- func (g *Gateway) Call(ctx context.Context, t Tool, args json.RawMessage) (*mcp.CallToolResult, error)
- func (g *Gateway) Inspect(ctx context.Context, srv Server) ([]Tool, error)
- func (g *Gateway) Refresh(ctx context.Context, actor *Actor) []Tool
- func (g *Gateway) Resolve(ctx context.Context, publicName string, actor Actor) (Tool, error)
- func (g *Gateway) Servers() []Server
- type NoteSaver
- type Server
- type Tool
Constants ¶
const ( ToolReference = "tool_reference" Imperative = "imperative" )
Finding kinds.
const ( StateOK = "ok" StateNoPin = "no_pin" StateBadSignature = "bad_signature" StateChanged = "changed" )
States of a tool against its pin.
const Prefix = "up."
Prefix is put before every upstream tool name; the gateway chooses it, the server cannot.
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 FetchTools ¶
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 ¶
GenerateKey makes a new key pair and returns both halves in base64.
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 ¶
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 ¶
SplitName splits up.<server>.<tool> into server and tool. The tool name may hold dots.
func TaintLabel ¶
TaintLabel is the value under TaintKey for a server.
Types ¶
type AuthHeader ¶
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.
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 ¶
Inspect reads tools/list of one server and compares each description with its pin.
func (*Gateway) Refresh ¶
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.
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.
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) Public ¶
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) ValidateInput ¶
ValidateInput checks the arguments against the input schema that was pinned. Empty arguments count as an empty object.