@paretools/shared 0.6.0 → 0.8.0

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.d.ts CHANGED
@@ -4,5 +4,6 @@ export { stripAnsi } from "./ansi.js";
4
4
  export { assertNoFlagInjection, assertAllowedCommand } from "./validation.js";
5
5
  export { INPUT_LIMITS } from "./limits.js";
6
6
  export { sanitizeErrorOutput } from "./sanitize.js";
7
+ export { shouldRegisterTool } from "./tool-filter.js";
7
8
  export type { ToolOutput } from "./types.js";
8
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAC5E,OAAO,EAAE,GAAG,EAAE,YAAY,EAAE,KAAK,SAAS,EAAE,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC;AACjF,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAC9E,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACpD,YAAY,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAC5E,OAAO,EAAE,GAAG,EAAE,YAAY,EAAE,KAAK,SAAS,EAAE,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC;AACjF,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAC9E,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,YAAY,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC"}
package/dist/index.js CHANGED
@@ -4,4 +4,5 @@ export { stripAnsi } from "./ansi.js";
4
4
  export { assertNoFlagInjection, assertAllowedCommand } from "./validation.js";
5
5
  export { INPUT_LIMITS } from "./limits.js";
6
6
  export { sanitizeErrorOutput } from "./sanitize.js";
7
+ export { shouldRegisterTool } from "./tool-filter.js";
7
8
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAC5E,OAAO,EAAE,GAAG,EAAE,YAAY,EAAmC,MAAM,aAAa,CAAC;AACjF,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAC9E,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAC5E,OAAO,EAAE,GAAG,EAAE,YAAY,EAAmC,MAAM,aAAa,CAAC;AACjF,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAC9E,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC"}
package/dist/runner.d.ts CHANGED
@@ -3,6 +3,14 @@ export interface RunOptions {
3
3
  cwd?: string;
4
4
  timeout?: number;
5
5
  env?: Record<string, string>;
6
+ /** Data to write to the child process's stdin. Useful for piping content
7
+ * (e.g., `git commit --file -`) instead of passing it as a command arg,
8
+ * which avoids cmd.exe argument-length and newline limitations on Windows. */
9
+ stdin?: string;
10
+ /** Override shell mode. Defaults to `true` on Windows (for .cmd/.bat wrappers)
11
+ * and `false` elsewhere. Set to `false` for native executables (e.g., git)
12
+ * whose args contain characters that cmd.exe would misinterpret (like `<>`). */
13
+ shell?: boolean;
6
14
  }
7
15
  /** Result of a command execution, containing the exit code and ANSI-stripped stdout/stderr. */
8
16
  export interface RunResult {
@@ -13,19 +21,21 @@ export interface RunResult {
13
21
  /**
14
22
  * Escapes a single argument for safe use with cmd.exe on Windows.
15
23
  *
16
- * When `shell: true` is used with `execFile` on Windows, Node.js wraps each
17
- * argument in double quotes. Inside double quotes cmd.exe still interprets:
18
- * - `%VAR%` for environment variable expansion
19
- * - `^` as the escape character itself
20
- * - `&`, `|`, `<`, `>` as pipeline / redirection operators
24
+ * When `shell: true` is used with `execFile` on Windows, Node.js joins the
25
+ * command and args with spaces to build a cmd.exe command line. It does NOT
26
+ * automatically quote individual arguments, so args containing spaces would
27
+ * be split into multiple tokens by cmd.exe.
21
28
  *
22
- * We neutralise these by:
23
- * 1. Replacing `%` with `%%` (disables env-var expansion inside quotes).
24
- * 2. Prefixing `^`, `&`, `|`, `<`, `>`, `!` with the cmd.exe escape char `^`.
25
- * (`!` must be escaped to prevent delayed expansion of `!VAR!`.)
29
+ * Strategy:
30
+ * - Args with spaces, tabs, or double quotes are wrapped in double quotes.
31
+ * Inside double quotes cmd.exe treats `&`, `|`, `<`, `>`, `^` as literal,
32
+ * so only `%` needs escaping (`%%`). Internal `"` chars are doubled (`""`).
33
+ * - Args without spaces are left unquoted, with cmd.exe metacharacters
34
+ * escaped via the caret (`^`) prefix.
35
+ * - `%` → `%%` is applied unconditionally (active in both quoted/unquoted).
26
36
  *
27
- * Parentheses `(` `)` are NOT escaped here because inside double-quoted
28
- * strings they are literal characters and do not affect grouping.
37
+ * Parentheses `(` `)` are NOT escaped because inside double-quoted strings
38
+ * they are literal, and outside quotes they rarely appear in tool args.
29
39
  */
30
40
  export declare function escapeCmdArg(arg: string): string;
31
41
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../src/runner.ts"],"names":[],"mappings":"AAIA,uGAAuG;AACvG,MAAM,WAAW,UAAU;IACzB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC9B;AAED,+FAA+F;AAC/F,MAAM,WAAW,SAAS;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAiBhD;AAED;;;;;;;;GAQG;AACH,wBAAgB,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,IAAI,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,SAAS,CAAC,CAkEtF"}
1
+ {"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../src/runner.ts"],"names":[],"mappings":"AAIA,uGAAuG;AACvG,MAAM,WAAW,UAAU;IACzB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B;;mFAE+E;IAC/E,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;qFAEiF;IACjF,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,+FAA+F;AAC/F,MAAM,WAAW,SAAS;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAqChD;AAED;;;;;;;;GAQG;AACH,wBAAgB,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,IAAI,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,SAAS,CAAC,CA8EtF"}
package/dist/runner.js CHANGED
@@ -4,26 +4,47 @@ import { sanitizeErrorOutput } from "./sanitize.js";
4
4
  /**
5
5
  * Escapes a single argument for safe use with cmd.exe on Windows.
6
6
  *
7
- * When `shell: true` is used with `execFile` on Windows, Node.js wraps each
8
- * argument in double quotes. Inside double quotes cmd.exe still interprets:
9
- * - `%VAR%` for environment variable expansion
10
- * - `^` as the escape character itself
11
- * - `&`, `|`, `<`, `>` as pipeline / redirection operators
7
+ * When `shell: true` is used with `execFile` on Windows, Node.js joins the
8
+ * command and args with spaces to build a cmd.exe command line. It does NOT
9
+ * automatically quote individual arguments, so args containing spaces would
10
+ * be split into multiple tokens by cmd.exe.
12
11
  *
13
- * We neutralise these by:
14
- * 1. Replacing `%` with `%%` (disables env-var expansion inside quotes).
15
- * 2. Prefixing `^`, `&`, `|`, `<`, `>`, `!` with the cmd.exe escape char `^`.
16
- * (`!` must be escaped to prevent delayed expansion of `!VAR!`.)
12
+ * Strategy:
13
+ * - Args with spaces, tabs, or double quotes are wrapped in double quotes.
14
+ * Inside double quotes cmd.exe treats `&`, `|`, `<`, `>`, `^` as literal,
15
+ * so only `%` needs escaping (`%%`). Internal `"` chars are doubled (`""`).
16
+ * - Args without spaces are left unquoted, with cmd.exe metacharacters
17
+ * escaped via the caret (`^`) prefix.
18
+ * - `%` → `%%` is applied unconditionally (active in both quoted/unquoted).
17
19
  *
18
- * Parentheses `(` `)` are NOT escaped here because inside double-quoted
19
- * strings they are literal characters and do not affect grouping.
20
+ * Parentheses `(` `)` are NOT escaped because inside double-quoted strings
21
+ * they are literal, and outside quotes they rarely appear in tool args.
20
22
  */
21
23
  export function escapeCmdArg(arg) {
22
- // Step 1: Escape % → %% to prevent %VAR% expansion
23
- let escaped = arg.replace(/%/g, "%%");
24
- // Step 2: Caret-escape cmd.exe metacharacters that are dangerous
25
- // even inside double quotes. The caret itself must be escaped first
26
- // so that carets we insert are not themselves re-escaped.
24
+ // NOTE: We intentionally do NOT escape % → %%. While % starts environment
25
+ // variable expansion in cmd.exe (%VAR%), the %% escape only works in batch
26
+ // files. When Node.js uses `shell: true`, it runs via `cmd.exe /d /s /c`
27
+ // which is NOT batch context — so %% passes through literally as two %
28
+ // characters. This breaks tools like git that use % in format strings
29
+ // (e.g., --format=%H), because git interprets %% as its own escape for
30
+ // literal %. User-provided text that might contain %VAR% patterns should
31
+ // be passed via stdin (e.g., git commit --file -) rather than as args.
32
+ let escaped = arg;
33
+ // Step 1: If the arg contains spaces, tabs, or double quotes, wrap it in
34
+ // double quotes so cmd.exe keeps it as a single token.
35
+ if (/[ \t"]/.test(arg)) {
36
+ // Replace newlines with spaces — cmd.exe treats \n as a command-line
37
+ // terminator even inside double quotes, so literal newlines cannot be
38
+ // passed via command args. Tools that need newline-preserving input
39
+ // should use RunOptions.stdin instead (e.g., git commit --file -).
40
+ escaped = escaped.replace(/\r?\n/g, " ");
41
+ // Escape internal double quotes by doubling them
42
+ escaped = escaped.replace(/"/g, '""');
43
+ return `"${escaped}"`;
44
+ }
45
+ // Step 2: For unquoted args, caret-escape cmd.exe metacharacters.
46
+ // The caret itself must be escaped first so that carets we insert
47
+ // are not themselves re-escaped.
27
48
  escaped = escaped.replace(/\^/g, "^^");
28
49
  escaped = escaped.replace(/&/g, "^&");
29
50
  escaped = escaped.replace(/\|/g, "^|");
@@ -44,16 +65,20 @@ export function escapeCmdArg(arg) {
44
65
  */
45
66
  export function run(cmd, args, opts) {
46
67
  return new Promise((resolve, reject) => {
68
+ // Determine shell mode: default to true on Windows (for .cmd/.bat wrappers),
69
+ // but allow callers to override (e.g., git uses shell:false to avoid cmd.exe
70
+ // mangling format strings that contain < > characters).
71
+ const useShell = opts?.shell ?? process.platform === "win32";
47
72
  // On Windows with shell mode, escape cmd.exe metacharacters to prevent
48
73
  // environment variable expansion and command injection via special chars.
49
74
  // See escapeCmdArg() for details on what is escaped and why.
50
- const safeArgs = process.platform === "win32" ? args.map(escapeCmdArg) : args;
51
- execFile(cmd, safeArgs, {
75
+ const safeArgs = useShell && process.platform === "win32" ? args.map(escapeCmdArg) : args;
76
+ const child = execFile(cmd, safeArgs, {
52
77
  cwd: opts?.cwd,
53
78
  timeout: opts?.timeout ?? 60_000,
54
79
  env: opts?.env ? { ...process.env, ...opts.env } : undefined,
55
80
  maxBuffer: 10 * 1024 * 1024, // 10 MB
56
- shell: process.platform === "win32",
81
+ shell: useShell,
57
82
  }, (error, stdout, stderr) => {
58
83
  if (error) {
59
84
  const errno = error;
@@ -85,6 +110,12 @@ export function run(cmd, args, opts) {
85
110
  stderr: sanitizeErrorOutput(stripAnsi(stderr)),
86
111
  });
87
112
  });
113
+ // Pipe stdin data if provided, then close the stream so the child
114
+ // process knows input is complete (e.g., `git commit --file -`).
115
+ if (opts?.stdin != null) {
116
+ child.stdin?.write(opts.stdin);
117
+ child.stdin?.end();
118
+ }
88
119
  });
89
120
  }
90
121
  //# sourceMappingURL=runner.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"runner.js","sourceRoot":"","sources":["../src/runner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAA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CAAC,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;gBACvE,MAAM,EAAE,SAAS,CAAC,MAAM,CAAC;gBACzB,MAAM,EAAE,mBAAmB,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;aAC/C,CAAC,CAAC;QACL,CAAC,CACF,CAAC;QAEF,kEAAkE;QAClE,iEAAiE;QACjE,IAAI,IAAI,EAAE,KAAK,IAAI,IAAI,EAAE,CAAC;YACxB,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAC/B,KAAK,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC;QACrB,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Granular tool selection — allows users to enable/disable individual tools
3
+ * via environment variables.
4
+ *
5
+ * Environment variable precedence:
6
+ * 1. `PARE_TOOLS` — universal filter across all servers.
7
+ * Format: comma-separated `server:tool` pairs.
8
+ * Example: `PARE_TOOLS=git:status,git:log,npm:install`
9
+ *
10
+ * 2. `PARE_{SERVER}_TOOLS` — per-server filter.
11
+ * Format: comma-separated tool names.
12
+ * Example: `PARE_GIT_TOOLS=status,log`
13
+ *
14
+ * 3. No env vars → all tools enabled (default).
15
+ *
16
+ * Universal (`PARE_TOOLS`) takes precedence over per-server env vars.
17
+ */
18
+ /**
19
+ * Determines whether a tool should be registered based on environment variables.
20
+ *
21
+ * @param serverName - The server identifier (e.g., "git", "npm", "docker").
22
+ * @param toolName - The tool name (e.g., "status", "log", "install").
23
+ * @returns `true` if the tool should be registered, `false` if filtered out.
24
+ */
25
+ export declare function shouldRegisterTool(serverName: string, toolName: string): boolean;
26
+ //# sourceMappingURL=tool-filter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-filter.d.ts","sourceRoot":"","sources":["../src/tool-filter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAiBhF"}
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Granular tool selection — allows users to enable/disable individual tools
3
+ * via environment variables.
4
+ *
5
+ * Environment variable precedence:
6
+ * 1. `PARE_TOOLS` — universal filter across all servers.
7
+ * Format: comma-separated `server:tool` pairs.
8
+ * Example: `PARE_TOOLS=git:status,git:log,npm:install`
9
+ *
10
+ * 2. `PARE_{SERVER}_TOOLS` — per-server filter.
11
+ * Format: comma-separated tool names.
12
+ * Example: `PARE_GIT_TOOLS=status,log`
13
+ *
14
+ * 3. No env vars → all tools enabled (default).
15
+ *
16
+ * Universal (`PARE_TOOLS`) takes precedence over per-server env vars.
17
+ */
18
+ /**
19
+ * Determines whether a tool should be registered based on environment variables.
20
+ *
21
+ * @param serverName - The server identifier (e.g., "git", "npm", "docker").
22
+ * @param toolName - The tool name (e.g., "status", "log", "install").
23
+ * @returns `true` if the tool should be registered, `false` if filtered out.
24
+ */
25
+ export function shouldRegisterTool(serverName, toolName) {
26
+ const universal = process.env.PARE_TOOLS;
27
+ if (universal !== undefined) {
28
+ if (universal.trim() === "")
29
+ return false;
30
+ const allowed = universal.split(",").map((s) => s.trim());
31
+ return allowed.includes(`${serverName}:${toolName}`);
32
+ }
33
+ const envKey = `PARE_${serverName.toUpperCase().replace(/-/g, "_")}_TOOLS`;
34
+ const perServer = process.env[envKey];
35
+ if (perServer !== undefined) {
36
+ if (perServer.trim() === "")
37
+ return false;
38
+ const allowed = perServer.split(",").map((s) => s.trim());
39
+ return allowed.includes(toolName);
40
+ }
41
+ return true;
42
+ }
43
+ //# sourceMappingURL=tool-filter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-filter.js","sourceRoot":"","sources":["../src/tool-filter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAAC,UAAkB,EAAE,QAAgB;IACrE,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC;IACzC,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;QAC5B,IAAI,SAAS,CAAC,IAAI,EAAE,KAAK,EAAE;YAAE,OAAO,KAAK,CAAC;QAC1C,MAAM,OAAO,GAAG,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;QAC1D,OAAO,OAAO,CAAC,QAAQ,CAAC,GAAG,UAAU,IAAI,QAAQ,EAAE,CAAC,CAAC;IACvD,CAAC;IAED,MAAM,MAAM,GAAG,QAAQ,UAAU,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,QAAQ,CAAC;IAC3E,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IACtC,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;QAC5B,IAAI,SAAS,CAAC,IAAI,EAAE,KAAK,EAAE;YAAE,OAAO,KAAK,CAAC;QAC1C,MAAM,OAAO,GAAG,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;QAC1D,OAAO,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IACpC,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paretools/shared",
3
- "version": "0.6.0",
3
+ "version": "0.8.0",
4
4
  "description": "Shared utilities for Pare MCP servers",
5
5
  "license": "MIT",
6
6
  "keywords": [