@chkp/policy-insights-mcp 0.4.1 → 0.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1606,6 +1606,11 @@ function sanitizeData(kwargs) {
1606
1606
  return data;
1607
1607
  }
1608
1608
 
1609
+ // ../mcp-utils/dist/cli-options.js
1610
+ function booleanOptionDefault(envValue, optionDefault) {
1611
+ return envValue === "true" || optionDefault === "true";
1612
+ }
1613
+
1609
1614
  // ../mcp-utils/dist/launcher.js
1610
1615
  import { Command } from "commander";
1611
1616
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
@@ -1836,6 +1841,31 @@ async function trackToolCall(mcpName, toolName, clientVersion, extra) {
1836
1841
  }
1837
1842
 
1838
1843
  // ../mcp-utils/dist/launcher.js
1844
+ function optionKey(flag) {
1845
+ const long = flag.split(/[,\s]+/).find((part) => part.startsWith("--"));
1846
+ if (!long)
1847
+ return void 0;
1848
+ const negated = long.startsWith("--no-");
1849
+ return {
1850
+ key: long.replace(/^--(no-)?/, "").replace(/-([a-z])/g, (_match, char) => char.toUpperCase()),
1851
+ negated
1852
+ };
1853
+ }
1854
+ function mirrorBooleanFlagsToEnv(config, options) {
1855
+ for (const option of config.options) {
1856
+ if (option.type !== "boolean" || !option.env)
1857
+ continue;
1858
+ const derived = optionKey(option.flag);
1859
+ if (!derived)
1860
+ continue;
1861
+ if (derived.negated) {
1862
+ throw new Error(`Option '${option.flag}' in the configuration for '${config.name}' is a negatable flag paired with env var '${option.env}', which cannot be mirrored automatically: commander keys it as '${derived.key}' and inverts its meaning, so whether the flag being present should set '${option.env}' to 'true' or 'false' depends on how that variable is named. Mirror it explicitly in launchMCPServer instead, the way --no-telemetry does for TELEMETRY_DISABLED.`);
1863
+ }
1864
+ if (options[derived.key] === true) {
1865
+ process.env[option.env] = "true";
1866
+ }
1867
+ }
1868
+ }
1839
1869
  async function launchMCPServer(configPath, serverModule2) {
1840
1870
  const config = JSON.parse(fs.readFileSync(configPath, "utf8"));
1841
1871
  const program = new Command();
@@ -1846,7 +1876,7 @@ async function launchMCPServer(configPath, serverModule2) {
1846
1876
  const envValue = option.env ? process.env[option.env] : void 0;
1847
1877
  const defaultValue = envValue || option.default;
1848
1878
  if (option.type === "boolean") {
1849
- const boolDefault = envValue === "true" || option.default === "true";
1879
+ const boolDefault = booleanOptionDefault(envValue, option.default);
1850
1880
  program.option(option.flag, option.description, boolDefault);
1851
1881
  } else {
1852
1882
  program.option(option.flag, option.description, defaultValue);
@@ -1870,6 +1900,7 @@ async function launchMCPServer(configPath, serverModule2) {
1870
1900
  if (options.telemetryUrl) {
1871
1901
  process.env.TELEMETRY_URL = options.telemetryUrl;
1872
1902
  }
1903
+ mirrorBooleanFlagsToEnv(config, options);
1873
1904
  if (!serverModule2.settingsManager) {
1874
1905
  throw new Error("ServerModule must have a settingsManager. Create it with createServerModule.");
1875
1906
  }
@@ -2614,10 +2645,11 @@ function wrapServerWithTracking(server2, createServerFn) {
2614
2645
  newServer[reg.method](...reg.args);
2615
2646
  }
2616
2647
  }
2617
- if (typeof server2.setToolPolicy === "function" && typeof newServer.setToolPolicy === "function") {
2618
- const toolPolicy = server2._toolPolicyCallback;
2619
- if (toolPolicy) {
2620
- newServer.setToolPolicy(toolPolicy);
2648
+ const toolPolicy = typeof server2.getToolPolicy === "function" ? server2.getToolPolicy() : void 0;
2649
+ if (toolPolicy && typeof newServer.setToolPolicy === "function") {
2650
+ newServer.setToolPolicy(toolPolicy);
2651
+ if (typeof newServer.applyToolPolicy === "function") {
2652
+ newServer.applyToolPolicy();
2621
2653
  }
2622
2654
  }
2623
2655
  return newServer;
@@ -2673,35 +2705,61 @@ var CPMcpServer = class extends McpServer {
2673
2705
  console.error("[CPMcpServer] Setting tool policy callback");
2674
2706
  this.toolPolicyCallback = callback;
2675
2707
  }
2708
+ /**
2709
+ * Get the tool policy callback, if one was set.
2710
+ *
2711
+ * Needed so the policy can be carried onto the per-session server instances
2712
+ * created for HTTP transport. A typed accessor keeps that transfer honest:
2713
+ * callers do not have to reach into the private field, where a misspelling
2714
+ * would go unnoticed by the compiler.
2715
+ */
2716
+ getToolPolicy() {
2717
+ return this.toolPolicyCallback;
2718
+ }
2676
2719
  /**
2677
2720
  * Apply the tool policy by checking all registered tools
2678
2721
  * This should be called after all tools are registered but before connecting
2722
+ *
2723
+ * Per-tool tracing is behind the debug flag. This used to run once per process
2724
+ * on the template server, where a line per tool was a cheap startup banner.
2725
+ * It now also runs per session under HTTP transport, so unconditional tracing
2726
+ * would scale stderr with sessions x tools and bury the summary. The summary
2727
+ * line always prints — it is the fact worth having for every session.
2679
2728
  */
2680
2729
  applyToolPolicy() {
2730
+ const verbose = SettingsManager.globalDebugState === true || SettingsManager.globalDebugState === "true";
2681
2731
  if (!this.toolPolicyCallback) {
2682
- console.error("[CPMcpServer] No tool policy callback set, allowing all tools");
2732
+ if (verbose) {
2733
+ console.error("[CPMcpServer] No tool policy callback set, allowing all tools");
2734
+ }
2683
2735
  return;
2684
2736
  }
2685
- console.error("[CPMcpServer] Applying tool policy");
2686
2737
  const registeredTools = this._registeredTools;
2687
2738
  if (!registeredTools || typeof registeredTools !== "object") {
2688
2739
  console.error("[CPMcpServer] No tools registered yet");
2689
2740
  return;
2690
2741
  }
2691
2742
  const toolNames = Object.keys(registeredTools);
2692
- console.error(`[CPMcpServer] Found ${toolNames.length} registered tools:`, toolNames);
2743
+ if (verbose) {
2744
+ console.error(`[CPMcpServer] Applying tool policy`);
2745
+ console.error(`[CPMcpServer] Found ${toolNames.length} registered tools:`, toolNames);
2746
+ }
2693
2747
  let enabledCount = 0;
2694
2748
  let disabledCount = 0;
2695
2749
  for (const [toolName, tool] of Object.entries(registeredTools)) {
2696
2750
  const isAllowed = this.toolPolicyCallback(toolName);
2697
2751
  if (!isAllowed) {
2698
- console.error(`[CPMcpServer] Tool '${toolName}' is NOT allowed by policy - disabling`);
2752
+ if (verbose) {
2753
+ console.error(`[CPMcpServer] Tool '${toolName}' is NOT allowed by policy - disabling`);
2754
+ }
2699
2755
  if (typeof tool.disable === "function") {
2700
2756
  tool.disable();
2701
2757
  disabledCount++;
2702
2758
  }
2703
2759
  } else {
2704
- console.error(`[CPMcpServer] Tool '${toolName}' is allowed by policy`);
2760
+ if (verbose) {
2761
+ console.error(`[CPMcpServer] Tool '${toolName}' is allowed by policy`);
2762
+ }
2705
2763
  enabledCount++;
2706
2764
  }
2707
2765
  }
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chkp/policy-insights-mcp",
3
- "version": "0.4.1",
3
+ "version": "0.4.3",
4
4
  "bin": {
5
5
  "policy-insights-mcp": "dist/index.js"
6
6
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chkp/policy-insights-mcp",
3
- "version": "0.4.1",
3
+ "version": "0.4.3",
4
4
  "bin": {
5
5
  "policy-insights-mcp": "dist/index.js"
6
6
  },
package/package.json.bak CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chkp/policy-insights-mcp",
3
- "version": "0.4.1",
3
+ "version": "0.4.3",
4
4
  "bin": {
5
5
  "policy-insights-mcp": "dist/index.js"
6
6
  },