LogoMCP Auth

Configuration

Environment variables and provider options for @mcpauth/auth

Configuration

@mcpauth/auth is highly configurable. This page documents environment variables, provider options, and server options.

Environment Variables

VariableRequiredDescription
MCPAUTH_ALLOWED_ORIGINComma-separated list of origins allowed to use your OAuth server.
MCPAUTH_SECRETSecret for signing the state param during OAuth flow.
MCPAUTH_PRIVATE_KEYPrivate key for signing JWTs. Must be PEM formatted.

Provider Options

All adapters ultimately consume the same core provider options:

interface ProviderOptions {
  adapter: StoreAdapter;        // PrismaAdapter | DrizzleAdapter | ...
  issuerUrl: string;            // e.g. process.env.BASE_URL
  issuerPath?: string;          // default: /api/oauth
  authenticateUser: (req) => Promise<OAuthUser | null>;
  signInUrl?: (req, cb: string) => string; // Optional custom login page
  serverOptions?: ServerOptions; // see below
}

authenticateUser

This callback bridges your existing user auth to the OAuth flow. Return a user object if the request is authenticated, otherwise null.

const mcpAuth = McpAuth({
  ...options,
  authenticateUser: async (req) => {
    // Example: using a session manager like NextAuth.js or Express Session
    const session = await getSession(req);
    return (session?.user as OAuthUser) ?? null;
  },
});

Server Options

OptionDefaultDescription
accessTokenLifetime3600Lifetime of access tokens (seconds).
refreshTokenLifetime1209600Lifetime of refresh tokens (seconds).

Next: Next.js Adapter ➡️