mcpremote

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Overview

Package mcpremote serves the remote MCP endpoint of the Claude connector, POST /__backyard/mcp (SPEC §14.1): Streamable HTTP, stateless, JSON responses only, protocol versions 2025-11-25 and 2025-06-18. It is a hand-written JSON-RPC handler (the Cloudflare edition's src/mcp.ts is its twin) over the shared tool catalog tools.json.

The endpoint accepts only the MCP access tokens of Backyard's own authorization server (internal/auth, SPEC §8.4): no cookies, API tokens, static tokens or identity-proxy headers. Every request re-checks the grant, so a revoked connection stops at once. The tools read the sites and publish through the deploy gateway (deploy.Gateway.Publish); a docstore lease serializes the connector's publishes of a site across replicas.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(o Options) http.Handler

New returns the endpoint handler. Mount it at /__backyard/mcp on the canonical hub host; it applies the gate of SPEC §14.1 itself.

func ToolsJSON

func ToolsJSON() []byte

ToolsJSON returns the embedded tool catalog (tools.json).

Types

type AuthServer

type AuthServer interface {
	// VerifyAccessToken returns the re-gated user and the grant of a
	// token; errors.Is(err, auth.ErrInvalidToken) means 401, anything else
	// an infrastructure failure.
	VerifyAccessToken(ctx context.Context, raw string) (*identity.User, *auth.Grant, error)
	// Challenge is the exact WWW-Authenticate value for a token error (nil:
	// the missing-token form).
	Challenge(err error) string
	ResourceMetadataURL() string // M
	Resource() string            // R
	Issuer() string              // P, the hub origin
	// AllowedOrigin reports whether an Origin other than the hub's may
	// call the endpoint (the origins of mcp.redirect_uris and mcp.clients).
	AllowedOrigin(origin string) bool
	MaxBodyBytes() int64
}

AuthServer is what the endpoint needs from the connector's authorization server; *auth.MCP implements it.

type Options

type Options struct {
	Config *config.Config
	// Auth is the authorization server (auth.MCPOf); nil or disabled
	// answers 404 everywhere.
	Auth  AuthServer
	Sites *sites.Registry // default: a registry over Blob
	Blob  blob.Store      // default: Sites.Store()
	// Docs holds the cross-replica publish lease (_system/_mcp_locks).
	Docs docstore.Store
	// Gateway publishes; nil when deploy.embedded_gateway is false.
	Gateway *deploy.Gateway
	// DocsFor returns backyard_docs topics (default mcpserver.DefaultDocs).
	DocsFor func(topic string) (string, error)
	// Allow is the per-user request limit (ratelimit.API) for the key
	// "user:<id>"; nil means unlimited.
	Allow func(key string) (bool, time.Duration)
	// OnPublish runs after every backyard_publish that reached the
	// gateway, ok or not (PurgeSite, ObserveDeploy("mcp", …)).
	OnPublish func(site string, ok bool)
	// RequestOrigin returns the client-visible origin (scheme://host[:port],
	// lowercase) of r, honouring trusted proxy headers; default: from r.TLS
	// and r.Host.
	RequestOrigin func(r *http.Request) string
	// ClientIP returns the caller's address for audit records; default:
	// the host of r.RemoteAddr.
	ClientIP func(r *http.Request) string
	Version  string // serverInfo.version (default version.Version)
	Logger   *slog.Logger
	Now      func() time.Time
}

Options configure the endpoint.

Jump to

Keyboard shortcuts

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