@chkp/mcp-utils

中文文档
1.6.2发布于 2026/11/08MITTypeScriptES Module构建来源已验证近 30 天下载 1.7万

Shared utilities for Check Point MCP servers

原始使用文档
文档目录18 节
  1. Features
  2. Configuration-Driven MCP Server Launcher
  3. Usage
  4. 1. Create a Server Configuration File
  5. 2. Update Your Server's Main Function
  6. 3. Add Dependency
  7. Configuration Schema
  8. ServerConfig
  9. CliOption
  10. HTTP Transport
  11. Starting the server in HTTP mode
  12. Connecting an MCP client
  13. Error Reporting
  14. Opting in to a better message or code
  15. Error codes
  16. Spotting unflagged failures
  17. Benefits
  18. Migration Example

@chkp/mcp-utils

Shared utilities for Check Point MCP servers.

Features

Configuration-Driven MCP Server Launcher

The launchMCPServer function provides a configuration-driven approach to launching MCP servers, eliminating boilerplate code and making CLI options maintainable through JSON configuration files.

Usage

1. Create a Server Configuration File

Create a server-config.json file in your server package:

{
  "name": "My MCP Server",
  "description": "Description of my MCP server",
  "options": [
    {
      "flag": "--api-key <key>",
      "description": "API key for authentication",
      "env": "API_KEY",
      "type": "string"
    },
    {
      "flag": "--host <host>",
      "description": "Server host",
      "env": "SERVER_HOST",
      "default": "localhost",
      "type": "string"
    },
    {
      "flag": "--verbose",
      "description": "Enable verbose output",
      "env": "VERBOSE",
      "type": "boolean"
    }
  ]
}

2. Update Your Server's Main Function

Replace your manual CLI setup with the launcher:

import { launchMCPServer } from '@chkp/mcp-utils';
import { join, dirname } from 'path';
import { fileURLToPath } from 'url';

// Your existing server, Settings, and pkg imports...

const main = async () => {
  await launchMCPServer(
    join(dirname(fileURLToPath(import.meta.url)), 'server-config.json'),
    { server, Settings, pkg }
  );
};

main().catch((error) => {
  console.error('Fatal error in main():', error);
  process.exit(1);
});

3. Add Dependency

Add @chkp/mcp-utils to your package.json:

{
  "dependencies": {
    "@chkp/mcp-utils": "*"
  }
}

Configuration Schema

ServerConfig

  • name (string): Display name for the server
  • description (string, optional): Description shown in help text
  • options (CliOption[]): Array of CLI options

CliOption

  • flag (string): Commander.js-style flag definition (e.g., --api-key <key>, --verbose)
  • description (string): Help text for the option
  • env (string, optional): Environment variable name to read default from
  • default (string, optional): Default value if not provided via CLI or env
  • type ('string' | 'boolean', optional): Option type (defaults to 'string')

HTTP Transport

By default, servers launched with launchMCPServer use stdio transport, which is the standard mode for MCP clients like Claude Desktop and Cursor. For hosted or multi-user deployments, an HTTP transport (MCP Streamable HTTP) is also available.

Security notice before you continue: The HTTP server has no built-in authentication and no TLS. Any client that can reach the port can establish a session, and credentials travel in cleartext. Only use HTTP transport behind an authenticated reverse proxy (nginx, Caddy, a cloud load balancer) that terminates TLS and enforces authentication. If you are running the server on the same machine as your MCP client, use the default stdio transport — it has none of these concerns.

Starting the server in HTTP mode

MCP_TRANSPORT_TYPE=http MCP_TRANSPORT_PORT=3000 my-mcp-server
# or
my-mcp-server --transport http --transport-port 3000

The server exposes:

  • POST/GET/DELETE /mcp — MCP protocol endpoint
  • GET /health — server status (active session count, version)

HTTP request bodies are limited to 4 MiB by default. Set MCP_MAX_HTTP_BODY_BYTES to a positive integer to change the limit (for example, 8388608 for 8 MiB). Requests exceeding it receive HTTP 413, including requests sent with chunked transfer encoding. The limit is enforced while reading, before JSON parsing or session creation. An empty value uses the default; other invalid values fail HTTP startup. To let clients receive the rejection while uploading, the server discards up to four times the body limit (at most 32 MiB) or waits at most one second before closing the rejected connection.

For both stdio and HTTP, request parameters are checked before tool-schema validation: arrays and objects may contain at most 10,000 items/properties, with at most 100,000 values and 64 nesting levels across the parameters. Oversized calls to registered, enabled tools return isError: true with VALIDATION_ERROR and record a failed telemetry event when telemetry is enabled, without executing the tool. Unknown or disabled tools retain the SDK's usual rejection without logging or reporting their requested names through this guard. Other request methods receive a protocol-level invalid-parameters error. These shared limits also cover generated tools and nested collections; individual tool schemas may impose smaller limits.

Connecting an MCP client

Point your MCP client at http://<host>:3000/mcp. Example for Claude Desktop (claude_desktop_config.json):

{
  "mcpServers": {
    "my-server": {
      "url": "http://localhost:3000/mcp"
    }
  }
}

Error Reporting

One rule, and CPMcpServer enforces it for you:

A failure must either be thrown, or already be a correctly-shaped isError result. Never return a failure as a plain value.

You do not need to write error handling for your tools to be correct. Every tool is wrapped, whether you register it with registerTool() or the older tool(). Anything you throw — an HTTP failure, a missing file, a SQLite error, a failed subprocess, a Zod validation error, a plain Error — is converted into a spec-compliant result with isError: true and a stable error_code, and reported to telemetry as a failure. Prompts and resources are wrapped the same way, through either method name. A handler that simply lets errors propagate is doing the right thing:

server.tool('my_tool', 'does a thing', { id: z.string() }, async (args, extra) => {
  const resp = await runApi('POST', 'show-thing', { uid: args.id }, extra);
  return { content: [{ type: 'text', text: JSON.stringify(resp) }] };
});

Do not write this — it makes a failed call look successful, which is exactly what the wrapper exists to prevent:

// ANTI-PATTERN: no isError, so callers and telemetry both see a success.
try {
  ...
} catch (error) {
  return { content: [{ type: 'text', text: `Error: ${error.message}` }] };
}

Opting in to a better message or code

Catch only when you can add something the classifier cannot infer — the operation's context, or a more specific code:

import { McpErrorCode, toolError, toolErrorFrom, McpToolError } from '@chkp/mcp-utils';

// Keep your context, and get a classified code for free.
catch (error) {
  return toolErrorFrom(error, 'Failed to parse rulebase');
}

// Or state the code yourself, with extra context for programmatic callers.
return toolError(McpErrorCode.OPERATION_FAILED, `Simulation failed: ${detail}`, {
  retryable: false,
  details: { task },
});

// From a client or helper, throw so every caller benefits.
throw new McpToolError(McpErrorCode.AUTH_FAILED, 'API key rejected', {
  upstreamStatus: 401,
});

Error codes

AUTH_FAILED, PERMISSION_DENIED, NOT_FOUND, VALIDATION_ERROR, RATE_LIMITED, TIMEOUT, UPSTREAM_UNREACHABLE, UPSTREAM_ERROR, RESOURCE_UNAVAILABLE, OPERATION_FAILED, INTERNAL.

Codes are cause-agnostic on purpose: they describe what went wrong for the caller, not which subsystem produced it. An error result looks like this:

{
  "isError": true,
  "content": [{ "type": "text", "text": "NOT_FOUND: Could not reach your Management" }],
  "structuredContent": {
    "error_code": "NOT_FOUND",
    "error_message": "Could not reach your Management",
    "upstream_status": 404,
    "retryable": false
  }
}

Spotting unflagged failures

Run a server with CP_MCP_STRICT_ERRORS=true to log a warning whenever a tool returns a result that is not flagged as an error but looks like one. It is a heuristic and never changes behaviour — it just points at handlers worth a second look during development.

Benefits

  • Consistent Error Reporting: Tool failures are flagged and coded centrally, without per-package work
  • Zero Boilerplate: Reduces main function from ~15 lines to ~5 lines
  • Configuration-Driven: All CLI options in maintainable JSON files
  • Environment Variable Support: Automatic mapping of env vars to options
  • Type Safety: TypeScript interfaces for all configuration
  • Consistent Help: Automatic help text generation
  • Easy Maintenance: Change options without touching code

Migration Example

Before:

const main = async () => {
  const program = new Command();
  program
    .option('--api-key <key>', 'API key')
    .option('--host <host>', 'Server host', process.env.SERVER_HOST || 'localhost')
    .option('--verbose', 'Enable verbose output', process.env.VERBOSE === 'true');
  program.parse(process.argv);
  const options = program.opts();
  Settings.setSettings(Settings.fromArgs(options));
  const transport = new StdioServerTransport();
  await server.connect(transport);
  console.error('Server running...');
};

After:

const main = async () => {
  await launchMCPServer(
    join(dirname(fileURLToPath(import.meta.url)), 'server-config.json'),
    { server, Settings, pkg }
  );
};

版本与发布记录

@chkp/mcp-utils 共发布 13 个版本,首次发布于 2025/07/17;过去 12 个月发布了 9 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.6.2latest2026/11/081 天前
1.6.12026/11/027 天前
1.4.02026/10/2514 天前
1.3.32026/10/051 个月前
1.3.12026/08/202 个月前
1.3.02026/04/067 个月前

关于 @chkp/mcp-utils 的常见问题

@chkp/mcp-utils 是什么?

Shared utilities for Check Point MCP servers

如何安装 @chkp/mcp-utils?

在项目目录运行 npm install @chkp/mcp-utils,或使用 pnpm add / yarn add / bun add。

@chkp/mcp-utils 支持 TypeScript 吗?

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

@chkp/mcp-utils 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@chkp/mcp-utils 需要什么版本的 Node.js?

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

@chkp/mcp-utils 可以商用吗?

@chkp/mcp-utils 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@chkp/mcp-utils 的下载量有多少?

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

@chkp/mcp-utils 还在维护吗?

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