The `mcp-auth` library provides plug-and-play authentication and authorization solutions specifically for Model Context Protocol (MCP) servers in Node.js environments. It implements the OAuth 2.1 and OpenID Connect standards as required by the MCP specification, aiming to simplify the integration of MCP servers with compliant identity providers. Currently at version 0.2.0, the project is under active development with frequent releases (e.g., from v0.1.0 to v0.2.0 in a short period), indicating continuous feature additions and refinements. Key differentiators include its strict adherence to MCP authorization requirements, a focus on reducing boilerplate for OAuth/OIDC implementation, and direct support for `express` applications, providing a streamlined developer experience for securing MCP resources. It is provider-agnostic and offers tools for checking provider compliance.
npm install mcp-authVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize `mcp-auth` with an OIDC provider, apply bearer token authentication to an Express application, and access authenticated user information within an MCP server tool definition. It highlights the `MCPAuth` class, `fetchServerConfig` utility, and middleware integration.
Regularly consult the project's GitHub changelog and README for the latest API documentation and migration guides. Pin dependencies to exact versions to prevent unexpected breakages.
Ensure `express` is installed as a direct dependency in your project: `npm install express@^5.0.1` or `yarn add express@^5.0.1`.
Upgrade to `mcp-auth` version 0.2.0 or newer to benefit from caching of remote JWK Sets, improving performance and reducing external network calls. No code changes are generally required, but ensure your OIDC provider's JWKS endpoint is robust.
Ensure your project's Node.js environment matches the specified engine requirements. Use a Node.js version manager like `nvm` to switch to a compatible version.
Ensure `await fetchServerConfig(...)` completes successfully and `MCPAuth` is instantiated before its methods are used. Check `authServerUrl` and network connectivity to the OIDC provider.
Run `npm install express@^5.0.1` or `yarn add express@^5.0.1` to install the compatible version of Express.
Verify that `AUTH_SERVER_URL` points to a valid and accessible OIDC provider's base URL. Check network connectivity and the OIDC provider's `.well-known/openid-configuration` endpoint.
Ensure the client sends a valid `Authorization: Bearer <token>` header with an access token obtained from the configured OIDC provider. Verify the token's validity, expiry, and issuer.