Drop-in OAuth 2.1 + PKCE authorization for any Model Context Protocol server. Human consent, scoped access, instant revocation, and a full audit trail — in under 10 lines of code.
npm install @grantex/mcp-auth
Copy
API keys and hardcoded JWTs are fine for demos. For production, you need consent, scoped permissions, revocation, and an audit trail.
| Capability | API Keys | Hardcoded JWT | Grantex MCP Auth |
|---|---|---|---|
| Human consent flow | ✕ | ✕ | ✓ |
| Scoped permissions | ✕ | Manual | ✓ |
| Instant revocation | Rotate key | ✕ | ✓ |
| Audit trail | ✕ | ✕ | ✓ |
| RFC standard | ✕ | Partial | ✓ |
| Dynamic Client Registration | ✕ | ✕ | ✓ |
| Token introspection | ✕ | ✕ | ✓ |
| MCP Spec compliant | ✕ | ✕ | ✓ |
createMcpAuthServer() registers
everything an MCP client needs to discover, register, authorize, and manage tokens.
| Method | Endpoint | RFC | Description |
|---|---|---|---|
| GET | /.well-known/oauth-authorization-server | RFC 8414 | Server metadata discovery |
| POST | /register | RFC 7591 | Dynamic Client Registration |
| GET | /authorize | OAuth 2.1 | Authorization (PKCE required) |
| POST | /token | OAuth 2.1 | Token endpoint (code + refresh) |
| POST | /introspect | RFC 7662 | Token introspection |
| POST | /revoke | RFC 7009 | Token revocation |
Install the package, create the server, protect your routes. MCP clients auto-discover your auth endpoints via the well-known metadata URL.
One dependency. Zero peer requirements beyond the Grantex SDK.
npm install @grantex/mcp-auth @grantex/sdk
Define your scopes and issuer. The server handles PKCE, DCR, introspection, and revocation automatically.
import { Grantex } from '@grantex/sdk'; import { createMcpAuthServer } from '@grantex/mcp-auth'; const grantex = new Grantex({ baseUrl: 'https://grantex-auth-dd4mtrt2gq-uc.a.run.app', apiKey: process.env.GRANTEX_API_KEY, }); const authServer = await createMcpAuthServer({ grantex, agentId: 'ag_your_mcp_server', scopes: ['tools:read', 'tools:execute', 'resources:read'], issuer: 'https://your-mcp-server.example.com', }); await authServer.listen({ port: 3001 });
Drop in the Express or Hono middleware. Every request is verified against the JWKS, scopes are enforced, and decoded grant claims are available in your handler.
import express from 'express'; import { requireMcpAuth } from '@grantex/mcp-auth/express'; const app = express(); // Protect all MCP tool routes app.use('/mcp', requireMcpAuth({ issuer: 'https://your-mcp-server.example.com', scopes: ['tools:execute'], })); // Decoded grant available on every request app.post('/mcp/tools/call', (req, res) => { const grant = req.mcpGrant; console.log(grant.agentDid, grant.scopes); res.json({ result: 'tool executed' }); });
Prove your MCP server implements OAuth 2.1 correctly. Three tiers, automated conformance testing, and a listing in the Grantex MCP Registry visible to 10,000+ developers.
Every certified server appears in the Grantex registry with its tier, scopes, and a direct install link. Users can trust that listed servers meet OAuth 2.1 requirements.
Read, create, and manage calendar events. Full delegation support with budget controls for scheduling agents.
Sandboxed file operations with scoped directory access. Read, write, and search files within allowed paths.
Read-only SQL queries against Postgres and MySQL. Schema introspection and query result formatting.
Use Grantex Cloud for zero-infrastructure auth, or run the full stack on your own infrastructure. The code is identical — just point the SDK at a different URL.
Grantex Cloud handles signing keys, JWKS hosting, and uptime.
Cloud Run auto-scaling with global CDN for metadata endpoints.
Compliance handled on our side. Export audit logs anytime.
1,000 token exchanges per month. No credit card required.
const server = await createMcpAuthServer({ grantex: new Grantex({ baseUrl: 'https://grantex-auth-dd4mtrt2gq-uc.a.run.app', apiKey: process.env.GRANTEX_API_KEY, }), agentId: 'ag_your_server', scopes: ['tools:read', 'tools:execute'], issuer: 'https://your-domain.example.com', });
All tokens, keys, and audit logs stay on your infrastructure.
Plug in Postgres, Redis, or any database via the ClientStore interface.
Deploy configs for Kubernetes, Cloud Run, ECS, and bare metal.
Works offline once JWKS is cached. No outbound calls required at runtime.
const server = await createMcpAuthServer({ grantex: new Grantex({ baseUrl: 'https://auth.your-company.internal', apiKey: process.env.GRANTEX_API_KEY, }), agentId: 'ag_internal_server', scopes: ['internal:read', 'internal:write'], issuer: 'https://auth.your-company.internal', // Persistent storage for client registrations clientStore: new PostgresClientStore(), });
Every security decision follows the OAuth 2.1 specification. No implicit grant, no password grant, no symmetric signing, no plain PKCE.
The plain method and implicit grant are rejected. Every authorization request requires S256 code challenge.
HS256 is explicitly rejected. Tokens are verified with RS256, ES256, PS256, or EdDSA via remote JWKS.
Authorization codes are consumed on first exchange. Replay attempts are rejected and logged as anomalies.
10/min on authorize, 20/min on token, 30/min on introspect. Configurable per deployment.
Every token issuance, introspection, and revocation is logged via Grantex events. Stream to Datadog, Splunk, or S3.
Client secrets are generated with crypto.randomBytes(32). Auth codes use the same entropy source.
One package. Six RFC-compliant endpoints. Human consent, scoped access, instant revocation, and a certification badge to prove it.
npm install @grantex/mcp-auth
Copy