@chkp/policy-insights-mcp 0.4.0 → 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";
@@ -1771,7 +1776,96 @@ var SettingsManager = class _SettingsManager {
1771
1776
  };
1772
1777
  SettingsManager.globalDebugState = void 0;
1773
1778
 
1779
+ // ../mcp-utils/dist/telemetry.js
1780
+ import machineIdPkg from "node-machine-id";
1781
+ import { createHash } from "crypto";
1782
+ var { machineIdSync } = machineIdPkg;
1783
+ var machineId = null;
1784
+ var hashedMachineId = null;
1785
+ var transportType = "stdio";
1786
+ function setTransportType(type) {
1787
+ transportType = type;
1788
+ }
1789
+ function isTelemetryDisabled() {
1790
+ return process.env.TELEMETRY_DISABLED === "true" || process.env.TELEMETRY_DISABLED === "1";
1791
+ }
1792
+ function getTelemetryUrl() {
1793
+ return process.env.TELEMETRY_URL || "https://metrics.security.ai.checkpoint.com/api/v1/metrics/collect";
1794
+ }
1795
+ function hashString(input) {
1796
+ return createHash("sha256").update(input).digest("hex");
1797
+ }
1798
+ function getMachineId() {
1799
+ if (!machineId) {
1800
+ try {
1801
+ machineId = machineIdSync();
1802
+ } catch (error) {
1803
+ console.warn("Failed to get machine ID for telemetry:", error);
1804
+ machineId = "unknown";
1805
+ }
1806
+ }
1807
+ return machineId;
1808
+ }
1809
+ function getHashedMachineId() {
1810
+ if (!hashedMachineId) {
1811
+ hashedMachineId = hashString(getMachineId());
1812
+ }
1813
+ return hashedMachineId;
1814
+ }
1815
+ function calculateChecksum(mcpName, toolName, machineId2, clientVersion) {
1816
+ const data = mcpName + machineId2.slice(0, 16) + toolName + clientVersion;
1817
+ return hashString(data);
1818
+ }
1819
+ async function trackToolCall(mcpName, toolName, clientVersion, extra) {
1820
+ if (isTelemetryDisabled()) {
1821
+ return;
1822
+ }
1823
+ try {
1824
+ const machineId2 = getHashedMachineId();
1825
+ const checksum = calculateChecksum(mcpName, toolName, machineId2, clientVersion);
1826
+ fetch(getTelemetryUrl(), {
1827
+ method: "POST",
1828
+ headers: { "Content-Type": "application/json" },
1829
+ body: JSON.stringify({
1830
+ mcp_name: mcpName,
1831
+ tool_name: toolName,
1832
+ machine_id: machineId2,
1833
+ client_version: clientVersion,
1834
+ transport_type: transportType,
1835
+ checksum
1836
+ })
1837
+ }).catch(() => {
1838
+ });
1839
+ } catch (error) {
1840
+ }
1841
+ }
1842
+
1774
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
+ }
1775
1869
  async function launchMCPServer(configPath, serverModule2) {
1776
1870
  const config = JSON.parse(fs.readFileSync(configPath, "utf8"));
1777
1871
  const program = new Command();
@@ -1782,7 +1876,7 @@ async function launchMCPServer(configPath, serverModule2) {
1782
1876
  const envValue = option.env ? process.env[option.env] : void 0;
1783
1877
  const defaultValue = envValue || option.default;
1784
1878
  if (option.type === "boolean") {
1785
- const boolDefault = envValue === "true" || option.default === "true";
1879
+ const boolDefault = booleanOptionDefault(envValue, option.default);
1786
1880
  program.option(option.flag, option.description, boolDefault);
1787
1881
  } else {
1788
1882
  program.option(option.flag, option.description, defaultValue);
@@ -1806,6 +1900,7 @@ async function launchMCPServer(configPath, serverModule2) {
1806
1900
  if (options.telemetryUrl) {
1807
1901
  process.env.TELEMETRY_URL = options.telemetryUrl;
1808
1902
  }
1903
+ mirrorBooleanFlagsToEnv(config, options);
1809
1904
  if (!serverModule2.settingsManager) {
1810
1905
  throw new Error("ServerModule must have a settingsManager. Create it with createServerModule.");
1811
1906
  }
@@ -1814,11 +1909,13 @@ async function launchMCPServer(configPath, serverModule2) {
1814
1909
  console.error("[launchMCPServer] Applying tool policy before connecting");
1815
1910
  serverModule2.server.applyToolPolicy();
1816
1911
  }
1817
- const transportType = (options.transport || process.env.MCP_TRANSPORT_TYPE || "stdio").toLowerCase() === "http" ? "http" : "stdio";
1912
+ const transportType2 = (options.transport || process.env.MCP_TRANSPORT_TYPE || "stdio").toLowerCase() === "http" ? "http" : "stdio";
1818
1913
  const transportPort = options.transportPort ? parseInt(options.transportPort, 10) : process.env.MCP_TRANSPORT_PORT ? parseInt(process.env.MCP_TRANSPORT_PORT, 10) : 3e3;
1819
- if (transportType === "http") {
1914
+ if (transportType2 === "http") {
1915
+ setTransportType("http");
1820
1916
  await launchHTTPServer(config, serverModule2, transportPort);
1821
1917
  } else {
1918
+ setTransportType("stdio");
1822
1919
  const transport = new StdioServerTransport();
1823
1920
  const defaultSessionId = "default";
1824
1921
  const sessionMetadata = {
@@ -2548,10 +2645,11 @@ function wrapServerWithTracking(server2, createServerFn) {
2548
2645
  newServer[reg.method](...reg.args);
2549
2646
  }
2550
2647
  }
2551
- if (typeof server2.setToolPolicy === "function" && typeof newServer.setToolPolicy === "function") {
2552
- const toolPolicy = server2._toolPolicyCallback;
2553
- if (toolPolicy) {
2554
- 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();
2555
2653
  }
2556
2654
  }
2557
2655
  return newServer;
@@ -2590,65 +2688,6 @@ function createServerModule(server2, Settings2, pkg2, apiManagerClass, toolPolic
2590
2688
  // ../mcp-utils/dist/index.js
2591
2689
  init_ui_dialog();
2592
2690
 
2593
- // ../mcp-utils/dist/telemetry.js
2594
- import machineIdPkg from "node-machine-id";
2595
- import { createHash } from "crypto";
2596
- var { machineIdSync } = machineIdPkg;
2597
- var machineId = null;
2598
- var hashedMachineId = null;
2599
- function isTelemetryDisabled() {
2600
- return process.env.TELEMETRY_DISABLED === "true" || process.env.TELEMETRY_DISABLED === "1";
2601
- }
2602
- function getTelemetryUrl() {
2603
- return process.env.TELEMETRY_URL || "https://metrics.security.ai.checkpoint.com/api/v1/metrics/collect";
2604
- }
2605
- function hashString(input) {
2606
- return createHash("sha256").update(input).digest("hex");
2607
- }
2608
- function getMachineId() {
2609
- if (!machineId) {
2610
- try {
2611
- machineId = machineIdSync();
2612
- } catch (error) {
2613
- console.warn("Failed to get machine ID for telemetry:", error);
2614
- machineId = "unknown";
2615
- }
2616
- }
2617
- return machineId;
2618
- }
2619
- function getHashedMachineId() {
2620
- if (!hashedMachineId) {
2621
- hashedMachineId = hashString(getMachineId());
2622
- }
2623
- return hashedMachineId;
2624
- }
2625
- function calculateChecksum(mcpName, toolName, machineId2, clientVersion) {
2626
- const data = mcpName + machineId2.slice(0, 16) + toolName + clientVersion;
2627
- return hashString(data);
2628
- }
2629
- async function trackToolCall(mcpName, toolName, clientVersion, extra) {
2630
- if (isTelemetryDisabled()) {
2631
- return;
2632
- }
2633
- try {
2634
- const machineId2 = getHashedMachineId();
2635
- const checksum = calculateChecksum(mcpName, toolName, machineId2, clientVersion);
2636
- fetch(getTelemetryUrl(), {
2637
- method: "POST",
2638
- headers: { "Content-Type": "application/json" },
2639
- body: JSON.stringify({
2640
- mcp_name: mcpName,
2641
- tool_name: toolName,
2642
- machine_id: machineId2,
2643
- client_version: clientVersion,
2644
- checksum
2645
- })
2646
- }).catch(() => {
2647
- });
2648
- } catch (error) {
2649
- }
2650
- }
2651
-
2652
2691
  // ../mcp-utils/dist/mcp-server.js
2653
2692
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2654
2693
  var CPMcpServer = class extends McpServer {
@@ -2666,35 +2705,61 @@ var CPMcpServer = class extends McpServer {
2666
2705
  console.error("[CPMcpServer] Setting tool policy callback");
2667
2706
  this.toolPolicyCallback = callback;
2668
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
+ }
2669
2719
  /**
2670
2720
  * Apply the tool policy by checking all registered tools
2671
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.
2672
2728
  */
2673
2729
  applyToolPolicy() {
2730
+ const verbose = SettingsManager.globalDebugState === true || SettingsManager.globalDebugState === "true";
2674
2731
  if (!this.toolPolicyCallback) {
2675
- 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
+ }
2676
2735
  return;
2677
2736
  }
2678
- console.error("[CPMcpServer] Applying tool policy");
2679
2737
  const registeredTools = this._registeredTools;
2680
2738
  if (!registeredTools || typeof registeredTools !== "object") {
2681
2739
  console.error("[CPMcpServer] No tools registered yet");
2682
2740
  return;
2683
2741
  }
2684
2742
  const toolNames = Object.keys(registeredTools);
2685
- 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
+ }
2686
2747
  let enabledCount = 0;
2687
2748
  let disabledCount = 0;
2688
2749
  for (const [toolName, tool] of Object.entries(registeredTools)) {
2689
2750
  const isAllowed = this.toolPolicyCallback(toolName);
2690
2751
  if (!isAllowed) {
2691
- 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
+ }
2692
2755
  if (typeof tool.disable === "function") {
2693
2756
  tool.disable();
2694
2757
  disabledCount++;
2695
2758
  }
2696
2759
  } else {
2697
- console.error(`[CPMcpServer] Tool '${toolName}' is allowed by policy`);
2760
+ if (verbose) {
2761
+ console.error(`[CPMcpServer] Tool '${toolName}' is allowed by policy`);
2762
+ }
2698
2763
  enabledCount++;
2699
2764
  }
2700
2765
  }
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chkp/policy-insights-mcp",
3
- "version": "0.4.0",
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.0",
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.0",
3
+ "version": "0.4.3",
4
4
  "bin": {
5
5
  "policy-insights-mcp": "dist/index.js"
6
6
  },