@frontmcp/auth

中文文档
1.12.2发布于 2026/11/15Apache-2.0TypeScriptESM + CJS构建来源已验证近 30 天下载 1.3万

Authentication and authorization for FrontMCP servers: auth modes, OAuth 2.1 (local and remote), JWT and session checks, authorities and the credential vault

原始使用文档
文档目录8 节
  1. Install
  2. Usage
  3. Importing from the package directly
  4. What's in it
  5. Docs
  6. Related packages
  7. Contributing
  8. License

@frontmcp/auth

Authentication and authorization for FrontMCP servers: the five auth modes, OAuth 2.1 sign-in with FrontMCP as its own authorization server or in front of your identity provider, JSON Web Token (JWT) and session checks, access rules on tools, and the built-in sign-in pages. @frontmcp/sdk depends on this package, so a FrontMCP server already has it, and you configure it through @FrontMcp({ auth }). Install it yourself only to import something the SDK doesn't re-export, like escapeHtml for a custom sign-in page or AuthorityDeniedError.

npm License

Install

A FrontMCP server doesn't need this step: @frontmcp/sdk installs @frontmcp/auth. To import from it directly:

npm install @frontmcp/auth

Use the same version as @frontmcp/sdk. It needs Node.js 24 or later.

Peer dependencyRequiredWhat it's for
@frontmcp/lazy-zodYesThe option schemas. @frontmcp/sdk already brings it; it needs zod 4.
ioredisNoRedis-backed stores: tokenStorage: { redis } in local and remote modes, RedisSessionStore, and others.
@vercel/kvNoVercelKvSessionStore.
@frontmcp/storage-sqliteNotokenStorage: { sqlite }.

Usage

Set auth on @FrontMcp; its schema comes from this package. Here users sign in at your identity provider, and FrontMCP issues the tokens MCP clients send:

import { FrontMcp } from '@frontmcp/sdk';

import { DeskApp } from './desk.app';

@FrontMcp({
  info: { name: 'desk', version: '1.0.0' },
  apps: [DeskApp],
  auth: {
    mode: 'remote',
    provider: 'https://idp.example.com',
    clientId: 'desk-mcp',
    clientSecret: process.env.IDP_CLIENT_SECRET,
    scopes: ['openid', 'profile', 'email'],
  },
})
export default class Server {}

In production, set JWT_SECRET: FrontMCP signs its tokens with it. Remote and proxied auth lists every option, and the callback URL to register at your provider. mode is one of:

modeWho gets in
'public'Everyone. The default.
'static'Requests that send one of your keys.
'transparent'Requests with a valid JWT signed by your identity provider.
'local'Users who sign in on FrontMCP's own page.
'remote'Users who sign in at your identity provider, through FrontMCP.

Importing from the package directly

In local mode, login.render replaces the sign-in page. FrontMCP doesn't escape what you print, so pass every value through escapeHtml:

import { escapeHtml } from '@frontmcp/auth';
import { FrontMcp } from '@frontmcp/sdk';

import { DeskApp } from './desk.app';

@FrontMcp({
  info: { name: 'desk', version: '1.0.0' },
  apps: [DeskApp],
  auth: {
    mode: 'local',
    login: {
      fields: { deskKey: { type: 'password', label: 'Desk key', required: true } },
      render: (ctx) => `<!doctype html>
<html lang="en">
  <body>
    <p>${escapeHtml(ctx.clientName)} wants to connect to your desk.</p>
    ${ctx.error ? `<p role="alert">${escapeHtml(ctx.error)}</p>` : ''}
    <form method="POST" action="${escapeHtml(ctx.callbackPath)}">
      <input type="hidden" name="pending_auth_id" value="${escapeHtml(ctx.pendingAuthId)}">
      <label>Desk key <input type="password" name="deskKey" required></label>
      <button>Sign in</button>
    </form>
  </body>
</html>`,
    },
    authenticate: async ({ fields }) =>
      fields.deskKey === process.env.DESK_KEY
        ? { ok: true, sub: 'operator' }
        : { ok: false, message: 'Unknown desk key' },
  },
})
export default class Server {}

What's in it

  • Auth modes: authOptionsSchema and the option types of each mode. See Auth modes.
  • Local mode: FrontMCP as an OAuth 2.1 authorization server, with PKCE (Proof Key for Code Exchange), dynamic client registration and refresh tokens. See Local auth.
  • Remote mode: users sign in at your identity provider, and FrontMCP issues the tokens. See Remote and proxied auth.
  • Upstream providers: several OAuth providers linked in one sign-in, on one picker page or one provider per page (incrementalAuth.showAllAppsAtOnce: false, buildFederatedStepPage). See Upstream providers.
  • Token checks: JWT verification against a JSON Web Key Set (JWKS), and audience and scope checks (JwksService, validateAudience). See Tokens and sessions.
  • CIMD (Client ID Metadata Documents): clients whose client_id is the URL of a metadata document (CimdService). A public client declares token_endpoint_auth_method: 'none'; a confidential one declares private_key_jwt and authenticates at the token endpoint with a client assertion signed by a key from its jwks / jwks_uri (RFC 7523, CimdService.verifyClientAssertion). See Client ID metadata.
  • Authorities: rules on tools, resources, prompts, skills and agents, from roles, permissions, token claims, the call's arguments or your own code (AuthorityDeniedError). See Authorities.
  • Credential vault: per-user credentials that tools read with this.credentials, and that users can add to mid-session. See Progressive auth.
  • Sign-in pages: the built-in sign-in, consent and error pages, and escapeHtml, buildLoginPage and baseLayout for your own. See Custom login UI.
  • Storage: memory, Redis, Vercel KV and SQLite stores for sessions, authorization codes and tokens, and encrypted storage for secrets (EncryptedTypedStorage, TokenVault). See Local auth storage.

Docs

  • @frontmcp/sdk: the framework. It runs this package and re-exports its option types.
  • @frontmcp/utils: the crypto (PKCE, encryption, key derivation) and storage adapters this package builds on.
  • @frontmcp/ui: @frontmcp/ui/auth, for React sign-in pages set with auth.ui.
  • @frontmcp/testing: token factories and mock OAuth servers for tests.

Contributing

Source: libs/auth. Issues and pull requests are welcome; see CONTRIBUTING.md.

License

Apache-2.0. See LICENSE.

版本与发布记录

@frontmcp/auth 共发布 109 个版本,首次发布于 2026/01/26;过去 12 个月发布了 109 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.12.2latest2026/11/151 天前
1.12.12026/11/132 天前
1.12.02026/11/114 天前
1.12.0-rc.1rc2026/11/114 天前
1.11.32026/11/106 天前
1.11.22026/11/096 天前

其他发布通道:beta → 1.1.2-beta.1,rc → 1.12.0-rc.1。

关于 @frontmcp/auth 的常见问题

@frontmcp/auth 是什么?

Authentication and authorization for FrontMCP servers: auth modes, OAuth 2.1 (local and remote), JWT and session checks, authorities and the credential vault

如何安装 @frontmcp/auth?

在项目目录运行 npm install @frontmcp/auth,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@frontmcp/lazy-zod(1.12.2)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@frontmcp/auth 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@frontmcp/auth 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@frontmcp/auth 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=24.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@frontmcp/auth 可以商用吗?

@frontmcp/auth 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@frontmcp/auth 的下载量有多少?

根据 npm 官方下载统计,@frontmcp/auth 在 2026/10/16 – 2026/11/14 这 30 天内被下载 13,013 次,日均约 434 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@frontmcp/auth 还在维护吗?

最新版本 1.12.2 发布于 2026/11/15(1 天前);至今共发布 109 个版本,其中过去 12 个月发布了 109 个;首次发布于 2026/01/26。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。