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
- type ApprovalRequest
- type Approver
- type ChainApprover
- type DenyApprover
- type Event
- type Inbox
- type Options
- type PendingApproval
- 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) Tools() []ToolBinding
- func (p *Proxy) Unfreeze() error
- type TTYApprover
- type ToolBinding
Constants ¶
This section is empty.
Variables ¶
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) (policy.Decision, 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) (policy.Decision, error)
Approve asks each approver in order.
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) (policy.Decision, 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 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 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 (*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.
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) Tools ¶
func (p *Proxy) Tools() []ToolBinding
Tools returns the current catalog, sorted by exposed name.
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) (policy.Decision, error)
Approve prints the call and waits for y or n.
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.