Skip to content

docs(mcp): reject requests when the api key isn't configured - #3772

Merged
kamilmysliwiec merged 1 commit into
nestjs:masterfrom
ofri-peretz:docs/mcp-api-key-guard
Nov 16, 2026
Merged

kamilmysliwiec merged 1 commit into
nestjs:masterfrom
ofri-peretz:docs/mcp-api-key-guard

Conversation

@ofri-peretz

Copy link
Copy Markdown
Contributor

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Docs
  • Other... Please describe:

What is the current behavior?

Issue Number: N/A

The ApiKeyGuard example in the MCP transports chapter compares the header straight to process.env.MCP_API_KEY. If the variable isn't set, a request with no x-api-key header gets through, because both sides are undefined. The line under the example says that request gets a 403.

What is the new behavior?

The guard returns false when the key isn't configured or the header is missing, and compares in constant time. It's the same shape as AdminGuard in the outbox chapter.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@kamilmysliwiec
kamilmysliwiec merged commit ad96d84 into nestjs:master Nov 16, 2026
4 checks passed
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