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 ¶
var ErrNoToken = errors.New("no token")
ErrNoToken is returned by a source that has no token.
Functions ¶
func LoadOrCreateKey ¶
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 TokenSource ¶
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.