remotemcp

package
v0.6.12 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: MIT Imports: 25 Imported by: 0

Documentation

Overview

Package remotemcp serves the AerolVM MCP tools over Streamable HTTP at /mcp on sandboxd (plans/mcp-server-and-agent-cli.md §5.7, Phase 2b). It is off unless SB_MCP_ENABLED=true, authenticates with the API's bearer token, and is pinned-only: every request names one sandbox in ?sandbox=.

The endpoint is stateless (no Mcp-Session-Id), so any node can serve any request behind any load balancer and nothing touches cluster state. Each request builds an agentmcp server whose tools reach the API in-process as the caller: the Access /mcp authenticated is handed to every inner call (handoff.go), and the caller's own token rides along for forwards (see inProcessTransport). With identity on, connectors can sign in through the company's identity provider with OAuth (metadata.go, §5.14).

Index

Constants

View Source
const BearerMethodHeader = "header"

BearerMethodHeader is the only bearer method /mcp accepts for an OAuth token: the Authorization header (RFC 6750 §2.1).

View Source
const MetadataPath = "/.well-known/oauth-protected-resource"

MetadataPath is RFC 9728's well-known path. sandboxd serves it, and the path form for /mcp (MetadataPath + Path), only with identity on, remote MCP on and mcp.resource set in the identity file. Caddy's @api matcher forwards both (scripts/install.sh, packaging/Caddyfile.template).

View Source
const Path = "/mcp"

Path is where the endpoint is mounted: not under /v1, because MCP versions itself.

Variables

This section is empty.

Functions

func ChallengeParams added in v0.6.8

func ChallengeParams(resource string, scopes []string) string

ChallengeParams are the auth-params a /mcp 401 adds to its Bearer challenge (RFC 9728 §5.1): resource_metadata, and scope when the identity file lists scopes, so the connector asks for them (the MCP authorization spec reads the challenge's scope first). "" for a resource with no URL. Scopes are RFC 6749 scope-tokens (no space, quote or backslash, checked at identity-file load), so quoting them needs no escaping.

func Handoff added in v0.6.8

func Handoff(ctx context.Context) (access controlplane.Access, inner, ok bool)

Handoff reports whether ctx belongs to a remote MCP tool's in-process inner call (inner) and, if so, the Access the outer /mcp request authenticated (ok). inner && !ok must never happen: the edge answers it with 500.

func MetadataURL added in v0.6.8

func MetadataURL(resource string) string

MetadataURL is where resource's metadata lives (RFC 9728 §3.1): the well-known path inserted between the host and the resource's path, so https://api.acme.dev/mcp → https://api.acme.dev/.well-known/oauth-protected-resource/mcp. "" for a resource that is not an absolute URL.

Types

type Config

type Config struct {
	// AllowedOrigins lists browser origins that may call /mcp. A request
	// with any other Origin is refused (DNS rebinding); MCP clients that
	// aren't browsers send no Origin and are unaffected.
	AllowedOrigins []string
	// AllowedHosts, when set, lists the Host values /mcp answers to.
	AllowedHosts []string
	// RateLimit is the per-token request rate (req/s); the burst is twice
	// that. Zero disables the limit.
	RateLimit float64
	Version   string
	Logger    *slog.Logger
}

Config configures the endpoint.

type Handler

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

Handler is the /mcp endpoint.

func New

func New(cfg Config, api func() http.Handler) *Handler

New builds the endpoint. api returns sandboxd's root API handler; it is a func because /mcp is mounted on that same handler.

func (*Handler) Wrap

func (h *Handler) Wrap(auth func(http.Handler) http.Handler) http.Handler

Wrap returns the endpoint wrapped around the API's auth middleware, in order: Origin/Host check (before auth, so a rebinding page learns nothing), bearer auth, per-token rate limit, query options, then MCP.

type ResourceMetadata added in v0.6.8

type ResourceMetadata struct {
	// Resource is the identity file's mcp.resource, the /mcp URL.
	Resource string `json:"resource"`
	// AuthorizationServers are the issuers that set mcp: true.
	AuthorizationServers []string `json:"authorization_servers"`
	// ScopesSupported are the identity file's mcp.scopes, the scopes a
	// connector asks its provider for (Entra needs one naming the API app).
	ScopesSupported        []string `json:"scopes_supported,omitempty"`
	BearerMethodsSupported []string `json:"bearer_methods_supported"`
}

ResourceMetadata is the body of GET MetadataPath (RFC 9728 §2).

Jump to

Keyboard shortcuts

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