toolscript-mcp 1.0.1 → 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 +41 -2
- package/dist/host/main.js +316 -33
- 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.
|
|
@@ -916,6 +922,39 @@ shows the cause. The next search or call tries the refresh again.
|
|
|
916
922
|
Sessions that share one token store refresh one at a time, so a server that revokes a reused refresh token keeps your login.
|
|
917
923
|
A `.lock` file can show beside the store for a moment. If a session waits up to 20 s for another session, `search_tools` shows the cause. The next call tries again.
|
|
918
924
|
|
|
925
|
+
### AWS SigV4
|
|
926
|
+
|
|
927
|
+
toolscript-mcp signs the requests to an AWS HTTP server, such as the AWS MCP Server, with AWS SigV4. It uses the
|
|
928
|
+
credentials of a profile of the AWS CLI. You do not need a proxy such as `mcp-proxy-for-aws`, and you do not need a
|
|
929
|
+
login.
|
|
930
|
+
|
|
931
|
+
```json
|
|
932
|
+
{
|
|
933
|
+
"mcpServers": {
|
|
934
|
+
"aws": {
|
|
935
|
+
"type": "http",
|
|
936
|
+
"url": "https://aws-mcp.us-east-1.api.aws/mcp",
|
|
937
|
+
"sigv4": { "profile": "dev" }
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
```
|
|
942
|
+
|
|
943
|
+
1. Install the AWS CLI version 2 and put `aws` on your `PATH`.
|
|
944
|
+
2. For an SSO profile, run `aws sso login --profile <profile>`.
|
|
945
|
+
3. Add one entry for each profile. Each entry uses one account.
|
|
946
|
+
|
|
947
|
+
- toolscript-mcp gets the credentials with `aws configure export-credentials --profile <profile>`. It keeps them in
|
|
948
|
+
memory and gets new ones 5 minutes before they expire.
|
|
949
|
+
- When the credentials cannot be read, the call fails with the cause and the `aws sso login` command. After you log in
|
|
950
|
+
again, the next call works, with no restart.
|
|
951
|
+
- The region and the service come from the host of `url`, such as `us-east-1` and `aws-mcp`. For another host, set
|
|
952
|
+
`"region"` and `"service"` in `sigv4`.
|
|
953
|
+
- An entry with `sigv4` does not log in with OAuth. An entry with `sigv4` and `oauth`, or with an `Authorization`
|
|
954
|
+
header, is an error.
|
|
955
|
+
- toolscript-mcp signs only the requests to the origin of `url`. It never writes the credentials or the signature to a
|
|
956
|
+
log.
|
|
957
|
+
|
|
919
958
|
### Run log
|
|
920
959
|
|
|
921
960
|
toolscript-mcp writes one line to `~/.toolscript-mcp/runs.jsonl` for each `run_code` call.
|
package/dist/host/main.js
CHANGED
|
@@ -17677,6 +17677,49 @@ var nonEmpty = (v, path15, errors) => {
|
|
|
17677
17677
|
return "";
|
|
17678
17678
|
};
|
|
17679
17679
|
var OAUTH_KEYS = ["clientId", "clientSecret", "scopes", "callbackPort"];
|
|
17680
|
+
var SIGV4_KEYS = ["profile", "region", "service"];
|
|
17681
|
+
var AWS_PROFILE = /^[A-Za-z0-9][A-Za-z0-9_.+=@-]{0,127}$/;
|
|
17682
|
+
var AWS_REGION = /^[a-z]{2}(?:-[a-z]+)+-\d{1,2}$/;
|
|
17683
|
+
var AWS_SERVICE = /^[a-z0-9][a-z0-9-]{0,62}$/;
|
|
17684
|
+
var awsEndpoint = (url2) => {
|
|
17685
|
+
if (!URL.canParse(url2)) return void 0;
|
|
17686
|
+
const host = /^https:\/\/([^/?#@:]+)(?::\d+)?(?:[/?#]|$)/i.exec(url2)?.[1]?.toLowerCase() ?? "";
|
|
17687
|
+
const m = /^([a-z0-9-]+)\.([a-z]{2}(?:-[a-z]+)+-\d{1,2})\.(?:api\.aws|amazonaws\.com)$/.exec(host);
|
|
17688
|
+
return m ? { service: m[1], region: m[2] } : void 0;
|
|
17689
|
+
};
|
|
17690
|
+
var parseSigV4 = (raw, url2, headers, oauth, path15, env, errors) => {
|
|
17691
|
+
if (raw === void 0) return void 0;
|
|
17692
|
+
if (!isObject2(raw)) {
|
|
17693
|
+
errors.push(`${path15}: must be an object with "profile"`);
|
|
17694
|
+
return void 0;
|
|
17695
|
+
}
|
|
17696
|
+
unknownKeys(raw, SIGV4_KEYS, path15, errors);
|
|
17697
|
+
if (oauth !== void 0 && oauth !== false)
|
|
17698
|
+
errors.push(`${path15}: an entry with "sigv4" does not log in: remove "oauth"`);
|
|
17699
|
+
if (Object.keys(headers).some((name) => name.toLowerCase() === "authorization"))
|
|
17700
|
+
errors.push(`${path15}: an entry with an Authorization header cannot sign with SigV4: remove one of them`);
|
|
17701
|
+
const field = (key, rule, fallback) => {
|
|
17702
|
+
const value = raw[key];
|
|
17703
|
+
if (value === void 0) {
|
|
17704
|
+
if (fallback === void 0) errors.push(`${path15}.${key}: is needed, because the URL is not an AWS endpoint`);
|
|
17705
|
+
return fallback;
|
|
17706
|
+
}
|
|
17707
|
+
const text2 = expand(nonEmpty(value, `${path15}.${key}`, errors), env, `${path15}.${key}`, errors);
|
|
17708
|
+
if (text2 !== "" && !rule.test(text2)) {
|
|
17709
|
+
errors.push(`${path15}.${key}: is not a valid ${key}`);
|
|
17710
|
+
return void 0;
|
|
17711
|
+
}
|
|
17712
|
+
return text2;
|
|
17713
|
+
};
|
|
17714
|
+
const endpoint = awsEndpoint(url2);
|
|
17715
|
+
const found = errors.length;
|
|
17716
|
+
if (raw.profile === void 0) errors.push(`${path15}.profile: is needed`);
|
|
17717
|
+
const profile = raw.profile === void 0 ? void 0 : field("profile", AWS_PROFILE, void 0);
|
|
17718
|
+
const region = field("region", AWS_REGION, endpoint?.region);
|
|
17719
|
+
const service = field("service", AWS_SERVICE, endpoint?.service);
|
|
17720
|
+
if (errors.length !== found || !profile || !region || !service) return void 0;
|
|
17721
|
+
return { profile, region, service };
|
|
17722
|
+
};
|
|
17680
17723
|
var parseOAuth = (raw, headers, path15, env, errors) => {
|
|
17681
17724
|
if (raw === false) return void 0;
|
|
17682
17725
|
if (raw === void 0) return Object.keys(headers).length === 0 ? { scopes: [] } : void 0;
|
|
@@ -17776,7 +17819,7 @@ var parseServer = (raw, path15, env, platform, errors) => {
|
|
|
17776
17819
|
};
|
|
17777
17820
|
}
|
|
17778
17821
|
if (type === "http") {
|
|
17779
|
-
unknownKeys(raw, ["type", "url", "headers", "oauth", "untrusted"], path15, errors);
|
|
17822
|
+
unknownKeys(raw, ["type", "url", "headers", "oauth", "sigv4", "untrusted"], path15, errors);
|
|
17780
17823
|
const found = errors.length;
|
|
17781
17824
|
const url2 = expand(nonEmpty(raw.url, `${path15}.url`, errors), env, `${path15}.url`, errors);
|
|
17782
17825
|
if (errors.length === found) {
|
|
@@ -17784,12 +17827,14 @@ var parseServer = (raw, path15, env, platform, errors) => {
|
|
|
17784
17827
|
else if (!URL.canParse(url2)) errors.push(`${path15}.url: must be a valid URL`);
|
|
17785
17828
|
}
|
|
17786
17829
|
const headers = stringMap(raw.headers, `${path15}.headers`, env, errors);
|
|
17787
|
-
const
|
|
17830
|
+
const sigv4 = parseSigV4(raw.sigv4, url2, headers, raw.oauth, `${path15}.sigv4`, env, errors);
|
|
17831
|
+
const oauth = raw.sigv4 === void 0 ? parseOAuth(raw.oauth, headers, `${path15}.oauth`, env, errors) : void 0;
|
|
17788
17832
|
return {
|
|
17789
17833
|
kind: "http",
|
|
17790
17834
|
url: url2,
|
|
17791
17835
|
headers,
|
|
17792
17836
|
...oauth && { oauth },
|
|
17837
|
+
...sigv4 && { sigv4 },
|
|
17793
17838
|
...parseTrust(raw.untrusted, `${path15}.untrusted`, errors)
|
|
17794
17839
|
};
|
|
17795
17840
|
}
|
|
@@ -18207,13 +18252,26 @@ var allowRefusal = (tool, keys) => {
|
|
|
18207
18252
|
};
|
|
18208
18253
|
var planAllow = (policy, bridges, tools) => {
|
|
18209
18254
|
const steps2 = [...new Set(tools)].map((tool) => {
|
|
18210
|
-
const deny = policy.find((r) => r.action === "deny" && matches(r.match, tool));
|
|
18211
|
-
if (deny !== void 0) return { tool, kind: "keep", why: `the deny rule ${ruleText(deny)} stays` };
|
|
18212
|
-
const ask = policy.find((r) => r.action === "ask" && r.match === tool);
|
|
18213
|
-
if (ask !== void 0) return { tool, kind: "keep", why: `the ask rule ${ruleText(ask)} stays` };
|
|
18214
18255
|
const { action, rule } = decide(policy, bridges, tool);
|
|
18215
18256
|
if (action === "allow" && rule !== void 0)
|
|
18216
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
|
+
};
|
|
18217
18275
|
return { tool, kind: "add" };
|
|
18218
18276
|
});
|
|
18219
18277
|
const added = new Set(steps2.flatMap((s) => s.kind === "add" ? [s.tool] : []));
|
|
@@ -18233,7 +18291,7 @@ var allowCommands = (lines, policy, bridges, start) => {
|
|
|
18233
18291
|
const out = asked.flatMap(({ name }) => {
|
|
18234
18292
|
if (!PLAIN_NAME.test(name)) return [label(shownName(name)), ` ${NAME_CHANGES}.`];
|
|
18235
18293
|
const [step] = planAllow(policy, bridges, [name]).steps;
|
|
18236
|
-
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}.`];
|
|
18237
18295
|
plain2.add(name);
|
|
18238
18296
|
return [label(name), allowCommand(start, [name], false)];
|
|
18239
18297
|
});
|
|
@@ -18325,15 +18383,42 @@ ${ALLOW_USAGE}`);
|
|
|
18325
18383
|
return 2;
|
|
18326
18384
|
}
|
|
18327
18385
|
const plan = planAllow(loaded2.config.policy, loaded2.config.bridges, tools);
|
|
18328
|
-
const steps2 = plan.steps.map(
|
|
18329
|
-
(s
|
|
18330
|
-
|
|
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
|
+
});
|
|
18331
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
|
+
}
|
|
18332
18418
|
if (added.length === 0) {
|
|
18333
18419
|
io2.print([...steps2, `The policy needs no change. allow did not change ${file2}.`].join("\n"));
|
|
18334
18420
|
return 0;
|
|
18335
18421
|
}
|
|
18336
|
-
const policy = plan.policy.map((rule) => ` ${ruleText(rule)}`);
|
|
18337
18422
|
if (!values.apply) {
|
|
18338
18423
|
const start = commandStart(file2, io2.platform, io2.launch, "allow");
|
|
18339
18424
|
io2.print(
|
|
@@ -18405,7 +18490,7 @@ var toolLines = (state, policy, bridges) => catalogOf([state]).map((t) => ({
|
|
|
18405
18490
|
person: t.requiresUserInteraction
|
|
18406
18491
|
}));
|
|
18407
18492
|
var toolLineText = ({ name, hint, action, person }) => `${shownName(name)} ${hint} ${action}${person && action !== "deny" ? ", a person each run" : ""}`;
|
|
18408
|
-
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.`}`;
|
|
18409
18494
|
var isObject3 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
18410
18495
|
var ofArray = (item) => item.startsWith("number (") ? `(${item})` : item;
|
|
18411
18496
|
var INT32 = 2147483647;
|
|
@@ -29380,6 +29465,174 @@ var oauthProvider = (file2, oauth, mode, lockFs) => {
|
|
|
29380
29465
|
};
|
|
29381
29466
|
};
|
|
29382
29467
|
|
|
29468
|
+
// src/host/sigv4.ts
|
|
29469
|
+
var import_cross_spawn4 = __toESM(require_cross_spawn(), 1);
|
|
29470
|
+
import { createHash as createHash2, createHmac } from "node:crypto";
|
|
29471
|
+
var sha256 = (data) => createHash2("sha256").update(data).digest("hex");
|
|
29472
|
+
var hmac = (key, data) => createHmac("sha256", key).update(data).digest();
|
|
29473
|
+
var encode3 = (text2) => encodeURIComponent(text2).replace(/[!'()*]/g, (c) => `%${c.charCodeAt(0).toString(16).toUpperCase()}`);
|
|
29474
|
+
var canonicalPath = (pathname) => pathname.split("/").map(encode3).join("/") || "/";
|
|
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("&");
|
|
29486
|
+
var signRequest = (request, credentials, scope, now) => {
|
|
29487
|
+
const url2 = new URL(request.url);
|
|
29488
|
+
const amzDate = now.toISOString().replace(/[:-]|\.\d{3}/g, "");
|
|
29489
|
+
const day = amzDate.slice(0, 8);
|
|
29490
|
+
const added = { "x-amz-date": amzDate };
|
|
29491
|
+
if (credentials.sessionToken !== void 0) added["x-amz-security-token"] = credentials.sessionToken;
|
|
29492
|
+
const signed = { host: url2.host, ...added };
|
|
29493
|
+
const contentType2 = request.headers.get("content-type");
|
|
29494
|
+
if (contentType2 !== null) signed["content-type"] = contentType2;
|
|
29495
|
+
const names = Object.keys(signed).sort();
|
|
29496
|
+
const canonical2 = [
|
|
29497
|
+
request.method.toUpperCase(),
|
|
29498
|
+
canonicalPath(url2.pathname),
|
|
29499
|
+
canonicalQuery(url2.search),
|
|
29500
|
+
names.map((n) => `${n}:${signed[n].trim().replace(/\s+/g, " ")}
|
|
29501
|
+
`).join(""),
|
|
29502
|
+
names.join(";"),
|
|
29503
|
+
sha256(request.body)
|
|
29504
|
+
].join("\n");
|
|
29505
|
+
const credentialScope = `${day}/${scope.region}/${scope.service}/aws4_request`;
|
|
29506
|
+
const toSign = ["AWS4-HMAC-SHA256", amzDate, credentialScope, sha256(canonical2)].join("\n");
|
|
29507
|
+
let key = hmac(`AWS4${credentials.secretAccessKey}`, day);
|
|
29508
|
+
for (const part of [scope.region, scope.service, "aws4_request"]) key = hmac(key, part);
|
|
29509
|
+
const signature = createHmac("sha256", key).update(toSign).digest("hex");
|
|
29510
|
+
added.authorization = `AWS4-HMAC-SHA256 Credential=${credentials.accessKeyId}/${credentialScope}, SignedHeaders=${names.join(";")}, Signature=${signature}`;
|
|
29511
|
+
return added;
|
|
29512
|
+
};
|
|
29513
|
+
var EARLY_MS = 5 * 6e4;
|
|
29514
|
+
var CLI_TIMEOUT_MS = 3e4;
|
|
29515
|
+
var MAX_OUTPUT = 64 * 1024;
|
|
29516
|
+
var AwsCredentialsError = class extends Error {
|
|
29517
|
+
};
|
|
29518
|
+
var parseExported = (text2) => {
|
|
29519
|
+
let raw;
|
|
29520
|
+
try {
|
|
29521
|
+
raw = JSON.parse(text2);
|
|
29522
|
+
} catch {
|
|
29523
|
+
return void 0;
|
|
29524
|
+
}
|
|
29525
|
+
if (typeof raw !== "object" || raw === null) return void 0;
|
|
29526
|
+
const { AccessKeyId, SecretAccessKey, SessionToken, Expiration } = raw;
|
|
29527
|
+
if (typeof AccessKeyId !== "string" || AccessKeyId === "" || typeof SecretAccessKey !== "string") return void 0;
|
|
29528
|
+
if (SecretAccessKey === "") return void 0;
|
|
29529
|
+
const expiresAt = typeof Expiration === "string" ? Date.parse(Expiration) : NaN;
|
|
29530
|
+
return {
|
|
29531
|
+
accessKeyId: AccessKeyId,
|
|
29532
|
+
secretAccessKey: SecretAccessKey,
|
|
29533
|
+
...typeof SessionToken === "string" && SessionToken !== "" && { sessionToken: SessionToken },
|
|
29534
|
+
...Number.isFinite(expiresAt) && { expiresAt }
|
|
29535
|
+
};
|
|
29536
|
+
};
|
|
29537
|
+
var failure2 = (profile, why) => new AwsCredentialsError(
|
|
29538
|
+
`could not get AWS credentials for the profile "${profile}" (${why}). If it is an SSO profile, run: aws sso login --profile ${profile}`
|
|
29539
|
+
);
|
|
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) => {
|
|
29548
|
+
let child;
|
|
29549
|
+
try {
|
|
29550
|
+
child = (0, import_cross_spawn4.default)(command3, ["configure", "export-credentials", "--profile", profile, "--format", "process"], {
|
|
29551
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
29552
|
+
windowsHide: true,
|
|
29553
|
+
// A process group, so endTree ends a helper that the CLI started.
|
|
29554
|
+
detached: process.platform !== "win32"
|
|
29555
|
+
});
|
|
29556
|
+
} catch {
|
|
29557
|
+
reject(failure2(profile, "the AWS CLI did not start"));
|
|
29558
|
+
return;
|
|
29559
|
+
}
|
|
29560
|
+
let out = "";
|
|
29561
|
+
let err = "";
|
|
29562
|
+
let settled = false;
|
|
29563
|
+
const settle2 = (end) => {
|
|
29564
|
+
if (settled) return;
|
|
29565
|
+
settled = true;
|
|
29566
|
+
clearTimeout(timer);
|
|
29567
|
+
end();
|
|
29568
|
+
};
|
|
29569
|
+
for (const stream of [child.stdout, child.stderr]) stream?.on("error", () => {
|
|
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
|
+
);
|
|
29599
|
+
});
|
|
29600
|
+
var sigv4Fetch = (server2, base, load = exportCredentials, clock = Date.now) => {
|
|
29601
|
+
const origin = new URL(server2.url).origin;
|
|
29602
|
+
let current;
|
|
29603
|
+
let pending;
|
|
29604
|
+
const credentials = async () => {
|
|
29605
|
+
if (current && (current.expiresAt === void 0 || current.expiresAt - EARLY_MS > clock())) return current;
|
|
29606
|
+
pending ??= load(server2.sigv4.profile).finally(() => pending = void 0);
|
|
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
|
+
}
|
|
29614
|
+
};
|
|
29615
|
+
const signed = async (url2, init) => {
|
|
29616
|
+
const target = new URL(url2);
|
|
29617
|
+
if (target.origin !== origin) return base(url2, init);
|
|
29618
|
+
const headers = new Headers(init?.headers);
|
|
29619
|
+
for (const [name, value] of Object.entries(server2.headers ?? {})) headers.set(name, value);
|
|
29620
|
+
const body = init?.body;
|
|
29621
|
+
if (body !== void 0 && body !== null && typeof body !== "string" && !(body instanceof Uint8Array))
|
|
29622
|
+
throw new Error("a SigV4 request body must be a string or bytes");
|
|
29623
|
+
const added = signRequest(
|
|
29624
|
+
{ method: init?.method ?? "GET", url: target.href, headers, body: body ?? "" },
|
|
29625
|
+
await credentials(),
|
|
29626
|
+
server2.sigv4,
|
|
29627
|
+
new Date(clock())
|
|
29628
|
+
);
|
|
29629
|
+
for (const [name, value] of Object.entries(added)) headers.set(name, value);
|
|
29630
|
+
return base(url2, { ...init, headers, redirect: "manual" });
|
|
29631
|
+
};
|
|
29632
|
+
const secrets = () => current ? [current.accessKeyId, current.secretAccessKey, ...current.sessionToken ? [current.sessionToken] : []] : [];
|
|
29633
|
+
return Object.assign(signed, { secrets });
|
|
29634
|
+
};
|
|
29635
|
+
|
|
29383
29636
|
// src/host/downstream.ts
|
|
29384
29637
|
var CONNECT_TIMEOUT_MS = 3e4;
|
|
29385
29638
|
var MAX_PAGES = 100;
|
|
@@ -29483,13 +29736,16 @@ var isOAuthStop = (err) => err instanceof LoginNeeded || err instanceof RefreshF
|
|
|
29483
29736
|
var HttpTransport = class extends StreamableHTTPClientTransport {
|
|
29484
29737
|
#onSessionEnd;
|
|
29485
29738
|
#loginReason;
|
|
29486
|
-
|
|
29739
|
+
/** The AWS credentials of a SigV4 entry, to hide from the texts that reach the model and the log. */
|
|
29740
|
+
secrets;
|
|
29741
|
+
constructor(server2, onSessionEnd, auth2, signed = server2.sigv4 && !auth2 ? sigv4Fetch({ url: server2.url, sigv4: server2.sigv4, headers: server2.headers }, serverFetch(server2)) : void 0) {
|
|
29487
29742
|
super(new URL(server2.url), {
|
|
29488
|
-
fetch: auth2 ? auth2.provider.fetch(serverFetch(server2)) : serverFetch(server2),
|
|
29743
|
+
fetch: auth2 ? auth2.provider.fetch(serverFetch(server2)) : signed ?? serverFetch(server2),
|
|
29489
29744
|
...auth2 && { authProvider: auth2.provider }
|
|
29490
29745
|
});
|
|
29491
29746
|
this.#onSessionEnd = onSessionEnd;
|
|
29492
29747
|
this.#loginReason = auth2?.reason;
|
|
29748
|
+
this.secrets = signed?.secrets ?? (() => []);
|
|
29493
29749
|
}
|
|
29494
29750
|
async send(...args) {
|
|
29495
29751
|
const hadSession = this.sessionId !== void 0;
|
|
@@ -29582,6 +29838,7 @@ var connectAll = (servers, version3, log2, {
|
|
|
29582
29838
|
refreshTimeoutMs = REFRESH_TIMEOUT_MS,
|
|
29583
29839
|
listFloorMs = LIST_FLOOR_MS,
|
|
29584
29840
|
firstWaitMs = FIRST_WAIT_MS,
|
|
29841
|
+
connectTimeoutMs = CONNECT_TIMEOUT_MS,
|
|
29585
29842
|
childStderr = (chunk) => void process.stderr.write(chunk),
|
|
29586
29843
|
unshown: unshown2 = UNSHOWN,
|
|
29587
29844
|
share,
|
|
@@ -29669,11 +29926,34 @@ var connectAll = (servers, version3, log2, {
|
|
|
29669
29926
|
if (closing2) throw new OwnError("toolscript-mcp is shutting down");
|
|
29670
29927
|
const made = transportOf(key, server2, sessionEnded, auth2, childStderr, share, lazily);
|
|
29671
29928
|
lastError = made.lastError;
|
|
29929
|
+
if (made.transport instanceof HttpTransport && !auth2) secrets = made.transport.secrets;
|
|
29672
29930
|
if (made.child !== void 0) {
|
|
29673
29931
|
children.add(made.child);
|
|
29674
29932
|
if (closing2) made.child.hurry();
|
|
29675
29933
|
}
|
|
29676
|
-
|
|
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
|
+
}
|
|
29677
29957
|
const first2 = await list2();
|
|
29678
29958
|
lists2 = startLists(
|
|
29679
29959
|
first2,
|
|
@@ -29716,7 +29996,7 @@ var connectAll = (servers, version3, log2, {
|
|
|
29716
29996
|
await client.close().catch(() => {
|
|
29717
29997
|
});
|
|
29718
29998
|
opened.delete(client);
|
|
29719
|
-
if (isOAuthStop(err) || err instanceof OwnError || err instanceof BrokerError)
|
|
29999
|
+
if (isOAuthStop(err) || err instanceof OwnError || err instanceof BrokerError || err instanceof AwsCredentialsError)
|
|
29720
30000
|
fail3(stderr === "" ? errorText(err) : `${errorText(err)}. ${STDERR_UNSHOWN}`);
|
|
29721
30001
|
else fail3(stderr === "" ? errorText(err) : `${errorText(err)}. ${STDERR_UNSHOWN}`, "the connect failed");
|
|
29722
30002
|
}
|
|
@@ -29734,7 +30014,7 @@ var connectAll = (servers, version3, log2, {
|
|
|
29734
30014
|
await after;
|
|
29735
30015
|
await connect(key, server2, woke);
|
|
29736
30016
|
})().finally(() => waking.delete(key));
|
|
29737
|
-
links.set(key, { status: "connecting", done });
|
|
30017
|
+
links.set(key, { status: "connecting", done, since: performance.now() });
|
|
29738
30018
|
return done;
|
|
29739
30019
|
};
|
|
29740
30020
|
const wake = (key) => {
|
|
@@ -29768,7 +30048,8 @@ var connectAll = (servers, version3, log2, {
|
|
|
29768
30048
|
};
|
|
29769
30049
|
const longWait = (key) => links.get(key)?.status === "asleep" || waking.has(key);
|
|
29770
30050
|
const stateOf = (key, link) => {
|
|
29771
|
-
if (link.status === "connecting")
|
|
30051
|
+
if (link.status === "connecting")
|
|
30052
|
+
return { key, status: "connecting", elapsedMs: Math.max(0, performance.now() - link.since) };
|
|
29772
30053
|
if (link.status === "connected") return { key, status: "connected", tools: link.lists.tools() };
|
|
29773
30054
|
if (link.status === "asleep") return { key, status: "asleep", tools: link.tools };
|
|
29774
30055
|
const wait = closing2 ? 0 : capWait(key);
|
|
@@ -29790,7 +30071,7 @@ var connectAll = (servers, version3, log2, {
|
|
|
29790
30071
|
links.set(key, { status: "asleep", tools: hit.tools });
|
|
29791
30072
|
}) : attempt2(key, server2);
|
|
29792
30073
|
first.set(key, done);
|
|
29793
|
-
if (!links.has(key)) links.set(key, { status: "connecting", done });
|
|
30074
|
+
if (!links.has(key)) links.set(key, { status: "connecting", done, since: performance.now() });
|
|
29794
30075
|
return done;
|
|
29795
30076
|
}
|
|
29796
30077
|
const reason = invalidReason(server2.errors);
|
|
@@ -30254,17 +30535,17 @@ var launch = (o) => {
|
|
|
30254
30535
|
};
|
|
30255
30536
|
|
|
30256
30537
|
// src/host/toolscache.ts
|
|
30257
|
-
import { createHash as
|
|
30538
|
+
import { createHash as createHash4 } from "node:crypto";
|
|
30258
30539
|
|
|
30259
30540
|
// src/host/shapes.ts
|
|
30260
|
-
import { createHash as
|
|
30541
|
+
import { createHash as createHash3 } from "node:crypto";
|
|
30261
30542
|
import fs10 from "node:fs";
|
|
30262
30543
|
var hashes = /* @__PURE__ */ new WeakMap();
|
|
30263
30544
|
var schemaHash = (inputSchema) => {
|
|
30264
30545
|
const key = inputSchema !== null && typeof inputSchema === "object" ? inputSchema : void 0;
|
|
30265
30546
|
const known = key === void 0 ? void 0 : hashes.get(key);
|
|
30266
30547
|
if (known !== void 0) return known;
|
|
30267
|
-
const hash =
|
|
30548
|
+
const hash = createHash3("sha256").update(canonicalJson(inputSchema)).digest("hex").slice(0, 32);
|
|
30268
30549
|
if (key !== void 0) hashes.set(key, hash);
|
|
30269
30550
|
return hash;
|
|
30270
30551
|
};
|
|
@@ -30362,7 +30643,7 @@ var write = async (home, learned, log2) => {
|
|
|
30362
30643
|
// src/host/toolscache.ts
|
|
30363
30644
|
import fs11 from "node:fs";
|
|
30364
30645
|
import path8 from "node:path";
|
|
30365
|
-
var toolsKey = (server2) =>
|
|
30646
|
+
var toolsKey = (server2) => createHash4("sha256").update(toolsKeyText(server2, childEnv(server2))).digest("hex");
|
|
30366
30647
|
var read = async (home, log2) => {
|
|
30367
30648
|
try {
|
|
30368
30649
|
const text2 = await readText(toolsFile(home), MAX_CACHE_BYTES);
|
|
@@ -31437,7 +31718,7 @@ import http from "node:http";
|
|
|
31437
31718
|
import path11 from "node:path";
|
|
31438
31719
|
import { parseArgs as parseArgs5 } from "node:util";
|
|
31439
31720
|
var LOGIN_USAGE = "usage: toolscript-mcp login <server> [--config <path>] [--help]";
|
|
31440
|
-
var
|
|
31721
|
+
var failure3 = (err) => errorText(err) || (err instanceof OAuthError && err.errorCode ? `the authorization server answered ${err.errorCode}` : "no reason given");
|
|
31441
31722
|
var NO_REGISTRATION = "Incompatible auth server: does not support dynamic client registration";
|
|
31442
31723
|
var OTHER_RESOURCE = /^Protected resource (\S+) does not match expected/;
|
|
31443
31724
|
var STILL_ASKS = "the server still asks for a login after the token exchange";
|
|
@@ -31445,7 +31726,7 @@ var Reason = class extends Error {
|
|
|
31445
31726
|
};
|
|
31446
31727
|
var notStarted = (err, url2) => {
|
|
31447
31728
|
if (err instanceof Reason) return err.message;
|
|
31448
|
-
const text2 =
|
|
31729
|
+
const text2 = failure3(err);
|
|
31449
31730
|
if (text2 === NO_REGISTRATION)
|
|
31450
31731
|
return 'its authorization server has no dynamic client registration. Calls that need a token need "clientId" in "oauth": see "OAuth login" in the README';
|
|
31451
31732
|
const other = OTHER_RESOURCE.exec(text2)?.[1];
|
|
@@ -31535,7 +31816,7 @@ var metadataLike = (text2) => {
|
|
|
31535
31816
|
};
|
|
31536
31817
|
var invalidText = (err) => {
|
|
31537
31818
|
const issues = err?.issues;
|
|
31538
|
-
return Array.isArray(issues) ? issues.map((i) => `${i.path.join(".")}: ${i.message}`).join("; ") :
|
|
31819
|
+
return Array.isArray(issues) ? issues.map((i) => `${i.path.join(".")}: ${i.message}`).join("; ") : failure3(err);
|
|
31539
31820
|
};
|
|
31540
31821
|
var takesOAuth = async (url2, fetchFn) => {
|
|
31541
31822
|
let unsure = false;
|
|
@@ -31568,6 +31849,8 @@ var serverOf = (name, file2, io2) => {
|
|
|
31568
31849
|
if (key === void 0 || entry === void 0) return `the config ${file2} has no server "${name}"`;
|
|
31569
31850
|
if (entry.kind === "invalid") return `${name}: ${invalidReason(entry.errors)}`;
|
|
31570
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}`;
|
|
31571
31854
|
if (entry.oauth === void 0)
|
|
31572
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.`;
|
|
31573
31856
|
return { key, server: entry, oauth: entry.oauth };
|
|
@@ -31704,7 +31987,7 @@ ${url2.href}`);
|
|
|
31704
31987
|
io2.print(`Logged in to ${key}. It has ${plural2(tools.length)}. The tokens are in ${store}${mode}.`);
|
|
31705
31988
|
return 0;
|
|
31706
31989
|
} catch (err) {
|
|
31707
|
-
io2.print(`login to ${key} failed: ${hide2(
|
|
31990
|
+
io2.print(`login to ${key} failed: ${hide2(failure3(err))}`);
|
|
31708
31991
|
return 1;
|
|
31709
31992
|
} finally {
|
|
31710
31993
|
clearTimeout(timer);
|
|
@@ -33233,7 +33516,7 @@ import os4 from "node:os";
|
|
|
33233
33516
|
import path14 from "node:path";
|
|
33234
33517
|
|
|
33235
33518
|
// src/host/run.ts
|
|
33236
|
-
import { createHash as
|
|
33519
|
+
import { createHash as createHash5, randomBytes as randomBytes2, randomUUID as randomUUID5 } from "node:crypto";
|
|
33237
33520
|
import fs15 from "node:fs";
|
|
33238
33521
|
import path13 from "node:path";
|
|
33239
33522
|
|
|
@@ -33571,7 +33854,7 @@ var saveFile = async (dir, name, data) => {
|
|
|
33571
33854
|
await fs15.promises.writeFile(file2, text2, { mode: 384 });
|
|
33572
33855
|
return { ok: true, value: file2 };
|
|
33573
33856
|
};
|
|
33574
|
-
var
|
|
33857
|
+
var sha2562 = (bytes) => createHash5("sha256").update(bytes).digest("hex");
|
|
33575
33858
|
var writeAttachments = async (dir, files, written2) => {
|
|
33576
33859
|
if (files.length === 0) return;
|
|
33577
33860
|
await fs15.promises.mkdir(dir, { recursive: true, mode: 448 });
|
|
@@ -33584,7 +33867,7 @@ var writeAttachments = async (dir, files, written2) => {
|
|
|
33584
33867
|
});
|
|
33585
33868
|
throw err;
|
|
33586
33869
|
});
|
|
33587
|
-
done.push({ file: file2, record: { mimeType, bytes: bytes.length, sha256:
|
|
33870
|
+
done.push({ file: file2, record: { mimeType, bytes: bytes.length, sha256: sha2562(bytes) } });
|
|
33588
33871
|
}
|
|
33589
33872
|
} catch (err) {
|
|
33590
33873
|
await Promise.all(done.map(({ file: file2 }) => fs15.promises.rm(file2, { force: true }).catch(() => {
|
|
@@ -33609,7 +33892,7 @@ var showImages = async (written2, returned) => {
|
|
|
33609
33892
|
if (stat.size !== record2.bytes) return "changed";
|
|
33610
33893
|
const bytes = await fs15.promises.readFile(file2).catch(() => void 0);
|
|
33611
33894
|
if (bytes === void 0) return "unreadable";
|
|
33612
|
-
if (bytes.length !== record2.bytes ||
|
|
33895
|
+
if (bytes.length !== record2.bytes || sha2562(bytes) !== record2.sha256) return "changed";
|
|
33613
33896
|
if (!holdsImage(record2.mimeType, bytes)) return "not-image";
|
|
33614
33897
|
total += bytes.length;
|
|
33615
33898
|
return { data: bytes.toString("base64"), mimeType: record2.mimeType };
|
|
@@ -33802,7 +34085,7 @@ could not answer message ${id} of the program: ${errorText(err)}`;
|
|
|
33802
34085
|
const answerCall = async (id, tool, args, sentKey) => {
|
|
33803
34086
|
if (ended) return;
|
|
33804
34087
|
const began = performance.now();
|
|
33805
|
-
const { code:
|
|
34088
|
+
const { code: failure4, cls, untrusted: fromTool, ...r } = await callTool(id, tool, args);
|
|
33806
34089
|
if (closed) return;
|
|
33807
34090
|
if (fromTool === true) untrusted = true;
|
|
33808
34091
|
const tainted = untrusted;
|
|
@@ -33811,7 +34094,7 @@ could not answer message ${id} of the program: ${errorText(err)}`;
|
|
|
33811
34094
|
decision: decided.get(id),
|
|
33812
34095
|
ms: performance.now() - began,
|
|
33813
34096
|
ok: r.ok,
|
|
33814
|
-
...r.ok ? {} : { error:
|
|
34097
|
+
...r.ok ? {} : { error: failure4 ?? "failed" },
|
|
33815
34098
|
...r.ok || cls === void 0 ? {} : { class: cls }
|
|
33816
34099
|
});
|
|
33817
34100
|
const key = sentKey ?? callKey(tool, args);
|