Documentation
¶
Overview ¶
Package proxy is the MCP passthrough: it terminates the connection from the host (downstream), keeps connections to the real MCP servers (upstream), and puts the policy evaluator and the audit log in between.
Everything that is not a tools/call is forwarded unchanged. tools/call is the only place agentgate has an opinion.
Index ¶
- Variables
- func AnnotationsFromCatalog(raw []byte) (map[string]policy.Annotations, error)
- type ApprovalRequest
- type Approver
- type Choice
- type DenyApprover
- type Event
- type FanoutApprover
- type Inbox
- type NtfyApprover
- type Options
- type PendingApproval
- type PinningMode
- type Proxy
- func (p *Proxy) Close() error
- func (p *Proxy) Config() *config.Config
- func (p *Proxy) Connect(ctx context.Context) error
- func (p *Proxy) Forward(ctx context.Context, exposed string, args json.RawMessage) (*mcp.CallToolResult, error)
- func (p *Proxy) ForwardJSON(ctx context.Context, exposed string, args json.RawMessage) (json.RawMessage, error)
- func (p *Proxy) Freeze(reason, by string) error
- func (p *Proxy) Frozen() bool
- func (p *Proxy) HTTPHandler() http.Handler
- func (p *Proxy) Lookup(exposed string) (ToolBinding, bool)
- func (p *Proxy) Refresh(ctx context.Context) error
- func (p *Proxy) RunStdio(ctx context.Context) error
- func (p *Proxy) Server() *mcp.Server
- func (p *Proxy) SetPolicy(pol *policy.Policy)
- func (p *Proxy) ToolReports() []ToolReport
- func (p *Proxy) Tools() []ToolBinding
- func (p *Proxy) Trust(ctx context.Context, tool string) ([]ToolReport, error)
- func (p *Proxy) Unfreeze() error
- type TTYApprover
- type ToolBinding
- type ToolReport
- type Verdict
Constants ¶
This section is empty.
Variables ¶
var ErrNoSuchTool = errors.New("no such tool")
ErrNoSuchTool is returned by Trust for a tool the last refresh did not see.
var Version = "dev"
Version is stamped into the implementation agentgate advertises. It is overridden from main at build time.
Functions ¶
func AnnotationsFromCatalog ¶ added in v0.4.0
func AnnotationsFromCatalog(raw []byte) (map[string]policy.Annotations, error)
AnnotationsFromCatalog reads a catalog snapshot from the audit log and returns each tool's annotations the way a live call would have seen them, keyed by exposed name. Replay uses it to evaluate annotations.* conditions.
Types ¶
type ApprovalRequest ¶
type ApprovalRequest struct {
SessionID string `json:"session_id"`
Upstream string `json:"upstream"`
Tool string `json:"tool"`
ToolName string `json:"tool_name"`
Args json.RawMessage `json:"args,omitempty"`
Decision policy.Decision `json:"decision"`
Timeout time.Duration `json:"-"`
}
ApprovalRequest describes a call that a rule marked "ask".
type Approver ¶
type Approver interface {
Approve(ctx context.Context, req ApprovalRequest) (Verdict, error)
}
Approver turns an "ask" into an allow or a deny. An error means the question could not be put to anyone, and the call is denied with that reason.
type DenyApprover ¶
type DenyApprover struct {
// Reason overrides the default explanation.
Reason string
}
DenyApprover is the fallback when no one can be asked.
func (DenyApprover) Approve ¶
func (d DenyApprover) Approve(context.Context, ApprovalRequest) (Verdict, error)
Approve always denies.
type Event ¶
type Event struct {
Event string `json:"event"`
At time.Time `json:"at"`
SessionID string `json:"session_id,omitempty"`
Host string `json:"host,omitempty"`
Upstream string `json:"upstream,omitempty"`
Tool string `json:"tool,omitempty"`
Decision policy.Decision `json:"decision"`
Args json.RawMessage `json:"args,omitempty"`
Shadow bool `json:"shadow,omitempty"`
Message string `json:"message"`
}
Event is what a webhook receives. It is also what the log line says, so a Slack message and a grep of the log tell the same story.
type FanoutApprover ¶ added in v0.4.0
type FanoutApprover []Approver
FanoutApprover puts the question to every channel at once — the web UI, the terminal, the phone — and takes the first answer; the other channels are withdrawn. A channel that cannot ask at all (an error) is skipped.
func (FanoutApprover) Approve ¶ added in v0.4.0
func (f FanoutApprover) Approve(ctx context.Context, req ApprovalRequest) (Verdict, error)
Approve asks everyone and returns the first answer.
type Inbox ¶
type Inbox struct {
// contains filtered or unexported fields
}
Inbox is the queue of pending approvals the web UI shows. It is also an Approver, so "ask" in a run with --ui waits for a click instead of a keystroke.
func (*Inbox) Pending ¶
func (i *Inbox) Pending() []PendingApproval
Pending lists the waiting approvals, oldest first.
type NtfyApprover ¶ added in v0.4.0
type NtfyApprover struct {
// Server is the ntfy base URL, "https://ntfy.sh" or your own.
Server string
// Topic is where questions are published. On a public server the topic
// name is the password: make it long and random.
Topic string
// Token is an access token for servers with access control.
Token string
// Redact scrubs the arguments before they leave the machine.
Redact func([]byte) []byte
Client *http.Client
Log *slog.Logger
// contains filtered or unexported fields
}
NtfyApprover puts a question on your phone. It publishes the pending call to an ntfy topic with Allow / Allow for session / Deny buttons; a button posts its answer to a second topic, <topic>-answers, which the approver reads over a long-lived subscription. Nothing listens on a port, so it works from a laptop behind any NAT, and the answer carries a one-time nonce, so it cannot be replayed or guessed.
func (*NtfyApprover) Approve ¶ added in v0.4.0
func (n *NtfyApprover) Approve(ctx context.Context, req ApprovalRequest) (Verdict, error)
Approve publishes the question and waits for a button, or ctx.
func (*NtfyApprover) Run ¶ added in v0.4.0
func (n *NtfyApprover) Run(ctx context.Context)
Run keeps the subscription to the answers topic open until ctx ends, reconnecting with backoff when the connection drops.
type Options ¶
type Options struct {
Config *config.Config
Store *audit.Store
// Redactor scrubs arguments and results that leave the process through a
// webhook, and results that reach the agent when redact_results is on.
Redactor *audit.Redactor
Logger *slog.Logger
// Approver decides "ask" calls. When nil, ask falls back to deny.
Approver Approver
// DownstreamTransport is recorded with the session ("stdio" or "http").
DownstreamTransport string
// Pinning says what the proxy may do with the lockfile. The zero value
// follows the config.
Pinning PinningMode
// Telemetry receives a span for every call. Nil exports nothing.
Telemetry *telemetry.Exporter
}
Options configure a Proxy.
type PendingApproval ¶
type PendingApproval struct {
ID string
Request ApprovalRequest
CreatedAt time.Time
Expires time.Time
}
PendingApproval is the read-only view the UI renders.
type PinningMode ¶ added in v0.4.0
type PinningMode int
PinningMode says what the proxy may do with the lockfile.
const ( // PinningLive follows the config: tools are pinned on first sight, // drift is recorded and reported, and tools are held back as configured. PinningLive PinningMode = iota // PinningInspect compares and reports but never writes the lockfile and // never holds a tool back. `agentgate lock` and replay use it. PinningInspect )
type Proxy ¶
type Proxy struct {
// contains filtered or unexported fields
}
Proxy fronts one or more upstream MCP servers.
func (*Proxy) Connect ¶
Connect dials every upstream and builds the merged catalog. Upstreams that fail to connect are reported but do not stop the others: a broken server should not take the whole gateway down.
func (*Proxy) Forward ¶
func (p *Proxy) Forward(ctx context.Context, exposed string, args json.RawMessage) (*mcp.CallToolResult, error)
Forward sends a tools/call to the upstream that owns the tool, without consulting the policy. It exists for "agentgate replay", which evaluates the policy itself so that it can report what changed.
func (*Proxy) ForwardJSON ¶
func (p *Proxy) ForwardJSON(ctx context.Context, exposed string, args json.RawMessage) (json.RawMessage, error)
ForwardJSON is Forward with the result marshalled, which is the shape the replay package needs.
func (*Proxy) Freeze ¶
Freeze throws the kill switch: every call, in every session, on every gateway that shares this config, is denied until Unfreeze.
func (*Proxy) HTTPHandler ¶
HTTPHandler serves the Streamable HTTP transport for downstream hosts. Sessions idle for half a day are closed: a host that went away without saying so, and the throwaway session a server/discover runs on, would otherwise stay open for as long as the process runs.
func (*Proxy) Lookup ¶
func (p *Proxy) Lookup(exposed string) (ToolBinding, bool)
Lookup resolves an exposed tool name to its binding.
func (*Proxy) Refresh ¶
Refresh rebuilds the merged catalog from every reachable upstream and registers it on the downstream server. Adding and removing features on the server is what makes the SDK emit the matching list_changed notifications.
func (*Proxy) RunStdio ¶
RunStdio serves a single downstream connection on stdin/stdout and returns when the host disconnects or ctx is cancelled.
func (*Proxy) Server ¶
Server exposes the downstream MCP server, for tests and for the HTTP handler.
func (*Proxy) SetPolicy ¶
SetPolicy swaps the policy in place, for hot reload from the web UI or a SIGHUP. Upstream connections are untouched.
func (*Proxy) ToolReports ¶ added in v0.4.0
func (p *Proxy) ToolReports() []ToolReport
ToolReports returns every tool's standing with the lockfile and the scan, as of the last refresh.
func (*Proxy) Tools ¶
func (p *Proxy) Tools() []ToolBinding
Tools returns the current catalog, sorted by exposed name.
func (*Proxy) Trust ¶ added in v0.4.0
Trust pins a tool as it is offered now, accepting whatever the scan found in it, writes the lockfile and refreshes the catalog so a tool that was held back reaches the host. tool is "upstream.tool" or the exposed name; "*" trusts everything that is not already pinned and clean.
type TTYApprover ¶
TTYApprover asks on agentgate's own terminal. In stdio mode stdin and stdout belong to the MCP conversation, so this only works when agentgate is run with --http, or when a separate terminal is wired up.
func NewTTYApprover ¶
func NewTTYApprover() *TTYApprover
NewTTYApprover returns an approver bound to the controlling terminal, or nil when there is none. In stdio mode /dev/tty is used so that the prompt does not land in the MCP stream.
func (*TTYApprover) Approve ¶
func (t *TTYApprover) Approve(ctx context.Context, req ApprovalRequest) (Verdict, error)
Approve prints the call and waits for y, n, or a (allow for the session).
type ToolBinding ¶
type ToolBinding struct {
// Exposed is the name the host sees, prefix included.
Exposed string
// Name is the name the upstream server uses.
Name string
// Upstream is the configured upstream name.
Upstream string
// Annotations are the server's hints about the tool, for annotations.*
// conditions.
Annotations policy.Annotations
}
ToolBinding maps an exposed tool name back to its upstream.
type ToolReport ¶ added in v0.4.0
type ToolReport struct {
pinning.Report
// Exposed is the name the host sees; empty for a tool that was removed.
Exposed string `json:"exposed,omitempty"`
// PinnedNow is set when the tool was pinned on this sight, on first use.
PinnedNow bool `json:"pinned_now,omitempty"`
// Quarantined is set when the tool is hidden from the host. Reason says
// why it is, or why it would be when the proxy only inspects.
Quarantined bool `json:"quarantined,omitempty"`
Reason string `json:"reason,omitempty"`
}
ToolReport is a tool's standing with the lockfile and the definition scan.