edge

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: Apache-2.0 Imports: 18 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 edge is the gate in front of the gateway's two HTTP entrances: /mcp for agents and /edi/inbound for partners (the second is in internal/inbound).

Input: every HTTP request to either entrance. Output: either an error response in the gateway's single format (internal/rpcerr) or the request passed on with the caller's identity attached.

Gate holds what both entrances share: the bucket per client address (spent only by failed token checks), the bearer token -> principal step (tenant and kind come only from the database) and the buckets per principal and per partner. The /mcp handler (Gate.MCP) adds, in this order, all before the SDK sees the request:

  1. only kind "agent" may use /mcp
  2. bucket per principal
  3. body size, single JSON-RPC object, Mcp-Method / Mcp-Name against the body

Every request gets a trace id (header Edigate-Trace-Id). The identity reaches tool handlers as the SDK's RequestExtra.TokenInfo; see Identity.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Caller

type Caller struct {
	Principal store.Principal
	TraceID   string
}

Caller is an authenticated principal and the trace id of the request.

type Gate

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

Gate is the part of the edge that /mcp and /edi/inbound share.

func NewGate

func NewGate(ctx context.Context, finder PrincipalFinder, log *slog.Logger) *Gate

NewGate builds the gate. The sweep of old buckets stops when ctx ends.

func (*Gate) AllowPartner

func (g *Gate) AllowPartner(tenantID, partnerID string) bool

AllowPartner takes one token from the bucket of a partner (2 interchanges per second, burst 2) and reports whether there was one.

func (*Gate) Authenticate

func (g *Gate) Authenticate(w http.ResponseWriter, r *http.Request) (Caller, bool)

Authenticate runs the steps both entrances share: sets the trace id header, checks the bucket of the client address and resolves the bearer token. On failure it writes the error response and returns false.

func (*Gate) MCP

func (g *Gate) MCP(next http.Handler) *Handler

MCP wraps the SDK handler with the /mcp checks.

func (*Gate) Reject

func (g *Gate) Reject(w http.ResponseWriter, trace, principal string, reason rpcerr.Reason, id json.RawMessage)

Reject logs and writes an error in the gateway's single format.

func (*Gate) RejectTooLarge

func (g *Gate) RejectTooLarge(w http.ResponseWriter, trace, principal string)

RejectTooLarge answers a body over the limit: HTTP 413 and schema_invalid.

type Handler

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

Handler is the /mcp middleware.

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Identity

type Identity struct {
	PrincipalID string
	TenantID    string
	Kind        string
	TraceID     string
}

Identity is who is calling and under which trace id.

func IdentityFrom

func IdentityFrom(ti *auth.TokenInfo) (Identity, bool)

IdentityFrom reads the identity the edge put into the SDK's TokenInfo.

type PrincipalFinder

type PrincipalFinder interface {
	FindPrincipal(ctx context.Context, tokenSHA256 []byte) (store.Principal, error)
}

PrincipalFinder looks a principal up by token hash. It returns store.ErrNotFound for unknown and revoked tokens.

type TransportLog

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

TransportLog writes one JSON line for every request that goes through it (EDIGATE_TRANSPORT_LOG, protocol item O3): the time, the trace id, the MCP method, the tool, the body of the request and the body of the answer. It is for the stand only: the bodies hold the data of the benchmark, which is synthetic. It wraps the /mcp handler from outside, so a request that the edge refuses is in the log too.

func OpenTransportLog

func OpenTransportLog(path string) (*TransportLog, error)

OpenTransportLog opens (and creates) the file in append mode.

func (*TransportLog) Close

func (l *TransportLog) Close() error

Close closes the file.

func (*TransportLog) Wrap

func (l *TransportLog) Wrap(next http.Handler) http.Handler

Wrap returns a handler that logs the requests it passes on to next.

Jump to

Keyboard shortcuts

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