Skip to main content

Overview

MCP clients use OAuth authorization-server metadata, Dynamic Client Registration, PKCE, token exchange, introspection, and revocation endpoints. @grantex/mcp-auth registers those six routes on a Fastify instance and provides Express and Hono JWT-verification middleware. Current published release: @grantex/mcp-auth@2.0.2.
This exact command is reproducible. See Release Status before upgrading either independently versioned package.
The supplied Grantex client can point at Grantex Cloud or a self-hosted Grantex API. That backend choice does not make the MCP authorization server’s own client-registration or authorization-code state managed or durable.
Release 2.0.2 is a single-process evaluation release, not a turnkey production deployment. Client registrations default to process memory and authorization codes always use a non-configurable in-memory store, so restarts lose state and multi-replica authorize/token flows can fail. consentUi only adds discovery metadata; no /consent page is registered. The package also does not persist the auth.code returned by the Grantex SDK and can fall back to an authorization-request ID during token exchange, which is not a valid exchange code. Do not rely on end-to-end token issuance until a corrected package release is published and validated with your backend.

Deployment behavior in 2.0.2

Quick Start

The following starts the published endpoint surface for local inspection and evaluation. It does not remove the limitations above.

1. Create the auth server

2. Protect your MCP routes

Use the Express or Hono middleware to validate tokens on every request:

3. Verify it works

MCP clients discover your auth server automatically:

Endpoints

createMcpAuthServer() registers six endpoints on the Fastify instance:

Well-Known Metadata

The metadata endpoint returns a JSON document that MCP clients use to discover all other endpoints:

Token Introspection

The endpoint verifies JWT signatures and claims against the issuer JWKS. In 2.0.2 it does not query Grantex for current revocation state, so a revoked but otherwise valid token can remain active here until expiry:
Active token response:

Token Revocation

The revocation endpoint decodes the token jti and requests revocation from Grantex. It returns 200 OK even if that backend call fails, and the package middleware/introspection paths do not consult the resulting revocation state:
Per RFC 7009, the endpoint always returns 200 OK, even if the token was already revoked.

Scope Definition

Define the scopes your MCP server supports when creating the auth server:
Scopes are used at two implemented points in 2.0.2:
  1. Authorization request: The package forwards the requested scopes to the configured Grantex client.
  2. Middleware: requireMcpAuth() rejects tokens that lack required scopes.
The package does not render a consent page. A complete human-consent handoff must be implemented outside this release. consentUi copies display metadata into the discovery document under grantex_extensions.consent_ui_config:
2.0.2 does not register the /consent URL advertised in grantex_extensions.consent_ui, and consentUi does not render or host a consent page. Supply that interaction separately and validate the complete authorization flow before use.

Lifecycle hooks

Only hooks.onRevocation is invoked by 2.0.2:
The exported configuration type also declares onTokenIssued, but the token endpoint in 2.0.2 does not call it. Do not depend on that hook until a corrected release is published.

Express Middleware

Express and Hono middleware verify JWT signatures, claims, algorithms, and configured scopes. They do not perform an online revocation check in 2.0.2.

requireMcpAuth(options)

McpGrant (decoded token claims)

Hono Middleware

Custom Client Store

By default, client registrations are stored in process memory. A custom ClientStore can persist registrations, but authorization codes remain in a non-configurable process-local store in 2.0.2; a custom client store alone does not make the server durable or horizontally scalable:

Certification Program

Grantex accepts Bronze, Silver, and Gold certification applications for registered MCP servers. Applications begin in pending_conformance_test; submission alone is not certification. See the MCP Certification Applications guide for the current API and limitations.
Using @grantex/mcp-auth does not automatically certify a server. Treat the status returned by the certification API as authoritative and do not publish a badge for a pending application.

Configuration Reference

McpAuthConfig

Rate Limits

Default per-endpoint rate limits:

Security Considerations

@grantex/mcp-auth implements the following request and token-validation controls. These controls do not remove the deployment and end-to-end flow limitations documented above:
  • PKCE S256 is mandatory. The plain method and implicit grant are rejected.
  • No password grant. The password grant type is not supported.
  • No implicit grant. Only response_type=code is accepted.
  • Authorization codes are single-use. Replayed codes are rejected.
  • HS256 rejected. Only asymmetric algorithms (RS256, ES256, PS256, EdDSA) are accepted.
  • Client secrets are generated using crypto.randomBytes(32).
  • JWKS verification uses the jose library with remote key set fetching and caching.
Last modified on July 12, 2026