toolscript-mcp 1.0.2 → 1.0.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/README.md +8 -2
- package/dist/host/main.js +145 -32
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -115,6 +115,8 @@ and prints the client changes. Use [Client setup](#client-setup) for Codex or a
|
|
|
115
115
|
To update, run `npx -y toolscript-mcp@latest --help` and restart your client. If your client entry pins a version,
|
|
116
116
|
change the version in that entry before you restart.
|
|
117
117
|
|
|
118
|
+
Questions about setup, the demo, approval prompts or a failed check? Read the [FAQ](FAQ.md).
|
|
119
|
+
|
|
118
120
|
#### Move an existing clone setup to npm
|
|
119
121
|
|
|
120
122
|
1. Find the config path in the existing client entry. If it uses the default path, keep that default.
|
|
@@ -430,7 +432,7 @@ usage error.
|
|
|
430
432
|
|
|
431
433
|
After the tools, `tools` prints an `allow` command for each tool that the policy asks for. The command follows the
|
|
432
434
|
rules of `init --list` for names and paths. A tool whose name has another character gets no command. The block names
|
|
433
|
-
the rule that
|
|
435
|
+
the rule that refuses a tool that a deny rule matches or an ask rule names. The last command allows all such
|
|
434
436
|
`read-only` tools:
|
|
435
437
|
|
|
436
438
|
```
|
|
@@ -444,7 +446,11 @@ in the policy:
|
|
|
444
446
|
|
|
445
447
|
- Each tool is `mcp__<server>__<tool>`, with a server key of the config. The tool part has only letters, digits and
|
|
446
448
|
`. _ -`. For any other name, `allow` exits 2 and changes nothing.
|
|
447
|
-
-
|
|
449
|
+
- `allow` never loosens a deny rule or an ask rule. It refuses a tool that the policy does not allow now if a deny
|
|
450
|
+
rule matches it or an ask rule names it. It prints `refused:` with the rule and the edit to make by hand, writes
|
|
451
|
+
nothing and exits 2.
|
|
452
|
+
If the run names other tools too, it writes nothing for them. It prints the command with `--apply` for the tools
|
|
453
|
+
that it can add.
|
|
448
454
|
- A tool that the policy allows now gets no new rule. An allow rule with the exact name below an earlier rule moves
|
|
449
455
|
to the top.
|
|
450
456
|
- Without `--apply`, `allow` writes nothing. It shows the new policy and the command with `--apply` that writes it.
|
package/dist/host/main.js
CHANGED
|
@@ -18252,13 +18252,26 @@ var allowRefusal = (tool, keys) => {
|
|
|
18252
18252
|
};
|
|
18253
18253
|
var planAllow = (policy, bridges, tools) => {
|
|
18254
18254
|
const steps2 = [...new Set(tools)].map((tool) => {
|
|
18255
|
-
const deny = policy.find((r) => r.action === "deny" && matches(r.match, tool));
|
|
18256
|
-
if (deny !== void 0) return { tool, kind: "keep", why: `the deny rule ${ruleText(deny)} stays` };
|
|
18257
|
-
const ask = policy.find((r) => r.action === "ask" && r.match === tool);
|
|
18258
|
-
if (ask !== void 0) return { tool, kind: "keep", why: `the ask rule ${ruleText(ask)} stays` };
|
|
18259
18255
|
const { action, rule } = decide(policy, bridges, tool);
|
|
18260
18256
|
if (action === "allow" && rule !== void 0)
|
|
18261
18257
|
return { tool, kind: "keep", why: `allowed already by ${ruleText(rule)}` };
|
|
18258
|
+
const before = (found) => `put an allow rule for ${tool} before the rule ${ruleText(rule ?? found)}`;
|
|
18259
|
+
const deny = policy.find((r) => r.action === "deny" && matches(r.match, tool));
|
|
18260
|
+
if (deny !== void 0)
|
|
18261
|
+
return {
|
|
18262
|
+
tool,
|
|
18263
|
+
kind: "refuse",
|
|
18264
|
+
why: `the deny rule ${ruleText(deny)} matches it. allow never loosens a deny rule`,
|
|
18265
|
+
edit: before(deny)
|
|
18266
|
+
};
|
|
18267
|
+
const ask = policy.find((r) => r.action === "ask" && r.match === tool);
|
|
18268
|
+
if (ask !== void 0)
|
|
18269
|
+
return {
|
|
18270
|
+
tool,
|
|
18271
|
+
kind: "refuse",
|
|
18272
|
+
why: `the ask rule ${ruleText(ask)} names it. allow never loosens an ask rule`,
|
|
18273
|
+
edit: rule === ask ? `change the rule ${ruleText(ask)} to allow` : before(ask)
|
|
18274
|
+
};
|
|
18262
18275
|
return { tool, kind: "add" };
|
|
18263
18276
|
});
|
|
18264
18277
|
const added = new Set(steps2.flatMap((s) => s.kind === "add" ? [s.tool] : []));
|
|
@@ -18278,7 +18291,7 @@ var allowCommands = (lines, policy, bridges, start) => {
|
|
|
18278
18291
|
const out = asked.flatMap(({ name }) => {
|
|
18279
18292
|
if (!PLAIN_NAME.test(name)) return [label(shownName(name)), ` ${NAME_CHANGES}.`];
|
|
18280
18293
|
const [step] = planAllow(policy, bridges, [name]).steps;
|
|
18281
|
-
if (step?.kind === "keep") return [label(name), ` no command: ${step.why}.`];
|
|
18294
|
+
if (step?.kind === "keep" || step?.kind === "refuse") return [label(name), ` no command: ${step.why}.`];
|
|
18282
18295
|
plain2.add(name);
|
|
18283
18296
|
return [label(name), allowCommand(start, [name], false)];
|
|
18284
18297
|
});
|
|
@@ -18370,15 +18383,42 @@ ${ALLOW_USAGE}`);
|
|
|
18370
18383
|
return 2;
|
|
18371
18384
|
}
|
|
18372
18385
|
const plan = planAllow(loaded2.config.policy, loaded2.config.bridges, tools);
|
|
18373
|
-
const steps2 = plan.steps.map(
|
|
18374
|
-
(s
|
|
18375
|
-
|
|
18386
|
+
const steps2 = plan.steps.map((s) => {
|
|
18387
|
+
switch (s.kind) {
|
|
18388
|
+
case "add":
|
|
18389
|
+
return `add: an allow rule for ${s.tool}`;
|
|
18390
|
+
case "keep":
|
|
18391
|
+
return `keep: ${s.tool}: ${s.why}`;
|
|
18392
|
+
case "refuse":
|
|
18393
|
+
return `refused: ${s.tool}: ${s.why}.`;
|
|
18394
|
+
}
|
|
18395
|
+
});
|
|
18376
18396
|
const added = plan.steps.flatMap((s) => s.kind === "add" ? [s.tool] : []);
|
|
18397
|
+
const refused2 = plan.steps.flatMap((s) => s.kind === "refuse" ? [s] : []);
|
|
18398
|
+
const policy = plan.policy.map((rule) => ` ${ruleText(rule)}`);
|
|
18399
|
+
if (refused2.length > 0) {
|
|
18400
|
+
const next = refused2.map((s) => `next: ${s.tool}: to allow it, edit the policy of ${file2}: ${s.edit}.`);
|
|
18401
|
+
const start = commandStart(file2, io2.platform, io2.launch, "allow");
|
|
18402
|
+
io2.print(
|
|
18403
|
+
[
|
|
18404
|
+
...steps2,
|
|
18405
|
+
...next,
|
|
18406
|
+
`allow did not change ${file2}, because it refused ${refused2.length === 1 ? "a tool" : "tools"}.`,
|
|
18407
|
+
...added.length === 0 ? [] : [
|
|
18408
|
+
"The command below adds only the tools that it names. It writes this policy:",
|
|
18409
|
+
...policy,
|
|
18410
|
+
...RELOAD,
|
|
18411
|
+
"To write this policy, run the command below.",
|
|
18412
|
+
...start.ok ? [allowCommand(start, added, true)] : start.lines
|
|
18413
|
+
]
|
|
18414
|
+
].join("\n")
|
|
18415
|
+
);
|
|
18416
|
+
return 2;
|
|
18417
|
+
}
|
|
18377
18418
|
if (added.length === 0) {
|
|
18378
18419
|
io2.print([...steps2, `The policy needs no change. allow did not change ${file2}.`].join("\n"));
|
|
18379
18420
|
return 0;
|
|
18380
18421
|
}
|
|
18381
|
-
const policy = plan.policy.map((rule) => ` ${ruleText(rule)}`);
|
|
18382
18422
|
if (!values.apply) {
|
|
18383
18423
|
const start = commandStart(file2, io2.platform, io2.launch, "allow");
|
|
18384
18424
|
io2.print(
|
|
@@ -18450,7 +18490,7 @@ var toolLines = (state, policy, bridges) => catalogOf([state]).map((t) => ({
|
|
|
18450
18490
|
person: t.requiresUserInteraction
|
|
18451
18491
|
}));
|
|
18452
18492
|
var toolLineText = ({ name, hint, action, person }) => `${shownName(name)} ${hint} ${action}${person && action !== "deny" ? ", a person each run" : ""}`;
|
|
18453
|
-
var notConnected = (s) => s.status === "connected" ? void 0 : `the MCP server "${s.key}" is not connected: ${s.status === "failed" ? s.reason : s.status === "asleep" ? "it is asleep and did not start. After 3 starts in 60 s a wait applies, and then it starts on the next call that names it" :
|
|
18493
|
+
var notConnected = (s) => s.status === "connected" ? void 0 : `the MCP server "${s.key}" is not connected: ${s.status === "failed" ? s.reason : s.status === "asleep" ? "it is asleep and did not start. After 3 starts in 60 s a wait applies, and then it starts on the next call that names it" : `it is still connecting (${Math.floor(Math.max(0, s.elapsedMs ?? 0) / 1e3)} s so far). Run the program again in a moment.`}`;
|
|
18454
18494
|
var isObject3 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
18455
18495
|
var ofArray = (item) => item.startsWith("number (") ? `(${item})` : item;
|
|
18456
18496
|
var INT32 = 2147483647;
|
|
@@ -29432,7 +29472,17 @@ var sha256 = (data) => createHash2("sha256").update(data).digest("hex");
|
|
|
29432
29472
|
var hmac = (key, data) => createHmac("sha256", key).update(data).digest();
|
|
29433
29473
|
var encode3 = (text2) => encodeURIComponent(text2).replace(/[!'()*]/g, (c) => `%${c.charCodeAt(0).toString(16).toUpperCase()}`);
|
|
29434
29474
|
var canonicalPath = (pathname) => pathname.split("/").map(encode3).join("/") || "/";
|
|
29435
|
-
var
|
|
29475
|
+
var decode3 = (text2) => {
|
|
29476
|
+
try {
|
|
29477
|
+
return decodeURIComponent(text2);
|
|
29478
|
+
} catch {
|
|
29479
|
+
return text2;
|
|
29480
|
+
}
|
|
29481
|
+
};
|
|
29482
|
+
var canonicalQuery = (search) => search.replace(/^\?/, "").split("&").filter((part) => part !== "").map((part) => {
|
|
29483
|
+
const at2 = part.indexOf("=");
|
|
29484
|
+
return at2 < 0 ? [part, ""] : [part.slice(0, at2), part.slice(at2 + 1)];
|
|
29485
|
+
}).map(([k, v]) => [encode3(decode3(k)), encode3(decode3(v))]).sort(([a, av], [b, bv]) => a < b ? -1 : a > b ? 1 : av < bv ? -1 : av > bv ? 1 : 0).map(([k, v]) => `${k}=${v}`).join("&");
|
|
29436
29486
|
var signRequest = (request, credentials, scope, now) => {
|
|
29437
29487
|
const url2 = new URL(request.url);
|
|
29438
29488
|
const amzDate = now.toISOString().replace(/[:-]|\.\d{3}/g, "");
|
|
@@ -29446,7 +29496,7 @@ var signRequest = (request, credentials, scope, now) => {
|
|
|
29446
29496
|
const canonical2 = [
|
|
29447
29497
|
request.method.toUpperCase(),
|
|
29448
29498
|
canonicalPath(url2.pathname),
|
|
29449
|
-
canonicalQuery(url2.
|
|
29499
|
+
canonicalQuery(url2.search),
|
|
29450
29500
|
names.map((n) => `${n}:${signed[n].trim().replace(/\s+/g, " ")}
|
|
29451
29501
|
`).join(""),
|
|
29452
29502
|
names.join(";"),
|
|
@@ -29487,12 +29537,21 @@ var parseExported = (text2) => {
|
|
|
29487
29537
|
var failure2 = (profile, why) => new AwsCredentialsError(
|
|
29488
29538
|
`could not get AWS credentials for the profile "${profile}" (${why}). If it is an SSO profile, run: aws sso login --profile ${profile}`
|
|
29489
29539
|
);
|
|
29490
|
-
var
|
|
29540
|
+
var timeoutReason = (limitMs) => `the AWS CLI did not answer in ${Math.round(limitMs / 100) / 10} s`;
|
|
29541
|
+
var stderrReason = (stderr) => {
|
|
29542
|
+
const line = stderr.split(/\r?\n/).find((l) => l.trim() !== "")?.trim();
|
|
29543
|
+
if (line === void 0) return void 0;
|
|
29544
|
+
if (/^usage:/i.test(line)) return "needs AWS CLI version 2";
|
|
29545
|
+
return hideArgSecrets([line]).args[0].slice(0, 300);
|
|
29546
|
+
};
|
|
29547
|
+
var exportCredentials = (profile, command3 = "aws", limitMs = CLI_TIMEOUT_MS) => new Promise((resolve2, reject) => {
|
|
29491
29548
|
let child;
|
|
29492
29549
|
try {
|
|
29493
29550
|
child = (0, import_cross_spawn4.default)(command3, ["configure", "export-credentials", "--profile", profile, "--format", "process"], {
|
|
29494
29551
|
stdio: ["ignore", "pipe", "pipe"],
|
|
29495
|
-
windowsHide: true
|
|
29552
|
+
windowsHide: true,
|
|
29553
|
+
// A process group, so endTree ends a helper that the CLI started.
|
|
29554
|
+
detached: process.platform !== "win32"
|
|
29496
29555
|
});
|
|
29497
29556
|
} catch {
|
|
29498
29557
|
reject(failure2(profile, "the AWS CLI did not start"));
|
|
@@ -29500,20 +29559,43 @@ var exportCredentials = (profile, command3 = "aws") => new Promise((resolve2, re
|
|
|
29500
29559
|
}
|
|
29501
29560
|
let out = "";
|
|
29502
29561
|
let err = "";
|
|
29503
|
-
|
|
29504
|
-
|
|
29505
|
-
|
|
29506
|
-
|
|
29562
|
+
let settled = false;
|
|
29563
|
+
const settle2 = (end) => {
|
|
29564
|
+
if (settled) return;
|
|
29565
|
+
settled = true;
|
|
29507
29566
|
clearTimeout(timer);
|
|
29508
|
-
|
|
29509
|
-
}
|
|
29510
|
-
child.on("
|
|
29511
|
-
clearTimeout(timer);
|
|
29512
|
-
const credentials = code === 0 ? parseExported(out) : void 0;
|
|
29513
|
-
if (credentials) return resolve2(credentials);
|
|
29514
|
-
const line = err.split(/\r?\n/).find((l) => l.trim() !== "")?.trim().slice(0, 300);
|
|
29515
|
-
reject(failure2(profile, line ?? (code === 0 ? "the AWS CLI printed no credentials" : `exit ${code}`)));
|
|
29567
|
+
end();
|
|
29568
|
+
};
|
|
29569
|
+
for (const stream of [child.stdout, child.stderr]) stream?.on("error", () => {
|
|
29516
29570
|
});
|
|
29571
|
+
child.stdout?.on("data", (b) => void (!settled && out.length < MAX_OUTPUT && (out += b.toString("utf8"))));
|
|
29572
|
+
child.stderr?.on("data", (b) => void (!settled && err.length < MAX_OUTPUT && (err += b.toString("utf8"))));
|
|
29573
|
+
const timer = setTimeout(
|
|
29574
|
+
() => settle2(() => {
|
|
29575
|
+
reject(failure2(profile, timeoutReason(limitMs)));
|
|
29576
|
+
endTree(child);
|
|
29577
|
+
child.stdout?.destroy();
|
|
29578
|
+
child.stderr?.destroy();
|
|
29579
|
+
}),
|
|
29580
|
+
limitMs
|
|
29581
|
+
);
|
|
29582
|
+
child.on(
|
|
29583
|
+
"error",
|
|
29584
|
+
(e) => settle2(
|
|
29585
|
+
() => reject(
|
|
29586
|
+
failure2(profile, e.code === "ENOENT" ? 'the AWS CLI "aws" is not on PATH' : "the AWS CLI did not start")
|
|
29587
|
+
)
|
|
29588
|
+
)
|
|
29589
|
+
);
|
|
29590
|
+
child.on(
|
|
29591
|
+
"close",
|
|
29592
|
+
(code, signal) => settle2(() => {
|
|
29593
|
+
const credentials = code === 0 ? parseExported(out) : void 0;
|
|
29594
|
+
if (credentials) return resolve2(credentials);
|
|
29595
|
+
const why = code === 0 ? "the AWS CLI printed no credentials" : code === null ? `killed by ${signal}` : `exit ${code}`;
|
|
29596
|
+
reject(failure2(profile, stderrReason(err) ?? why));
|
|
29597
|
+
})
|
|
29598
|
+
);
|
|
29517
29599
|
});
|
|
29518
29600
|
var sigv4Fetch = (server2, base, load = exportCredentials, clock = Date.now) => {
|
|
29519
29601
|
const origin = new URL(server2.url).origin;
|
|
@@ -29522,8 +29604,13 @@ var sigv4Fetch = (server2, base, load = exportCredentials, clock = Date.now) =>
|
|
|
29522
29604
|
const credentials = async () => {
|
|
29523
29605
|
if (current && (current.expiresAt === void 0 || current.expiresAt - EARLY_MS > clock())) return current;
|
|
29524
29606
|
pending ??= load(server2.sigv4.profile).finally(() => pending = void 0);
|
|
29525
|
-
|
|
29526
|
-
|
|
29607
|
+
try {
|
|
29608
|
+
current = await pending;
|
|
29609
|
+
return current;
|
|
29610
|
+
} catch (error2) {
|
|
29611
|
+
if (current?.expiresAt !== void 0 && current.expiresAt > clock()) return current;
|
|
29612
|
+
throw error2;
|
|
29613
|
+
}
|
|
29527
29614
|
};
|
|
29528
29615
|
const signed = async (url2, init) => {
|
|
29529
29616
|
const target = new URL(url2);
|
|
@@ -29751,6 +29838,7 @@ var connectAll = (servers, version3, log2, {
|
|
|
29751
29838
|
refreshTimeoutMs = REFRESH_TIMEOUT_MS,
|
|
29752
29839
|
listFloorMs = LIST_FLOOR_MS,
|
|
29753
29840
|
firstWaitMs = FIRST_WAIT_MS,
|
|
29841
|
+
connectTimeoutMs = CONNECT_TIMEOUT_MS,
|
|
29754
29842
|
childStderr = (chunk) => void process.stderr.write(chunk),
|
|
29755
29843
|
unshown: unshown2 = UNSHOWN,
|
|
29756
29844
|
share,
|
|
@@ -29843,7 +29931,29 @@ var connectAll = (servers, version3, log2, {
|
|
|
29843
29931
|
children.add(made.child);
|
|
29844
29932
|
if (closing2) made.child.hurry();
|
|
29845
29933
|
}
|
|
29846
|
-
|
|
29934
|
+
let timer;
|
|
29935
|
+
let arm;
|
|
29936
|
+
const expired = new Promise((_, reject) => {
|
|
29937
|
+
arm = () => {
|
|
29938
|
+
timer = setTimeout(
|
|
29939
|
+
() => reject(new OwnError(`the connect did not finish within ${connectTimeoutMs / 1e3} s`)),
|
|
29940
|
+
connectTimeoutMs
|
|
29941
|
+
);
|
|
29942
|
+
};
|
|
29943
|
+
});
|
|
29944
|
+
const start = made.transport.start.bind(made.transport);
|
|
29945
|
+
made.transport.start = async () => {
|
|
29946
|
+
await start();
|
|
29947
|
+
arm();
|
|
29948
|
+
};
|
|
29949
|
+
const connecting = client.connect(made.transport, { timeout: connectTimeoutMs });
|
|
29950
|
+
try {
|
|
29951
|
+
await Promise.race([connecting, expired]);
|
|
29952
|
+
} finally {
|
|
29953
|
+
clearTimeout(timer);
|
|
29954
|
+
connecting.catch(() => {
|
|
29955
|
+
});
|
|
29956
|
+
}
|
|
29847
29957
|
const first2 = await list2();
|
|
29848
29958
|
lists2 = startLists(
|
|
29849
29959
|
first2,
|
|
@@ -29904,7 +30014,7 @@ var connectAll = (servers, version3, log2, {
|
|
|
29904
30014
|
await after;
|
|
29905
30015
|
await connect(key, server2, woke);
|
|
29906
30016
|
})().finally(() => waking.delete(key));
|
|
29907
|
-
links.set(key, { status: "connecting", done });
|
|
30017
|
+
links.set(key, { status: "connecting", done, since: performance.now() });
|
|
29908
30018
|
return done;
|
|
29909
30019
|
};
|
|
29910
30020
|
const wake = (key) => {
|
|
@@ -29938,7 +30048,8 @@ var connectAll = (servers, version3, log2, {
|
|
|
29938
30048
|
};
|
|
29939
30049
|
const longWait = (key) => links.get(key)?.status === "asleep" || waking.has(key);
|
|
29940
30050
|
const stateOf = (key, link) => {
|
|
29941
|
-
if (link.status === "connecting")
|
|
30051
|
+
if (link.status === "connecting")
|
|
30052
|
+
return { key, status: "connecting", elapsedMs: Math.max(0, performance.now() - link.since) };
|
|
29942
30053
|
if (link.status === "connected") return { key, status: "connected", tools: link.lists.tools() };
|
|
29943
30054
|
if (link.status === "asleep") return { key, status: "asleep", tools: link.tools };
|
|
29944
30055
|
const wait = closing2 ? 0 : capWait(key);
|
|
@@ -29960,7 +30071,7 @@ var connectAll = (servers, version3, log2, {
|
|
|
29960
30071
|
links.set(key, { status: "asleep", tools: hit.tools });
|
|
29961
30072
|
}) : attempt2(key, server2);
|
|
29962
30073
|
first.set(key, done);
|
|
29963
|
-
if (!links.has(key)) links.set(key, { status: "connecting", done });
|
|
30074
|
+
if (!links.has(key)) links.set(key, { status: "connecting", done, since: performance.now() });
|
|
29964
30075
|
return done;
|
|
29965
30076
|
}
|
|
29966
30077
|
const reason = invalidReason(server2.errors);
|
|
@@ -31738,6 +31849,8 @@ var serverOf = (name, file2, io2) => {
|
|
|
31738
31849
|
if (key === void 0 || entry === void 0) return `the config ${file2} has no server "${name}"`;
|
|
31739
31850
|
if (entry.kind === "invalid") return `${name}: ${invalidReason(entry.errors)}`;
|
|
31740
31851
|
if (entry.kind === "stdio") return `${name} is a stdio server. Only an HTTP server logs in with OAuth.`;
|
|
31852
|
+
if (entry.sigv4 !== void 0)
|
|
31853
|
+
return `${name} signs its requests with AWS credentials (SigV4), so it needs no login. For an SSO profile, run: aws sso login --profile ${entry.sigv4.profile}`;
|
|
31741
31854
|
if (entry.oauth === void 0)
|
|
31742
31855
|
return `${name} does not log in with OAuth: it has headers, or "oauth": false. To log in, remove an Authorization header and set "oauth": true.`;
|
|
31743
31856
|
return { key, server: entry, oauth: entry.oauth };
|