Skip to content

Require CORTEX_API_KEY for MCP server in production#52

Merged
askmy-stack merged 1 commit into
mainfrom
security/mcp-require-api-key-in-production
Jul 14, 2026
Merged

Require CORTEX_API_KEY for MCP server in production#52
askmy-stack merged 1 commit into
mainfrom
security/mcp-require-api-key-in-production

Conversation

@askmy-stack

Copy link
Copy Markdown
Owner

Summary

  • mcp/server.js falls back to the legacy X-Cortex-Roles header when CORTEX_API_KEY is unset, which api/deps.py trusts whenever CORTEX_API_KEYS is not configured server-side. Any process with MCP env access could escalate to admin/gdpr_officer and invoke GDPR-adjacent tools without a real key.
  • The MCP server now refuses all tool calls when ENVIRONMENT=production and CORTEX_API_KEY is missing, and logs a warning at startup.
  • Documented the requirement in .env.example and mcp/Dockerfile (which now defaults ENVIRONMENT=production).
  • Extracted auth resolution into mcp/auth.js so it's unit-testable independently of the MCP SDK; added mcp/server.test.js (npm test via Node's built-in test runner).

Test plan

  • npm test in mcp/ — 5 passing tests covering production+missing key (blocked), production+key (allowed), dev without key (allowed), default/unset environment, and case-insensitivity.
  • Verified postJson throws an explicit auth error for all three tools (cortex_query, cortex_remember, cortex_inject) when blocked.

Fixes #51

Made with Cursor

When CORTEX_API_KEY is unset, mcp/server.js falls back to sending the
legacy X-Cortex-Roles header, which api/deps.py trusts whenever
CORTEX_API_KEYS is not configured server-side. Any process with MCP
env access could therefore claim admin/gdpr_officer without a real
key and invoke GDPR-adjacent tools.

Refuse all MCP tool calls when ENVIRONMENT=production and
CORTEX_API_KEY is missing, log a warning at startup, and document the
requirement in .env.example and mcp/Dockerfile. Auth resolution is
extracted into mcp/auth.js so it can be unit tested independently of
the MCP SDK.

Fixes #51

Co-authored-by: Cursor <cursoragent@cursor.com>
@vercel

vercel Bot commented Jul 14, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
cortex Ready Ready Preview, Comment Jul 14, 2026 1:26pm

@askmy-stack
askmy-stack merged commit 22c5cd5 into main Jul 14, 2026
4 checks passed
@askmy-stack
askmy-stack deleted the security/mcp-require-api-key-in-production branch July 14, 2026 14:53
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.

MCP server: require API key in production

1 participant