Skip to content

fix: require a token for MCP over HTTP and bind servers to one org (#116) - #146

Merged
OkiriGabriel merged 1 commit into
mainfrom
fix/mcp-auth-116
Oct 29, 2026
Merged

OkiriGabriel merged 1 commit into
mainfrom
fix/mcp-auth-116

Conversation

@OkiriGabriel

Copy link
Copy Markdown
Collaborator

Description

Fixes #116. It also closes the MCP half of #59, whose HTTP API half was fixed in #127.

devops-agent mcp --transport sse|streamable-http served every tool with no authentication. Anyone who could reach the port could call configure_org_credentials for any org and swap in their own GitHub token, kubeconfig, Anthropic key or Slack webhook (taking over the agent's actions and capturing its reports), or call any agent tool for any org.

1. Token required for HTTP transports (devops_mcp/auth.py)

  • MCP_AUTH_TOKEN must be set for sse and streamable-http, or the server refuses to start with a clear message.
  • The Starlette apps FastMCP builds (sse_app() / streamable_http_app()) are wrapped in an ASGI middleware. Every HTTP request needs Authorization: Bearer <token>, otherwise it gets 401 + WWW-Authenticate: Bearer. The comparison is constant time and reuses _signatures_equal.
  • MCP_AUTH_DISABLED=true is accepted only on a loopback host; on 0.0.0.0 or a LAN address it still refuses to start.
  • run_mcp still calls mcp.run(transport=...), so FastMCP's own server startup and the bind-address precedence from [BUG] FASTMCP_HOST/PORT in .env silently override the mcp --host/--port flags #40 are unchanged.

2. Org binding: MCP_ORG_ID=acme

  • Every tool and resource now resolves its org through resolve_org(). On a bound server, any other org_id is rejected (the client gets a tool error) and calls without one use the bound org.
  • Tool schemas no longer default org_id to ORG_ID. That default would have been sent as an explicit, different org and conflicted with the binding. Empty now means "the default org".
  • Shared infrastructure runs one MCP server per tenant, each with its own token and MCP_ORG_ID.

3. Credential writes off over HTTP by default

  • configure_org_credentials is only registered on sse/streamable-http with MCP_ALLOW_CREDENTIAL_WRITE=true. On stdio, a local single-user process, it's unchanged.

⚠️ Breaking change

Anyone already running devops-agent mcp --transport sse|streamable-http must set MCP_AUTH_TOKEN and configure clients to send it. The default stdio transport (Cursor, Claude Desktop) is not affected.

Type of Change

  • Bug fix (security)
  • Breaking change (HTTP MCP needs a token)
  • Documentation update

Testing

  • New tests/test_mcp_auth.py (32 tests):
    • startup: both HTTP transports refuse without a token on loopback, 0.0.0.0 and LAN addresses; MCP_AUTH_DISABLED works on 127.0.0.1/localhost/::1 only; run_mcp never builds the server when refusing; stdio needs no token.
    • middleware against FastMCP's real apps: streamable-http rejects missing, wrong, Basic and scheme-less credentials with 401 and completes initialize with the token. SSE /sse and /messages/ return 401 without it, and the token is passed through to the transport.
    • credential tool: absent over sse/streamable-http by default, present with the opt-in, always present on stdio.
    • org binding end-to-end via call_tool: platform tools and agent tools reject another org on a bound server, and default to the bound org.
  • tests/test_mcp_env_precedence.py now sets a token (those tests cover bind-address precedence, not auth).
  • Full suite: 975 passed, 4 skipped. Flake8 critical: 0. Bandit -ll clean. mkdocs build --strict plus link check: 0 errors.

Docs

  • README.md: "Start the MCP server" now covers the token, binding, credential opt-in and loopback-only disable.
  • .env.example: documents the four new variables.
  • docs/API_REFERENCE.md and SECURITY_GUARANTEES.md no longer say MCP is uncovered.

🤖 Generated with Claude Code

`devops-agent mcp --transport sse|streamable-http` served every tool,
including configure_org_credentials, without authentication (#116).
Anyone who could reach the port could replace an org's GitHub token,
kubeconfig or Slack webhook, or call any agent tool for any org.

- MCP_AUTH_TOKEN is required for both HTTP transports; the Starlette
  apps FastMCP builds are wrapped in a bearer-token check (401 +
  WWW-Authenticate otherwise, constant-time compare). The server refuses
  to start without it; MCP_AUTH_DISABLED=true is accepted only on a
  loopback host.
- MCP_ORG_ID binds a server to one org: every tool and resource resolves
  its org through resolve_org, so other org_ids are rejected and calls
  without one use the bound org. Tool schemas no longer default org_id
  to ORG_ID, which would have conflicted with the binding.
- configure_org_credentials is only registered over HTTP with
  MCP_ALLOW_CREDENTIAL_WRITE=true; stdio is unchanged.

Fixes #116

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@OkiriGabriel
OkiriGabriel merged commit 97b9793 into main Oct 29, 2026
12 checks passed
@OkiriGabriel
OkiriGabriel deleted the fix/mcp-auth-116 branch November 26, 2026 10:13
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.

[SECURITY] MCP server over SSE/HTTP has no authentication and lets any caller overwrite org credentials

1 participant