proxy

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2026 License: GPL-3.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

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

Constants

This section is empty.

Variables

View Source
var Version = "dev"

Version is stamped into the implementation agentgate advertises. It is overridden from main at build time.

Functions

This section is empty.

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 ChainApprover

type ChainApprover []Approver

ChainApprover tries each approver in turn and uses the first that can answer.

func (ChainApprover) Approve

func (c ChainApprover) Approve(ctx context.Context, req ApprovalRequest) (Verdict, error)

Approve asks each approver in order.

type Choice added in v0.3.0

type Choice string

Choice is what a person clicked.

const (
	// ChoiceAllow lets this one call through.
	ChoiceAllow Choice = "allow"
	// ChoiceAllowSession lets this call and every later call of the same tool
	// in the same session through.
	ChoiceAllowSession Choice = "allow-session"
	// ChoiceDeny rejects the call.
	ChoiceDeny Choice = "deny"
)

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

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 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 NewInbox

func NewInbox() *Inbox

NewInbox returns an empty approval inbox.

func (*Inbox) Approve

func (i *Inbox) Approve(ctx context.Context, req ApprovalRequest) (Verdict, error)

Approve parks the call until someone answers in the UI or ctx expires.

func (*Inbox) Pending

func (i *Inbox) Pending() []PendingApproval

Pending lists the waiting approvals, oldest first.

func (*Inbox) Resolve

func (i *Inbox) Resolve(id string, choice Choice, who string) bool

Resolve answers a pending approval. It reports false when the id is unknown, which happens when the call already timed out.

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
}

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 Proxy

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

Proxy fronts one or more upstream MCP servers.

func New

func New(opts Options) (*Proxy, error)

New builds a proxy. Call Connect before serving.

func (*Proxy) Close

func (p *Proxy) Close() error

Close ends every downstream session and closes every upstream.

func (*Proxy) Config

func (p *Proxy) Config() *config.Config

Config returns the configuration currently in force.

func (*Proxy) Connect

func (p *Proxy) Connect(ctx context.Context) error

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

func (p *Proxy) Freeze(reason, by string) error

Freeze throws the kill switch: every call, in every session, on every gateway that shares this config, is denied until Unfreeze.

func (*Proxy) Frozen

func (p *Proxy) Frozen() bool

Frozen reports whether the kill switch is thrown.

func (*Proxy) HTTPHandler

func (p *Proxy) HTTPHandler() http.Handler

HTTPHandler serves the Streamable HTTP transport for downstream hosts.

func (*Proxy) Lookup

func (p *Proxy) Lookup(exposed string) (ToolBinding, bool)

Lookup resolves an exposed tool name to its binding.

func (*Proxy) Refresh

func (p *Proxy) Refresh(ctx context.Context) error

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

func (p *Proxy) RunStdio(ctx context.Context) error

RunStdio serves a single downstream connection on stdin/stdout and returns when the host disconnects or ctx is cancelled.

func (*Proxy) Server

func (p *Proxy) Server() *mcp.Server

Server exposes the downstream MCP server, for tests and for the HTTP handler.

func (*Proxy) SetPolicy

func (p *Proxy) SetPolicy(pol *policy.Policy)

SetPolicy swaps the policy in place, for hot reload from the web UI or a SIGHUP. Upstream connections are untouched.

func (*Proxy) Tools

func (p *Proxy) Tools() []ToolBinding

Tools returns the current catalog, sorted by exposed name.

func (*Proxy) Unfreeze

func (p *Proxy) Unfreeze() error

Unfreeze lifts the kill switch.

type TTYApprover

type TTYApprover struct {
	In  io.Reader
	Out io.Writer
	// contains filtered or unexported fields
}

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 Verdict added in v0.3.0

type Verdict struct {
	policy.Decision
	Session bool
}

Verdict is an approver's answer. Session is set when the human chose to allow the tool for the rest of the session, so that the same question is not asked again a minute later.

Jump to

Keyboard shortcuts

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