Anonymous View

API Key

Secure access and protect your MCP server using API keys.

For the complete documentation index, see llms.txt. Markdown variants of every page are available by appending .md to the URL.

To enable API key authentication, you can use the apiKeyAuthMiddleware middleware on your app.

src/middleware.ts

If no headerName is provided, the middleware will default to x-api-key.

This middleware can also be used with a validation function. It should return a boolean value indicating if the API key is valid.

src/middleware.ts

Next time you connect to your MCP server, you'll need to provide the API key in the x-api-key header (or the name you specified in the middleware).

Your connection object will look like this:

Make sure to check the connecting documentation for more details on the different clients.

One framework to rule them all