Repository navigation
fix: require a token for MCP over HTTP and bind servers to one org (#116) - #146
Merged
Merged
Conversation
`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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-httpserved every tool with no authentication. Anyone who could reach the port could callconfigure_org_credentialsfor 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_TOKENmust be set forsseandstreamable-http, or the server refuses to start with a clear message.sse_app()/streamable_http_app()) are wrapped in an ASGI middleware. Every HTTP request needsAuthorization: Bearer <token>, otherwise it gets 401 +WWW-Authenticate: Bearer. The comparison is constant time and reuses_signatures_equal.MCP_AUTH_DISABLED=trueis accepted only on a loopback host; on0.0.0.0or a LAN address it still refuses to start.run_mcpstill callsmcp.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=acmeresolve_org(). On a bound server, any otherorg_idis rejected (the client gets a tool error) and calls without one use the bound org.org_idtoORG_ID. That default would have been sent as an explicit, different org and conflicted with the binding. Empty now means "the default org".MCP_ORG_ID.3. Credential writes off over HTTP by default
configure_org_credentialsis only registered onsse/streamable-httpwithMCP_ALLOW_CREDENTIAL_WRITE=true. On stdio, a local single-user process, it's unchanged.Anyone already running
devops-agent mcp --transport sse|streamable-httpmust setMCP_AUTH_TOKENand configure clients to send it. The default stdio transport (Cursor, Claude Desktop) is not affected.Type of Change
Testing
tests/test_mcp_auth.py(32 tests):0.0.0.0and LAN addresses;MCP_AUTH_DISABLEDworks on127.0.0.1/localhost/::1only;run_mcpnever builds the server when refusing; stdio needs no token.Basicand scheme-less credentials with 401 and completesinitializewith the token. SSE/sseand/messages/return 401 without it, and the token is passed through to the transport.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.pynow sets a token (those tests cover bind-address precedence, not auth).-llclean.mkdocs build --strictplus 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.mdandSECURITY_GUARANTEES.mdno longer say MCP is uncovered.🤖 Generated with Claude Code