-
Notifications
You must be signed in to change notification settings - Fork 60
Open
Labels
feature-requestNew feature requestNew feature request
Description
Problem statement
XMCP's current JWT validation logic requires a statically configured JWK via config.jwt.jwk. This approach works for simple cases but has several limitations:
- No Key Rotation Support: Static JWKs don’t allow for automatic key rollover from providers like Auth0, Okta, or Azure AD
- No
kidMatching: If the JWT contains akidin its header, there’s no mechanism to resolve that key from a remote key set - Provider Lock-In: Many OAuth providers expose only a
.well-known/jwks.jsonURL for key discovery, which cannot be used without JWKS support
Proposed solution
Extend config.jwt to support a jwksUri field, and use jose's createRemoteJWKSet() to dynamically fetch and cache keys for JWT verification.
Suggested Config Schema Addition
const jwtConfigSchema = z.object({
issuer: z.string(),
audience: z.string().optional(),
jwk: z.record(z.any()).optional(), // existing
jwksUri: z.string().url().optional(), // new
});Suggested Validation Implementation
import { createRemoteJWKSet, jwtVerify, decodeJwt } from "jose";
if (this.config.jwt?.jwksUri) {
const JWKS = createRemoteJWKSet(new URL(this.config.jwt.jwksUri));
const { payload } = await jwtVerify(token, JWKS, {
issuer: this.config.jwt.issuer,
audience: this.config.jwt.audience,
});
return {
token,
clientId: payload.azp ?? payload.client_id ?? "jwt",
scopes: payload.scope?.split(" ") ?? [],
expiresAt: payload.exp ? new Date(payload.exp * 1000) : undefined,
};
}Benefits
- Standards Compliant: Aligns with RFC 7517 and common OpenID Connect discovery patterns
- Key Rotation Ready: Automatically supports key rollover via JWKS
- Secure: Signature verification will correctly respect the JWT’s
kidheader - Interoperable: Makes XMCP compatible with more real-world OAuth 2.0 and OIDC providers
Implementation Notes
- Fallback to
jwkifjwksUriis not configured createRemoteJWKSetincludes built-in caching and rate limiting- Consider exposing JWKS cache options later if needed (e.g., TTL)
Package
xmcp (core framework)
Metadata
Metadata
Assignees
Labels
feature-requestNew feature requestNew feature request