mcpproxy

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: Apache-2.0 Imports: 18 Imported by: ? 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 mcpproxy is a host-side proxy for the master's MCP endpoint. It keeps the access token outside of dev containers: the container talks to the proxy without a hub token, and the proxy adds the token, which it reads on the host (macOS Keychain, a file or the environment).

Only the MCP endpoint and its build uploads are forwarded, so whoever reaches the proxy can't use the token for the rest of the API.

Uploads: the begin_upload tool returns a URL next to the MCP endpoint. The proxy tells the master the address the client used (X-Forwarded-Host, -Proto, -Prefix), so that URL points back at the proxy, and forwards "PUT <mcp path>/uploads/<id>". That path needs no proxy key: the upload id is a single-use secret only the MCP session that created it knows.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoToken = errors.New("no token")

ErrNoToken is returned by a source that has no token.

Functions

func Handler

func Handler(cfg Config) http.Handler

Handler returns the proxy handler.

func LoadOrCreateKey

func LoadOrCreateKey(path string) (string, error)

LoadOrCreateKey returns the proxy key stored in path, creating it (mode 600, directory 700) on first use.

Types

type Config

type Config struct {
	// Upstream is the master, e.g. http://localhost:8002.
	Upstream *url.URL
	// Project is used for requests to /mcp. Requests to /<project>/mcp
	// name the project themselves.
	Project string
	// Token supplies the hub access token (an ahp_ personal token).
	Token TokenSource
	// Key, when set, must be sent by clients as "Authorization: Bearer <key>".
	// It is a local key of this proxy, not a hub token: it limits who on the
	// docker network can use the proxy and is worthless anywhere else.
	Key string
	// Logf logs requests and errors; nil uses log.Printf.
	Logf func(format string, args ...any)
}

Config of the proxy.

type TokenFunc

type TokenFunc func() (string, error)

TokenFunc adapts a function to TokenSource.

func (TokenFunc) Token

func (f TokenFunc) Token() (string, error)

type TokenSource

type TokenSource interface {
	Token() (string, error)
}

TokenSource supplies the hub access token.

func CachedToken

func CachedToken(source TokenSource, ttl time.Duration) TokenSource

CachedToken keeps a token for ttl, so a rotated token is picked up without a restart while the Keychain isn't asked on every request.

func EnvToken

func EnvToken(name string) TokenSource

EnvToken reads the token from an environment variable.

func FileToken

func FileToken(path string) TokenSource

FileToken reads the token from a file only its owner can read.

func FirstToken

func FirstToken(sources ...TokenSource) TokenSource

FirstToken uses the first source that has a token. A source that fails for another reason than ErrNoToken stops the search, so a misconfigured file isn't silently skipped.

func KeychainToken

func KeychainToken(service, account string) TokenSource

KeychainToken reads a generic password from the macOS Keychain. On other systems it never has a token.

Jump to

Keyboard shortcuts

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