gateway

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package gateway is the MCP gateway core. It terminates streamable-HTTP on the front, runs every message through the inspection pipeline, then routes to one or more backends (aggregating with tool prefixes when several).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Gateway

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

Gateway is the shared front for all sessions.

func New

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

New builds a Gateway.

func (*Gateway) Close

func (g *Gateway) Close()

Close terminates all sessions.

func (*Gateway) Handler

func (g *Gateway) Handler() http.Handler

Handler returns the streamable-HTTP front: POST = one JSON-RPC message, GET = SSE stream of server-initiated messages, DELETE = end session.

type HeldCall

type HeldCall struct {
	Session string
	User    string
	Backend string
	Tool    string
	Args    []byte
	Rule    string
}

HeldCall describes one parked tool call.

type HeldStore

type HeldStore interface {
	// Hold parks a call and returns a resolution channel. The channel
	// yields true (approved) or false (rejected) exactly once.
	Hold(ctx context.Context, h HeldCall) (id string, resolved <-chan bool, err error)
}

HeldStore parks messages awaiting human approval.

type IdentityResolver

type IdentityResolver func(r *http.Request) (inspect.Identity, error)

IdentityResolver authenticates an HTTP request (inbound auth). It returns the caller identity or an error that terminates the request. The gateway stays auth-agnostic: the daemon (or hoop) supplies the resolver.

type Observer

type Observer interface {
	ObserveMessage(dir inspect.Direction, backendName, method, tool, decision string, dur time.Duration)
}

Observer is the telemetry seam: one call per gateway-processed message.

type Options

type Options struct {
	// Backends: name → factory. Names are tool prefixes in aggregation.
	Backends map[string]backend.Factory
	// Pipeline is the ordered check chain applied to every message.
	Pipeline []inspect.Check
	// Resolver authenticates requests. nil = anonymous.
	Resolver IdentityResolver
	// Sink receives audit events. nil = discard.
	Sink audit.Sink
	// SessionIdleTimeout reaps sessions with no traffic. 0 = 30m.
	SessionIdleTimeout time.Duration
	// RequestTimeout bounds one round-trip to a backend. 0 = 5m, since
	// slow tool calls are normal. Approvals hold longer via ctx.
	RequestTimeout time.Duration
	// Held is the approval parking lot; nil disables Hold verdicts
	// (they become Deny).
	Held HeldStore
	// Observer receives per-message timing/decision telemetry. Optional.
	Observer Observer
	Logger   *slog.Logger
}

Options assemble a Gateway.

Jump to

Keyboard shortcuts

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