Documentation
¶
Overview ¶
Package pinning keeps MCP servers from changing their tools behind the user's back.
A tool's definition — its description above all — is read by the model as instructions. A server that was harmless when it was installed can start sending a different description later (a "rug pull"), and one that ships a poisoned description from the start can hide instructions in it that the user never sees. This package pins every tool definition in a lockfile the first time it is seen, reports any later change as drift, and scans definitions for the tricks poisoned ones use.
Index ¶
- Constants
- func Reveal(s string) string
- func StripInvisible(s string) (string, int)
- type Definition
- type Drift
- type Finding
- type Lockfile
- func (l *Lockfile) Check(upstream string, defs []Definition, others []OtherTool) []Report
- func (l *Lockfile) Known(upstream string) bool
- func (l *Lockfile) NoteDrift(r Report, now time.Time) bool
- func (l *Lockfile) Path() string
- func (l *Lockfile) Pin(upstream string, d Definition, accepted []string, now time.Time)
- func (l *Lockfile) Pinned(upstream, tool string) *Pin
- func (l *Lockfile) Save() error
- func (l *Lockfile) Trust(r Report, now time.Time)
- func (l *Lockfile) Unpin(upstream, tool string)
- type OtherTool
- type Pin
- type Report
- type Status
- type Upstream
Constants ¶
const ( KindInvisible = "invisible" KindInstruction = "instruction" KindCredentials = "credentials" KindShadowing = "shadowing" )
Finding kinds.
Variables ¶
This section is empty.
Functions ¶
func Reveal ¶
Reveal renders what a text hides: tag characters are spelled out in «hidden: …», and every other invisible or reordering character is shown as its code point. What is left is exactly what the model reads.
func StripInvisible ¶
StripInvisible removes every character that renders as nothing or reorders what is rendered, and reports how many it removed.
Types ¶
type Definition ¶
type Definition struct {
Name string `json:"name"`
Title string `json:"title,omitempty"`
Description string `json:"description,omitempty"`
InputSchema json.RawMessage `json:"inputSchema,omitempty"`
OutputSchema json.RawMessage `json:"outputSchema,omitempty"`
Annotations json.RawMessage `json:"annotations,omitempty"`
}
Definition is the part of a tool that is pinned: everything the model reads and everything that decides how the tool is called. _meta and icons are left out; they are not shown to the model.
func DefinitionFromJSON ¶
func DefinitionFromJSON(raw []byte) (Definition, error)
DefinitionFromJSON extracts a Definition from a tool as it travels on the wire.
type Drift ¶
type Drift struct {
Hash string `json:"hash"`
SeenAt time.Time `json:"seen_at"`
Definition Definition `json:"definition"`
}
Drift is a definition that differs from the pinned one.
type Finding ¶
type Finding struct {
// Kind is invisible, instruction, credentials or shadowing.
Kind string `json:"kind"`
// Where is the part of the definition it was found in: description,
// title, or a path into a schema ("inputSchema.properties.note.description").
Where string `json:"where"`
// Detail says what was found, in words.
Detail string `json:"detail"`
// Excerpt is the text in question. For hidden characters it is what they
// spell out, which is usually the whole point of hiding them.
Excerpt string `json:"excerpt,omitempty"`
}
Finding is one suspicious thing in a tool definition.
func Scan ¶
func Scan(d Definition, others []OtherTool) []Finding
Scan looks through a definition for the marks of a poisoned tool: text the user cannot see, instructions addressed to the model rather than a description of the tool, pointers at credentials, and talk about other servers' tools.
func ScanResult ¶
ScanResult looks through what a tool returned for text aimed at the model rather than the user: hidden characters and instructions. Pointers at credentials are left out here; a result that mentions .env files is usually just a result about .env files.
type Lockfile ¶
type Lockfile struct {
Version int `json:"version"`
Upstreams map[string]*Upstream `json:"upstreams"`
// contains filtered or unexported fields
}
Lockfile is the record of every tool definition a human has trusted, grouped by upstream.
func (*Lockfile) Check ¶
func (l *Lockfile) Check(upstream string, defs []Definition, others []OtherTool) []Report
Check compares the tools an upstream offers with what is pinned, and scans each current definition. others are the tools of every other upstream, which a definition should have no reason to talk about.
func (*Lockfile) NoteDrift ¶
NoteDrift records that a tool changed, once per new definition. It reports whether this drift is news.
func (*Lockfile) Pin ¶
Pin trusts a definition: it becomes the pinned one, any drift is cleared, and the given findings are recorded as accepted.
type Pin ¶
type Pin struct {
Hash string `json:"hash"`
PinnedAt time.Time `json:"pinned_at"`
Definition Definition `json:"definition"`
// Accepted lists the scan findings a human looked at and accepted for
// this exact definition.
Accepted []string `json:"accepted_findings,omitempty"`
// Drift is set when the server started offering something else under
// this name. It stays until a human pins the tool again.
Drift *Drift `json:"drift,omitempty"`
}
Pin is one tool as it was trusted.
type Report ¶
type Report struct {
Upstream string `json:"upstream"`
Tool string `json:"tool"`
Status Status `json:"status"`
Current Definition `json:"current"`
// Pinned is the trusted definition, for changed and removed tools.
Pinned *Definition `json:"pinned,omitempty"`
// Findings are what the scan found in the current definition, minus the
// ones a human already accepted for it.
Findings []Finding `json:"findings,omitempty"`
// Accepted are the findings a human accepted for this definition.
Accepted []Finding `json:"accepted,omitempty"`
}
Report is the verdict on one tool.
type Status ¶
type Status string
Status is how a tool on offer relates to the lockfile.
const ( // StatusPinned means the tool is exactly what was trusted. StatusPinned Status = "pinned" // StatusNew means the upstream is pinned, but this tool is not. StatusNew Status = "new" // StatusChanged means the definition differs from the pinned one. StatusChanged Status = "changed" // StatusRemoved means the tool is pinned but no longer offered. StatusRemoved Status = "removed" // StatusUnpinned means nothing about this upstream is pinned yet. StatusUnpinned Status = "unpinned" )