@frontmcp/utils

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

Shared helpers for FrontMCP: URI templates, naming, cross-platform crypto and PKCE, key-value storage, file system and environment detection

原始使用文档
文档目录6 节
  1. Install
  2. Usage
  3. What's in it
  4. Related packages
  5. Contributing
  6. License

@frontmcp/utils

Shared helpers for the FrontMCP packages: names and URI templates, cross-platform crypto, key-value storage, file system access, environment detection and more. This is an internal package: @frontmcp/sdk and the other @frontmcp/* packages depend on it and install it for you. Import it directly only when your own code, like a plugin, needs one of these helpers.

npm License

Install

npm install @frontmcp/utils

It needs Node.js 24 or later. The crypto, async context, event emitter, environment and path helpers also have browser builds, picked through the package's imports map. @frontmcp/lazy-zod is a required peer dependency (it needs zod 4). The others are optional, one per storage backend:

Optional peerEnables
iorediscreateStorage({ type: 'redis' }) and RedisStorageAdapter
@vercel/kvcreateStorage({ type: 'vercel-kv' })
@upstash/rediscreateStorage({ type: 'upstash' })

Usage

import { createStorage, expandUriTemplate, matchUriTemplate, sha256Hex, toCase } from '@frontmcp/utils';

matchUriTemplate('tickets://{id}/comments/{commentId}', 'tickets://T-1/comments/42');
// { id: 'T-1', commentId: '42' }

expandUriTemplate('tickets://{id}', { id: 'T-2' }); // 'tickets://T-2'
toCase(['create', 'ticket'], 'snake'); // 'create_ticket'
sha256Hex('hello world'); // 'b94d27b9...'

const storage = await createStorage({ type: 'memory' });
await storage.set('ticket:T-1', 'open', { ttlSeconds: 60 });
await storage.get('ticket:T-1'); // 'open'

What's in it

AreaExports
NamingsplitWords, toCase, shortHash, ensureMaxLen, idFromString
URIsisValidMcpUri, extractUriScheme, parseUriTemplate, matchUriTemplate, expandUriTemplate, extractTemplateParams (RFC 3986 URIs, RFC 6570 templates)
PathstrimSlashes, joinPath, and cross-platform pathJoin, pathResolve, basename, dirname, extname
ContentsanitizeToJson, inferMimeType, safeStringify, canonicalJson
HTTPvalidateBaseUrl, buildSetCookie, parseCookies, getCookie, isLocalhost, isSecureRequest
NetworkclassifyIpAddress, isGloballyRoutableIp, parseIpv4, expandIpv6, isRedirectResponse, for SSRF (server-side request forgery) checks
Outbound HTTPvalidateOutboundUrl, sendOutboundRequest, outboundFailureCategory, for a request to a URL that a client chose
EscapingescapeHtml, escapeHtmlAttr, escapeJsString, safeJsonForScript
Cryptosha256, sha256Hex, hmacSha256, hkdfSha256, encryptAesGcm, decryptAesGcm, randomBytes, randomUUID, timingSafeEqual, base64urlEncode, base64urlDecode
PKCEgenerateCodeVerifier, generateCodeChallenge, verifyCodeChallenge, generatePkcePair (RFC 7636)
WebhookssignWebhookMessage, webhookSignatureHeaders, verifyWebhookSignature, isStandardWebhookSecret, generateWebhookMessageId (Standard Webhooks)
Encryption, keysencryptValue, decryptValue, signData, verifyData, KeyPersistence, createKeyPersistence
StoragecreateStorage, createMemoryStorage, TypedStorage, EncryptedTypedStorage, and adapters for memory, Redis, Vercel KV, Upstash and the file system
File systemreadFile, writeFile, mkdir, stat, fileExists, readJSON, writeJSON, ensureDir, isDirEmpty, runCmd and more. Node.js only; fs loads on first use.
ProcessesspawnOwned, reapOrphans, watchParent, watchPath, stopProcessTree, signalProcessTree. Node.js only; child_process loads on first use.
EnvironmentgetEnv, isProduction, isDevelopment, isEdgeRuntime, isServerless, getRuntimeContext, isNode, isBrowser
Context, eventsAsyncLocalStorage, EventEmitter, both with browser builds
Safe regexisPatternSafe, createSafeRegExp, safeTest, safeMatch, safeReplace, against ReDoS (regular expression denial of service)
Model tool callsprocessPlatformToolCalls, which passes OpenAI, Claude or Vercel AI tool calls to your callTool function and returns the results in that platform's format
Machine IDgetMachineId, setMachineIdOverride, getHostname

Contributing

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

License

Apache-2.0. See LICENSE.

版本与发布记录

@frontmcp/utils 共发布 111 个版本,首次发布于 2026/01/04;过去 12 个月发布了 111 个版本。最新版本附带 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/utils 的常见问题

@frontmcp/utils 是什么?

Shared helpers for FrontMCP: URI templates, naming, cross-platform crypto and PKCE, key-value storage, file system and environment detection

如何安装 @frontmcp/utils?

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

@frontmcp/utils 支持 TypeScript 吗?

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

@frontmcp/utils 支持 ESM 还是 CommonJS?

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

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

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

@frontmcp/utils 可以商用吗?

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

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

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

@frontmcp/utils 还在维护吗?

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