Skip to content

Add MCP_AUTH_CONFIG for inline OAuth tokens#89

Merged
avelino merged 2 commits into
mainfrom
avelino/k8s-auth-env-inline
May 4, 2026
Merged

Add MCP_AUTH_CONFIG for inline OAuth tokens#89
avelino merged 2 commits into
mainfrom
avelino/k8s-auth-env-inline

Conversation

@avelino
Copy link
Copy Markdown
Owner

@avelino avelino commented May 4, 2026

Deploying mcp serve in Kubernetes with a read-only root filesystem made auth.json awkward: MCP_AUTH_PATH only accepts a file path, so OAuth tokens had to be mounted as a file instead of injected from a Secret like every other piece of config. MCP_SERVERS_CONFIG already solved this for servers.json — auth needed the same escape hatch.

Mirror the MCP_SERVERS_CONFIG pattern: when MCP_AUTH_CONFIG is set, load_auth_store reads the JSON inline and skips the file entirely, taking precedence over MCP_AUTH_PATH. Since auth.json is mutable (OAuth refresh writes new tokens), save_auth_store becomes a no-op in inline mode with a single warn log via std::sync::Once — refresh keeps working in-process for the pod's lifetime, and on restart the Secret is read again. Documented as a container-only feature in the k8s/docker how-tos so it doesn't pollute the workstation guide.

Deploying mcp serve in Kubernetes with a read-only root filesystem
made auth.json awkward: MCP_AUTH_PATH only accepts a file path, so
OAuth tokens had to be mounted as a file instead of injected from a
Secret like every other piece of config. MCP_SERVERS_CONFIG already
solved this for servers.json — auth needed the same escape hatch.

Mirror the MCP_SERVERS_CONFIG pattern: when MCP_AUTH_CONFIG is set,
load_auth_store reads the JSON inline and skips the file entirely,
taking precedence over MCP_AUTH_PATH. Since auth.json is mutable
(OAuth refresh writes new tokens), save_auth_store becomes a no-op
in inline mode with a single warn log via std::sync::Once — refresh
keeps working in-process for the pod's lifetime, and on restart the
Secret is read again. Documented as a container-only feature in the
k8s/docker how-tos so it doesn't pollute the workstation guide.

Signed-off-by: Avelino <31996+avelino@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 4, 2026 11:34
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a container-focused escape hatch for OAuth token storage by allowing auth.json to be provided inline via an environment variable, mirroring the existing MCP_SERVERS_CONFIG pattern used for servers.json.

Changes:

  • Introduces MCP_AUTH_CONFIG (higher precedence than MCP_AUTH_PATH) to load the auth store from inline JSON.
  • Makes save_auth_store a no-op when MCP_AUTH_CONFIG is set (with a one-time warn), and adds unit tests for inline-mode behavior.
  • Documents MCP_AUTH_CONFIG usage and precedence across the environment variable reference and the Kubernetes/Docker/container configuration guides.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/auth/store.rs Adds inline auth store loading via MCP_AUTH_CONFIG, makes saves no-op in inline mode, and adds tests.
docs/reference/environment-variables.md Documents MCP_AUTH_CONFIG, its precedence, and intended container use.
docs/howto/kubernetes.md Adds Kubernetes Secret-based deployment instructions for inline OAuth tokens.
docs/howto/docker.md Adds MCP_AUTH_CONFIG to the container env var list and Docker OAuth limitations guidance.
docs/guides/configuration.md Adds a container/Kubernetes section describing inline JSON env vars for config and auth.

Comment thread src/auth/store.rs
Comment thread src/auth/store.rs
Comment thread docs/reference/environment-variables.md
Comment thread docs/reference/environment-variables.md Outdated
Comment thread docs/howto/kubernetes.md Outdated
Signed-off-by: Avelino <31996+avelino@users.noreply.github.com>
@avelino avelino merged commit 9a1b4ce into main May 4, 2026
9 checks passed
@avelino avelino deleted the avelino/k8s-auth-env-inline branch May 4, 2026 11:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants