@paretools/shared 0.12.0 → 0.13.1
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/ansi.js +1 -1
- package/dist/ansi.js.map +1 -1
- package/dist/discover-tool.d.ts +19 -0
- package/dist/discover-tool.d.ts.map +1 -0
- package/dist/discover-tool.js +70 -0
- package/dist/discover-tool.js.map +1 -0
- package/dist/index.d.ts +8 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -5
- package/dist/index.js.map +1 -1
- package/dist/lazy-tools.d.ts +44 -0
- package/dist/lazy-tools.d.ts.map +1 -0
- package/dist/lazy-tools.js +54 -0
- package/dist/lazy-tools.js.map +1 -0
- package/dist/output.d.ts +27 -0
- package/dist/output.d.ts.map +1 -1
- package/dist/output.js +43 -0
- package/dist/output.js.map +1 -1
- package/dist/profiles.d.ts +16 -0
- package/dist/profiles.d.ts.map +1 -1
- package/dist/profiles.js +58 -0
- package/dist/profiles.js.map +1 -1
- package/dist/runner.d.ts +31 -5
- package/dist/runner.d.ts.map +1 -1
- package/dist/runner.js +140 -12
- package/dist/runner.js.map +1 -1
- package/dist/server.d.ts +10 -2
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +40 -1
- package/dist/server.js.map +1 -1
- package/dist/strict-input.d.ts +19 -0
- package/dist/strict-input.d.ts.map +1 -0
- package/dist/strict-input.js +59 -0
- package/dist/strict-input.js.map +1 -0
- package/dist/tool-filter.d.ts +12 -0
- package/dist/tool-filter.d.ts.map +1 -1
- package/dist/tool-filter.js +24 -0
- package/dist/tool-filter.js.map +1 -1
- package/dist/validation.d.ts +8 -0
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +17 -0
- package/dist/validation.js.map +1 -1
- package/dist/version.d.ts +16 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +42 -0
- package/dist/version.js.map +1 -0
- package/package.json +3 -3
package/dist/runner.js
CHANGED
|
@@ -1,6 +1,49 @@
|
|
|
1
1
|
import { spawn, execFileSync } from "node:child_process";
|
|
2
|
+
import { normalize } from "node:path";
|
|
2
3
|
import { stripAnsi } from "./ansi.js";
|
|
3
4
|
import { sanitizeErrorOutput } from "./sanitize.js";
|
|
5
|
+
/**
|
|
6
|
+
* Resolves a command name to its absolute path using `where` (Windows) or
|
|
7
|
+
* `which` (Unix). On Windows this is used to detect whether a command is a
|
|
8
|
+
* .cmd/.bat wrapper so the runner can invoke it via cmd.exe without using
|
|
9
|
+
* `shell: true` (which triggers CodeQL alert #16).
|
|
10
|
+
*
|
|
11
|
+
* Returns the original command string if resolution fails (e.g., the command
|
|
12
|
+
* is already an absolute path, or `which`/`where` is unavailable).
|
|
13
|
+
*/
|
|
14
|
+
function resolveCommand(cmd) {
|
|
15
|
+
// Skip resolution if cmd is already an absolute path
|
|
16
|
+
if (cmd.startsWith("/") || /^[A-Za-z]:[/\\]/.test(cmd)) {
|
|
17
|
+
return cmd;
|
|
18
|
+
}
|
|
19
|
+
try {
|
|
20
|
+
const resolver = process.platform === "win32" ? "where" : "which";
|
|
21
|
+
const output = execFileSync(resolver, [cmd], {
|
|
22
|
+
timeout: 5_000,
|
|
23
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
24
|
+
windowsHide: true,
|
|
25
|
+
}).toString("utf-8");
|
|
26
|
+
const lines = output
|
|
27
|
+
.split(/\r?\n/)
|
|
28
|
+
.map((l) => l.trim())
|
|
29
|
+
.filter(Boolean);
|
|
30
|
+
if (process.platform === "win32" && lines.length > 1) {
|
|
31
|
+
// On Windows, `where` returns multiple matches (e.g., `npx` and `npx.cmd`).
|
|
32
|
+
// Prefer .cmd/.bat entries so _buildSpawnConfig routes them through the
|
|
33
|
+
// cmd.exe wrapper path (Branch 2) instead of trying to execute an
|
|
34
|
+
// extensionless shell script with shell: false (which would fail).
|
|
35
|
+
const cmdLine = lines.find((l) => /\.(cmd|bat)$/i.test(l));
|
|
36
|
+
if (cmdLine)
|
|
37
|
+
return cmdLine;
|
|
38
|
+
}
|
|
39
|
+
return lines[0] || cmd;
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
// Resolution failed — fall back to the bare command name so existing
|
|
43
|
+
// behavior (PATH lookup by the shell/OS) is preserved.
|
|
44
|
+
return cmd;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
4
47
|
/**
|
|
5
48
|
* Kills an entire process group (Unix) or process tree (Windows).
|
|
6
49
|
*
|
|
@@ -87,32 +130,117 @@ export function escapeCmdArg(arg) {
|
|
|
87
130
|
escaped = escaped.replace(/!/g, "^!");
|
|
88
131
|
return escaped;
|
|
89
132
|
}
|
|
133
|
+
// ---------------------------------------------------------------------------
|
|
134
|
+
// Verbatim-mode escaping helpers (cross-spawn pattern)
|
|
135
|
+
//
|
|
136
|
+
// These are used when spawning .cmd/.bat files via cmd.exe with
|
|
137
|
+
// windowsVerbatimArguments: true, where libuv performs NO quoting.
|
|
138
|
+
// Algorithm ported from cross-spawn (https://github.com/moxystudio/node-cross-spawn).
|
|
139
|
+
// ---------------------------------------------------------------------------
|
|
140
|
+
/** cmd.exe metacharacters that need caret-escaping. */
|
|
141
|
+
const META_CHARS_RE = /([()\][%!^"`<>&|;, *?])/g;
|
|
142
|
+
/** Caret-escape cmd.exe metacharacters in a command path. */
|
|
143
|
+
function escapeCommandForVerbatim(cmd) {
|
|
144
|
+
return cmd.replace(META_CHARS_RE, "^$1");
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Escapes a single argument for cmd.exe in windowsVerbatimArguments mode.
|
|
148
|
+
*
|
|
149
|
+
* Based on https://qntm.org/cmd (same algorithm as cross-spawn):
|
|
150
|
+
* 1. Handle backslash+quote sequences for MSVC C runtime parsing
|
|
151
|
+
* 2. Wrap in double quotes
|
|
152
|
+
* 3. Caret-escape cmd.exe metacharacters on the quoted result
|
|
153
|
+
*/
|
|
154
|
+
function escapeArgForVerbatim(arg) {
|
|
155
|
+
// Sequence of backslashes followed by a double quote:
|
|
156
|
+
// double up all the backslashes and escape the double quote.
|
|
157
|
+
// The outer `?` makes the capture group optional so bare `"` (zero
|
|
158
|
+
// preceding backslashes) is also matched — matching cross-spawn exactly.
|
|
159
|
+
let escaped = arg.replace(/(?=(\\+?)?)\1"/g, '$1$1\\"');
|
|
160
|
+
// Sequence of backslashes at end of string (will be followed by our closing quote):
|
|
161
|
+
// double up all the backslashes
|
|
162
|
+
escaped = escaped.replace(/(?=(\\+?)?)\1$/, "$1$1");
|
|
163
|
+
// Wrap in double quotes, then caret-escape metacharacters
|
|
164
|
+
escaped = `"${escaped}"`;
|
|
165
|
+
escaped = escaped.replace(META_CHARS_RE, "^$1");
|
|
166
|
+
return escaped;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Determines how to spawn a command, handling Windows .cmd/.bat wrappers
|
|
170
|
+
* without using `shell: true` (which triggers CodeQL alert #16).
|
|
171
|
+
*
|
|
172
|
+
* @internal — Exported for unit testing only. Use `run()` instead.
|
|
173
|
+
*
|
|
174
|
+
* Branches:
|
|
175
|
+
* 1. Explicit `shell: true` — pass cmd directly, don't resolve (caller wants shell features)
|
|
176
|
+
* 2. Windows native .exe/.com — spawn resolved path directly
|
|
177
|
+
* 3. Windows non-exe (cmd/bat/extensionless/bare) — cmd.exe /d /s /c with windowsVerbatimArguments
|
|
178
|
+
* 4. Unix — spawn cmd directly, execvp handles PATH
|
|
179
|
+
*/
|
|
180
|
+
export function _buildSpawnConfig(cmd, args, opts, platform = process.platform, resolver = resolveCommand) {
|
|
181
|
+
// Branch 1: Explicit shell: true — caller wants shell features (pipes, globs).
|
|
182
|
+
// Pass cmd directly to spawn with shell: true — do NOT call resolveCommand,
|
|
183
|
+
// which breaks the taint flow that CodeQL flags (environment → shell command).
|
|
184
|
+
if (opts?.shell === true) {
|
|
185
|
+
const safeArgs = platform === "win32" ? args.map(escapeCmdArg) : args;
|
|
186
|
+
return { command: cmd, args: safeArgs, shell: true, windowsVerbatimArguments: false };
|
|
187
|
+
}
|
|
188
|
+
// Branches 2+3: Windows without shell
|
|
189
|
+
if (platform === "win32") {
|
|
190
|
+
const resolved = resolver(cmd);
|
|
191
|
+
// Branch 2: Native .exe/.com — spawn resolved path directly.
|
|
192
|
+
// Only these extensions are true PE executables that CreateProcessW can run
|
|
193
|
+
// without a shell. This matches cross-spawn's isExecutableRegExp check.
|
|
194
|
+
if (/\.(exe|com)$/i.test(resolved)) {
|
|
195
|
+
return { command: resolved, args, shell: false, windowsVerbatimArguments: false };
|
|
196
|
+
}
|
|
197
|
+
// Branch 3: Everything else (.cmd, .bat, extensionless, bare names) needs
|
|
198
|
+
// cmd.exe to interpret it. Use cross-spawn pattern:
|
|
199
|
+
// cmd.exe /d /s /c "escaped-command escaped-args"
|
|
200
|
+
// with windowsVerbatimArguments: true so libuv doesn't re-quote.
|
|
201
|
+
// shell: false ensures resolveCommand output never enters a shell command
|
|
202
|
+
// string from Node's perspective — satisfying CodeQL.
|
|
203
|
+
// Normalize posix slashes to Windows backslashes (cross-spawn does this too).
|
|
204
|
+
const normalizedCmd = normalize(resolved);
|
|
205
|
+
const escapedParts = [
|
|
206
|
+
escapeCommandForVerbatim(normalizedCmd),
|
|
207
|
+
...args.map((a) => escapeArgForVerbatim(a)),
|
|
208
|
+
];
|
|
209
|
+
return {
|
|
210
|
+
command: "cmd.exe",
|
|
211
|
+
args: ["/d", "/s", "/c", `"${escapedParts.join(" ")}"`],
|
|
212
|
+
shell: false,
|
|
213
|
+
windowsVerbatimArguments: true,
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
// Branch 4: Unix — spawn cmd directly with shell: false.
|
|
217
|
+
// execvp handles PATH lookup natively, no resolution needed.
|
|
218
|
+
return { command: cmd, args, shell: false, windowsVerbatimArguments: false };
|
|
219
|
+
}
|
|
90
220
|
/**
|
|
91
221
|
* Executes a command and returns cleaned output with ANSI codes stripped.
|
|
92
222
|
* Uses spawn (not exec) to avoid shell injection. The child is spawned in its
|
|
93
223
|
* own process group (`detached: true` on Unix) so that on timeout we can kill
|
|
94
224
|
* the entire group — preventing orphaned grandchild processes.
|
|
95
225
|
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
226
|
+
* Shell mode defaults to `false` on all platforms. On Windows, .cmd/.bat
|
|
227
|
+
* wrappers (like npm, npx) are automatically handled via cmd.exe invocation
|
|
228
|
+
* with windowsVerbatimArguments (cross-spawn pattern), avoiding shell injection.
|
|
229
|
+
*
|
|
230
|
+
* Callers can opt in to `shell: true` for shell features (pipes, globs),
|
|
231
|
+
* but this bypasses security protections — use only with trusted input.
|
|
98
232
|
*
|
|
99
233
|
* Throws on system-level errors (command not found, permission denied, timeout).
|
|
100
234
|
* Normal non-zero exit codes are returned in the result, not thrown.
|
|
101
235
|
*/
|
|
102
236
|
export function run(cmd, args, opts) {
|
|
103
237
|
return new Promise((resolve, reject) => {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
// mangling format strings that contain < > characters).
|
|
107
|
-
const useShell = opts?.shell ?? process.platform === "win32";
|
|
108
|
-
// On Windows with shell mode, escape cmd.exe metacharacters to prevent
|
|
109
|
-
// environment variable expansion and command injection via special chars.
|
|
110
|
-
// See escapeCmdArg() for details on what is escaped and why.
|
|
111
|
-
const safeArgs = useShell && process.platform === "win32" ? args.map(escapeCmdArg) : args;
|
|
112
|
-
const child = spawn(cmd, safeArgs, {
|
|
238
|
+
const config = _buildSpawnConfig(cmd, args, { shell: opts?.shell });
|
|
239
|
+
const child = spawn(config.command, config.args, {
|
|
113
240
|
cwd: opts?.cwd,
|
|
114
241
|
env: opts?.env ? (opts.replaceEnv ? opts.env : { ...process.env, ...opts.env }) : undefined,
|
|
115
|
-
shell:
|
|
242
|
+
shell: config.shell,
|
|
243
|
+
windowsVerbatimArguments: config.windowsVerbatimArguments,
|
|
116
244
|
// Unix: creates a new process group via setsid(2) so we can kill the
|
|
117
245
|
// entire group on timeout (prevents orphaned grandchild processes).
|
|
118
246
|
// Windows: skip — detached on Windows creates a visible console window,
|
package/dist/runner.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runner.js","sourceRoot":"","sources":["../src/runner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"runner.js","sourceRoot":"","sources":["../src/runner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAEpD;;;;;;;;GAQG;AACH,SAAS,cAAc,CAAC,GAAW;IACjC,qDAAqD;IACrD,IAAI,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,iBAAiB,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;QACvD,OAAO,GAAG,CAAC;IACb,CAAC;IACD,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC;QAClE,MAAM,MAAM,GAAG,YAAY,CAAC,QAAQ,EAAE,CAAC,GAAG,CAAC,EAAE;YAC3C,OAAO,EAAE,KAAK;YACd,KAAK,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,CAAC;YACnC,WAAW,EAAE,IAAI;SAClB,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QAErB,MAAM,KAAK,GAAG,MAAM;aACjB,KAAK,CAAC,OAAO,CAAC;aACd,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,C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S,yBAAyB,CAClF,CACF,CAAC;gBACF,OAAO;YACT,CAAC;YAED,4DAA4D;YAC5D,IAAI,IAAI,KAAK,CAAC,IAAI,MAAM,CAAC,QAAQ,CAAC,mBAAmB,CAAC,EAAE,CAAC;gBACvD,MAAM,CACJ,IAAI,KAAK,CACP,uBAAuB,GAAG,uDAAuD,CAClF,CACF,CAAC;gBACF,OAAO;YACT,CAAC;YAED,OAAO,CAAC;gBACN,QAAQ,EAAE,IAAI,IAAI,CAAC;gBACnB,MAAM;gBACN,MAAM;gBACN,GAAG,CAAC,iBAAiB,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,iBAAiB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBACjE,GAAG,CAAC,mBAAmB,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,mBAAmB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aACtE,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,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"}
|
package/dist/server.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import { type LazyToolManager } from "./lazy-tools.js";
|
|
2
3
|
export interface CreateServerOptions {
|
|
3
4
|
/** Package name, e.g. "@paretools/git" */
|
|
4
5
|
name: string;
|
|
@@ -6,8 +7,15 @@ export interface CreateServerOptions {
|
|
|
6
7
|
version: string;
|
|
7
8
|
/** Human-readable server instructions for MCP clients */
|
|
8
9
|
instructions: string;
|
|
9
|
-
/**
|
|
10
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Callback that registers all tools on the server.
|
|
12
|
+
*
|
|
13
|
+
* When lazy mode is active (`PARE_LAZY=true`), the second argument is a
|
|
14
|
+
* `LazyToolManager` that the callback can use to defer non-core tools.
|
|
15
|
+
* When lazy mode is off, the second argument is `undefined` and all tools
|
|
16
|
+
* should be registered directly.
|
|
17
|
+
*/
|
|
18
|
+
registerTools: (server: McpServer, lazyManager?: LazyToolManager) => void;
|
|
11
19
|
}
|
|
12
20
|
/**
|
|
13
21
|
* Creates an MCP server with the standard Pare boilerplate:
|
package/dist/server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAQpE,OAAO,EAAyB,KAAK,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAI9E,MAAM,WAAW,mBAAmB;IAClC,0CAA0C;IAC1C,IAAI,EAAE,MAAM,CAAC;IACb,oCAAoC;IACpC,OAAO,EAAE,MAAM,CAAC;IAChB,yDAAyD;IACzD,YAAY,EAAE,MAAM,CAAC;IACrB;;;;;;;OAOG;IACH,aAAa,EAAE,CAAC,MAAM,EAAE,SAAS,EAAE,WAAW,CAAC,EAAE,eAAe,KAAK,IAAI,CAAC;CAC3E;AA0BD;;;;;GAKG;AACH,wBAAsB,YAAY,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,SAAS,CAAC,CA0BnF"}
|
package/dist/server.js
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
2
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
3
|
+
import { ErrorCode, ListResourcesRequestSchema, McpError, ReadResourceRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
|
|
4
|
+
import { createLazyToolManager } from "./lazy-tools.js";
|
|
5
|
+
import { isLazyEnabled } from "./tool-filter.js";
|
|
6
|
+
import { strictifyInputSchema } from "./strict-input.js";
|
|
7
|
+
/**
|
|
8
|
+
* Wraps an McpServer so that every `registerTool` call automatically applies
|
|
9
|
+
* strict input validation (rejects unknown parameters) to the tool's
|
|
10
|
+
* inputSchema. This prevents AI agents from silently passing wrong-but-
|
|
11
|
+
* plausible parameter names (e.g. `branch` instead of `ref`).
|
|
12
|
+
*/
|
|
13
|
+
function applyStrictInputSchemas(server) {
|
|
14
|
+
const original = server.registerTool.bind(server);
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
16
|
+
server.registerTool = function (...args) {
|
|
17
|
+
// The config-based overload: registerTool(name, config, callback)
|
|
18
|
+
// config is always the second argument and contains inputSchema
|
|
19
|
+
if (args.length >= 2 && typeof args[1] === "object" && args[1] !== null) {
|
|
20
|
+
const config = args[1];
|
|
21
|
+
if (config.inputSchema) {
|
|
22
|
+
config.inputSchema = strictifyInputSchema(config.inputSchema);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
26
|
+
return original(...args);
|
|
27
|
+
};
|
|
28
|
+
}
|
|
3
29
|
/**
|
|
4
30
|
* Creates an MCP server with the standard Pare boilerplate:
|
|
5
31
|
* instantiates McpServer, registers tools via callback, connects StdioServerTransport.
|
|
@@ -9,7 +35,20 @@ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"
|
|
|
9
35
|
export async function createServer(options) {
|
|
10
36
|
const { name, version, instructions, registerTools } = options;
|
|
11
37
|
const server = new McpServer({ name, version }, { instructions });
|
|
12
|
-
|
|
38
|
+
applyStrictInputSchemas(server);
|
|
39
|
+
const lazy = isLazyEnabled();
|
|
40
|
+
const lazyManager = lazy ? createLazyToolManager(server) : undefined;
|
|
41
|
+
registerTools(server, lazyManager);
|
|
42
|
+
// Pare servers are tool-only and register no resources. Some MCP clients
|
|
43
|
+
// (e.g. OpenCode) fire `resources/read` after every structured tool call,
|
|
44
|
+
// which causes a -32603 InternalError because no resource handler exists.
|
|
45
|
+
// Register stub handlers so those requests receive a clean -32602 response
|
|
46
|
+
// ("Resource not found") instead of the confusing generic error.
|
|
47
|
+
server.server.registerCapabilities({ resources: {} });
|
|
48
|
+
server.server.setRequestHandler(ListResourcesRequestSchema, () => ({ resources: [] }));
|
|
49
|
+
server.server.setRequestHandler(ReadResourceRequestSchema, (request) => {
|
|
50
|
+
throw new McpError(ErrorCode.InvalidParams, `Resource not found: ${request.params.uri}`);
|
|
51
|
+
});
|
|
13
52
|
const transport = new StdioServerTransport();
|
|
14
53
|
await server.connect(transport);
|
|
15
54
|
return server;
|
package/dist/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EACL,SAAS,EACT,0BAA0B,EAC1B,QAAQ,EACR,yBAAyB,GAC1B,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,qBAAqB,EAAwB,MAAM,iBAAiB,CAAC;AAC9E,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAoBzD;;;;;GAKG;AACH,SAAS,uBAAuB,CAAC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EAAE,SAAS,EAAE,EAAE,EAAE,CAAC,CAAC;IACtD,MAAM,CAAC,MAAM,CAAC,iBAAiB,CAAC,0BAA0B,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;IACvF,MAAM,CAAC,MAAM,CAAC,iBAAiB,CAAC,yBAAyB,EAAE,CAAC,OAAO,EAAE,EAAE;QACrE,MAAM,IAAI,QAAQ,CAAC,SAAS,CAAC,aAAa,EAAE,uBAAuB,OAAO,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC;IAC3F,CAAC,CAAC,CAAC;IAEH,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;IAC7C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAEhC,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a raw Zod shape (used as `inputSchema` in tool registration) into
|
|
3
|
+
* a strict Zod object schema that rejects unrecognized properties.
|
|
4
|
+
*
|
|
5
|
+
* By default the MCP SDK wraps raw shapes with `z.object(shape)` which
|
|
6
|
+
* silently strips unknown keys. This causes confusing errors when an AI agent
|
|
7
|
+
* passes a wrong-but-plausible parameter name (e.g. `branch` instead of `ref`).
|
|
8
|
+
*
|
|
9
|
+
* Applying `z.strictObject(shape)` instead causes validation to fail with a
|
|
10
|
+
* clear error message listing the unrecognized key.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* If `schema` is a raw Zod shape, wraps it in `z.strictObject()` so that
|
|
14
|
+
* unknown parameters are rejected during validation. If the schema is already
|
|
15
|
+
* a Zod schema instance, applies `.strict()` if it's an object schema.
|
|
16
|
+
* Otherwise returns the schema unchanged.
|
|
17
|
+
*/
|
|
18
|
+
export declare function strictifyInputSchema<T>(schema: T): T;
|
|
19
|
+
//# sourceMappingURL=strict-input.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strict-input.d.ts","sourceRoot":"","sources":["../src/strict-input.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AA2BH;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,GAAG,CAAC,CAiBpD"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a raw Zod shape (used as `inputSchema` in tool registration) into
|
|
3
|
+
* a strict Zod object schema that rejects unrecognized properties.
|
|
4
|
+
*
|
|
5
|
+
* By default the MCP SDK wraps raw shapes with `z.object(shape)` which
|
|
6
|
+
* silently strips unknown keys. This causes confusing errors when an AI agent
|
|
7
|
+
* passes a wrong-but-plausible parameter name (e.g. `branch` instead of `ref`).
|
|
8
|
+
*
|
|
9
|
+
* Applying `z.strictObject(shape)` instead causes validation to fail with a
|
|
10
|
+
* clear error message listing the unrecognized key.
|
|
11
|
+
*/
|
|
12
|
+
import { z } from "zod";
|
|
13
|
+
/**
|
|
14
|
+
* Checks whether a value is a Zod schema instance (has `_zod` for v4).
|
|
15
|
+
*/
|
|
16
|
+
function isZodSchema(value) {
|
|
17
|
+
return typeof value === "object" && value !== null && ("_zod" in value || "_def" in value);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Checks whether a value is a "raw shape" — a plain object whose values are
|
|
21
|
+
* Zod schemas. This is the shorthand form used by all Pare tools:
|
|
22
|
+
* `{ path: z.string(), maxCount: z.number() }`.
|
|
23
|
+
*/
|
|
24
|
+
function isRawShape(value) {
|
|
25
|
+
if (typeof value !== "object" || value === null)
|
|
26
|
+
return false;
|
|
27
|
+
// If it's already a Zod schema instance, it's NOT a raw shape
|
|
28
|
+
if (isZodSchema(value))
|
|
29
|
+
return false;
|
|
30
|
+
const entries = Object.values(value);
|
|
31
|
+
// Empty shape is valid (tools with no parameters)
|
|
32
|
+
if (entries.length === 0)
|
|
33
|
+
return true;
|
|
34
|
+
// A raw shape has values that are Zod schemas
|
|
35
|
+
return entries.some((v) => isZodSchema(v));
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* If `schema` is a raw Zod shape, wraps it in `z.strictObject()` so that
|
|
39
|
+
* unknown parameters are rejected during validation. If the schema is already
|
|
40
|
+
* a Zod schema instance, applies `.strict()` if it's an object schema.
|
|
41
|
+
* Otherwise returns the schema unchanged.
|
|
42
|
+
*/
|
|
43
|
+
export function strictifyInputSchema(schema) {
|
|
44
|
+
if (!schema)
|
|
45
|
+
return schema;
|
|
46
|
+
if (isRawShape(schema)) {
|
|
47
|
+
// Convert raw shape to strict object schema.
|
|
48
|
+
// The MCP SDK's normalizeObjectSchema will recognize this as a pre-built
|
|
49
|
+
// Zod v4 schema and use it directly instead of wrapping in z.object().
|
|
50
|
+
return z.strictObject(schema);
|
|
51
|
+
}
|
|
52
|
+
// If it's already a Zod object schema, apply .strict()
|
|
53
|
+
const schemaObj = schema;
|
|
54
|
+
if (isZodSchema(schema) && typeof schemaObj.strict === "function") {
|
|
55
|
+
return schemaObj.strict();
|
|
56
|
+
}
|
|
57
|
+
return schema;
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=strict-input.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strict-input.js","sourceRoot":"","sources":["../src/strict-input.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;GAEG;AACH,SAAS,WAAW,CAAC,KAAc;IACjC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,MAAM,IAAI,KAAK,IAAI,MAAM,IAAI,KAAK,CAAC,CAAC;AAC7F,CAAC;AAED;;;;GAIG;AACH,SAAS,UAAU,CAAC,KAAc;IAChC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,KAAK,CAAC;IAC9D,8DAA8D;IAC9D,IAAI,WAAW,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IACrC,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACrC,kDAAkD;IAClD,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IACtC,8CAA8C;IAC9C,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;AAC7C,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB,CAAI,MAAS;IAC/C,IAAI,CAAC,MAAM;QAAE,OAAO,MAAM,CAAC;IAE3B,IAAI,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;QACvB,6CAA6C;QAC7C,yEAAyE;QACzE,uEAAuE;QACvE,OAAO,CAAC,CAAC,YAAY,CAAC,MAAmC,CAAiB,CAAC;IAC7E,CAAC;IAED,uDAAuD;IACvD,MAAM,SAAS,GAAG,MAAiC,CAAC;IACpD,IAAI,WAAW,CAAC,MAAM,CAAC,IAAI,OAAO,SAAS,CAAC,MAAM,KAAK,UAAU,EAAE,CAAC;QAClE,OAAQ,SAAS,CAAC,MAAwB,EAAO,CAAC;IACpD,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/dist/tool-filter.d.ts
CHANGED
|
@@ -22,6 +22,18 @@
|
|
|
22
22
|
*/
|
|
23
23
|
import { _resetProfileCache } from "./profiles.js";
|
|
24
24
|
export { _resetProfileCache };
|
|
25
|
+
/**
|
|
26
|
+
* Returns `true` when lazy tool loading is enabled.
|
|
27
|
+
*
|
|
28
|
+
* Lazy mode is activated by setting `PARE_LAZY=true` (case-insensitive).
|
|
29
|
+
* When active, only core tools are registered at startup; extended tools
|
|
30
|
+
* are deferred and discoverable via the `discover-tools` meta-tool.
|
|
31
|
+
*
|
|
32
|
+
* Lazy mode is NOT active when `PARE_PROFILE=full` is explicitly set,
|
|
33
|
+
* or when any explicit tool filter (`PARE_TOOLS`, `PARE_{SERVER}_TOOLS`)
|
|
34
|
+
* is in use — those filters already provide precise control.
|
|
35
|
+
*/
|
|
36
|
+
export declare function isLazyEnabled(): boolean;
|
|
25
37
|
/**
|
|
26
38
|
* Determines whether a tool should be registered based on environment variables.
|
|
27
39
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-filter.d.ts","sourceRoot":"","sources":["../src/tool-filter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAkB,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAEnE,OAAO,EAAE,kBAAkB,EAAE,CAAC;AAE9B;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CA0BhF"}
|
|
1
|
+
{"version":3,"file":"tool-filter.d.ts","sourceRoot":"","sources":["../src/tool-filter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAkB,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAEnE,OAAO,EAAE,kBAAkB,EAAE,CAAC;AAE9B;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,IAAI,OAAO,CAWvC;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CA0BhF"}
|
package/dist/tool-filter.js
CHANGED
|
@@ -22,6 +22,30 @@
|
|
|
22
22
|
*/
|
|
23
23
|
import { resolveProfile, _resetProfileCache } from "./profiles.js";
|
|
24
24
|
export { _resetProfileCache };
|
|
25
|
+
/**
|
|
26
|
+
* Returns `true` when lazy tool loading is enabled.
|
|
27
|
+
*
|
|
28
|
+
* Lazy mode is activated by setting `PARE_LAZY=true` (case-insensitive).
|
|
29
|
+
* When active, only core tools are registered at startup; extended tools
|
|
30
|
+
* are deferred and discoverable via the `discover-tools` meta-tool.
|
|
31
|
+
*
|
|
32
|
+
* Lazy mode is NOT active when `PARE_PROFILE=full` is explicitly set,
|
|
33
|
+
* or when any explicit tool filter (`PARE_TOOLS`, `PARE_{SERVER}_TOOLS`)
|
|
34
|
+
* is in use — those filters already provide precise control.
|
|
35
|
+
*/
|
|
36
|
+
export function isLazyEnabled() {
|
|
37
|
+
// Explicit tool filters take precedence — no lazy behavior.
|
|
38
|
+
if (process.env.PARE_TOOLS !== undefined)
|
|
39
|
+
return false;
|
|
40
|
+
// Explicit "full" profile means load everything.
|
|
41
|
+
const profile = process.env.PARE_PROFILE;
|
|
42
|
+
if (profile !== undefined && profile.trim().toLowerCase() === "full")
|
|
43
|
+
return false;
|
|
44
|
+
const raw = process.env.PARE_LAZY;
|
|
45
|
+
if (raw === undefined)
|
|
46
|
+
return false;
|
|
47
|
+
return raw.trim().toLowerCase() === "true";
|
|
48
|
+
}
|
|
25
49
|
/**
|
|
26
50
|
* Determines whether a tool should be registered based on environment variables.
|
|
27
51
|
*
|
package/dist/tool-filter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-filter.js","sourceRoot":"","sources":["../src/tool-filter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAEnE,OAAO,EAAE,kBAAkB,EAAE,CAAC;AAE9B;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAAC,UAAkB,EAAE,QAAgB;IACrE,qDAAqD;IACrD,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,M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AM,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,2BAA2B;IAC3B,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/dist/validation.d.ts
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Preprocess function for Zod schemas that coerces a JSON string to an array.
|
|
3
|
+
* Handles the case where MCP clients serialize array parameters as JSON strings
|
|
4
|
+
* before the tool schema is fully loaded.
|
|
5
|
+
*
|
|
6
|
+
* Usage: `z.preprocess(coerceJsonArray, z.array(z.string()))`
|
|
7
|
+
*/
|
|
8
|
+
export declare function coerceJsonArray(val: unknown): unknown;
|
|
1
9
|
/**
|
|
2
10
|
* Validates that a string argument is safe to pass as a positional argument to a CLI tool.
|
|
3
11
|
* Prevents flag injection attacks (e.g., passing "--output=/etc/passwd" as a ref name).
|
package/dist/validation.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../src/validation.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CAM5E;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CAMzE;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CASzE;AAiCD;;;;;;;;;;;;GAYG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAwB1D"}
|
|
1
|
+
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../src/validation.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAOrD;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CAM5E;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CAMzE;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CASzE;AAiCD;;;;;;;;;;;;GAYG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAwB1D"}
|
package/dist/validation.js
CHANGED
|
@@ -1,3 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Preprocess function for Zod schemas that coerces a JSON string to an array.
|
|
3
|
+
* Handles the case where MCP clients serialize array parameters as JSON strings
|
|
4
|
+
* before the tool schema is fully loaded.
|
|
5
|
+
*
|
|
6
|
+
* Usage: `z.preprocess(coerceJsonArray, z.array(z.string()))`
|
|
7
|
+
*/
|
|
8
|
+
export function coerceJsonArray(val) {
|
|
9
|
+
if (typeof val !== "string")
|
|
10
|
+
return val;
|
|
11
|
+
try {
|
|
12
|
+
return JSON.parse(val);
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
return val;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
1
18
|
/**
|
|
2
19
|
* Validates that a string argument is safe to pass as a positional argument to a CLI tool.
|
|
3
20
|
* Prevents flag injection attacks (e.g., passing "--output=/etc/passwd" as a ref name).
|
package/dist/validation.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validation.js","sourceRoot":"","sources":["../src/validation.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,UAAU,qBAAqB,CAAC,KAAa,EAAE,SAAiB;IACpE,IAAI,KAAK,CAAC,SAAS,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QACtC,MAAM,IAAI,KAAK,CACb,WAAW,SAAS,MAAM,KAAK,kEAAkE,CAClG,CAAC;IACJ,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAa,EAAE,SAAiB;IACjE,IAAI,CAAC,8BAA8B,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QAChD,MAAM,IAAI,KAAK,CACb,WAAW,SAAS,MAAM,KAAK,yDAAyD,CACzF,CAAC;IACJ,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAa,EAAE,SAAiB;IACjE,MAAM,MAAM,GAAG,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAClD,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,IAAI,CAAC,0BAA0B,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;YAC5C,MAAM,IAAI,KAAK,CACb,WAAW,SAAS,YAAY,KAAK,kEAAkE,CACxG,CAAC;QACJ,CAAC;IACH,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,sBAAsB,GAAG,IAAI,GAAG,CAAC;IACrC,KAAK;IACL,KAAK;IACL,MAA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AAS;IACT,QAAQ;IACR,OAAO;IACP,IAAI;IACJ,OAAO;CACR,CAAC,CAAC;AAEH;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,oBAAoB,CAAC,OAAe;IAClD,+EAA+E;IAC/E,MAAM,IAAI,GACR,OAAO;SACJ,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC;SACnB,KAAK,CAAC,GAAG,CAAC;SACV,GAAG,EAAE;QACN,EAAE,OAAO,CAAC,sBAAsB,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC;IAEhD,IAAI,CAAC,sBAAsB,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;QACtC,MAAM,IAAI,KAAK,CACb,YAAY,OAAO,+CAA+C;YAChE,YAAY,CAAC,GAAG,sBAAsB,CAAC,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAC9D,CAAC;IACJ,CAAC;IAED,2FAA2F;IAC3F,IAAI,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;QACpD,OAAO,CAAC,IAAI,CACV,8CAA8C,OAAO,KAAK;YACxD,sBAAsB,IAAI,yCAAyC;YACnE,8CAA8C,CACjD,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reads the `version` field from the nearest `package.json` relative to
|
|
3
|
+
* the calling module's `import.meta.url`.
|
|
4
|
+
*
|
|
5
|
+
* Walks up directory tree from the given module URL until it finds a
|
|
6
|
+
* `package.json` with a `version` field, or returns `"0.0.0"` as a
|
|
7
|
+
* fallback.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { readPackageVersion } from "@paretools/shared";
|
|
12
|
+
* const version = readPackageVersion(import.meta.url);
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export declare function readPackageVersion(importMetaUrl: string): string;
|
|
16
|
+
//# sourceMappingURL=version.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;GAaG;AACH,wBAAgB,kBAAkB,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,CAwBhE"}
|
package/dist/version.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
/**
|
|
5
|
+
* Reads the `version` field from the nearest `package.json` relative to
|
|
6
|
+
* the calling module's `import.meta.url`.
|
|
7
|
+
*
|
|
8
|
+
* Walks up directory tree from the given module URL until it finds a
|
|
9
|
+
* `package.json` with a `version` field, or returns `"0.0.0"` as a
|
|
10
|
+
* fallback.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { readPackageVersion } from "@paretools/shared";
|
|
15
|
+
* const version = readPackageVersion(import.meta.url);
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export function readPackageVersion(importMetaUrl) {
|
|
19
|
+
let dir = dirname(fileURLToPath(importMetaUrl));
|
|
20
|
+
// Walk up to find the nearest package.json with a version field
|
|
21
|
+
for (;;) {
|
|
22
|
+
try {
|
|
23
|
+
const pkgPath = join(dir, "package.json");
|
|
24
|
+
const raw = readFileSync(pkgPath, "utf-8");
|
|
25
|
+
const pkg = JSON.parse(raw);
|
|
26
|
+
if (pkg.version) {
|
|
27
|
+
return pkg.version;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
// No package.json in this directory, keep walking up
|
|
32
|
+
}
|
|
33
|
+
const parent = dirname(dir);
|
|
34
|
+
if (parent === dir) {
|
|
35
|
+
// Reached filesystem root
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
dir = parent;
|
|
39
|
+
}
|
|
40
|
+
return "0.0.0";
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=version.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,kBAAkB,CAAC,aAAqB;IACtD,IAAI,GAAG,GAAG,OAAO,CAAC,aAAa,CAAC,aAAa,CAAC,CAAC,CAAC;IAEhD,gEAAgE;IAChE,SAAS,CAAC;QACR,IAAI,CAAC;YACH,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC;YAC1C,MAAM,GAAG,GAAG,YAAY,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YAC3C,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAyB,CAAC;YACpD,IAAI,GAAG,CAAC,OAAO,EAAE,CAAC;gBAChB,OAAO,GAAG,CAAC,OAAO,CAAC;YACrB,CAAC;QACH,CAAC;QAAC,MAAM,CAAC;YACP,qDAAqD;QACvD,CAAC;QACD,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;QAC5B,IAAI,MAAM,KAAK,GAAG,EAAE,CAAC;YACnB,0BAA0B;YAC1B,MAAM;QACR,CAAC;QACD,GAAG,GAAG,MAAM,CAAC;IACf,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@paretools/shared",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.1",
|
|
4
4
|
"description": "Shared utilities for Pare MCP servers",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
@@ -40,11 +40,11 @@
|
|
|
40
40
|
"dist"
|
|
41
41
|
],
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@modelcontextprotocol/sdk": "^1.
|
|
43
|
+
"@modelcontextprotocol/sdk": "^1.27.1",
|
|
44
44
|
"zod": "^4.3.6"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@types/node": "^25.
|
|
47
|
+
"@types/node": "^25.3.3",
|
|
48
48
|
"typescript": "^5.7.0",
|
|
49
49
|
"vitest": "^4.0.18",
|
|
50
50
|
"@paretools/tsconfig": "0.0.0"
|