hmcp-gateway 0.0.2 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. package/LICENSE +77 -0
  2. package/README.md +41 -9
  3. package/bin/hmcp-gateway.js +20 -0
  4. package/catalog/atlassian.yaml +41 -0
  5. package/catalog/brave-search.yaml +57 -0
  6. package/catalog/context7.yaml +42 -0
  7. package/catalog/fetch.yaml +37 -0
  8. package/catalog/figma.yaml +48 -0
  9. package/catalog/filesystem.yaml +48 -0
  10. package/catalog/git.yaml +48 -0
  11. package/catalog/github.yaml +103 -0
  12. package/catalog/huggingface.yaml +59 -0
  13. package/catalog/linear.yaml +47 -0
  14. package/catalog/memory.yaml +47 -0
  15. package/catalog/notion.yaml +41 -0
  16. package/catalog/playwright.yaml +38 -0
  17. package/catalog/postgres.yaml +66 -0
  18. package/catalog/sentry.yaml +39 -0
  19. package/catalog/sequential-thinking.yaml +29 -0
  20. package/catalog/stripe.yaml +41 -0
  21. package/catalog/supabase.yaml +45 -0
  22. package/catalog/time.yaml +49 -0
  23. package/dist/adopt-cli.d.ts +351 -0
  24. package/dist/adopt-cli.js +1857 -0
  25. package/dist/adopt-emit.d.ts +64 -0
  26. package/dist/adopt-emit.js +248 -0
  27. package/dist/adopt-plan.d.ts +108 -0
  28. package/dist/adopt-plan.js +386 -0
  29. package/dist/catalog.d.ts +140 -0
  30. package/dist/catalog.js +250 -0
  31. package/dist/classify.d.ts +23 -0
  32. package/dist/classify.js +47 -0
  33. package/dist/cli.d.ts +2 -0
  34. package/dist/cli.js +535 -0
  35. package/dist/client-allow.d.ts +42 -0
  36. package/dist/client-allow.js +95 -0
  37. package/dist/client-config.d.ts +200 -0
  38. package/dist/client-config.js +784 -0
  39. package/dist/config-source.d.ts +106 -0
  40. package/dist/config-source.js +156 -0
  41. package/dist/config.d.ts +159 -0
  42. package/dist/config.js +330 -0
  43. package/dist/connect-client.d.ts +49 -0
  44. package/dist/connect-client.js +249 -0
  45. package/dist/contracts.d.ts +251 -0
  46. package/dist/contracts.js +9 -0
  47. package/dist/credential.d.ts +63 -0
  48. package/dist/credential.js +136 -0
  49. package/dist/draft.d.ts +71 -0
  50. package/dist/draft.js +596 -0
  51. package/dist/exposure-cli.d.ts +28 -0
  52. package/dist/exposure-cli.js +119 -0
  53. package/dist/gateway.d.ts +756 -0
  54. package/dist/gateway.js +2106 -0
  55. package/dist/index.d.ts +26 -0
  56. package/dist/index.js +26 -0
  57. package/dist/notify.d.ts +44 -0
  58. package/dist/notify.js +93 -0
  59. package/dist/oauth.d.ts +139 -0
  60. package/dist/oauth.js +641 -0
  61. package/dist/observe.d.ts +10 -0
  62. package/dist/observe.js +26 -0
  63. package/dist/open.d.ts +24 -0
  64. package/dist/open.js +31 -0
  65. package/dist/packs.d.ts +119 -0
  66. package/dist/packs.js +131 -0
  67. package/dist/pin-cli.d.ts +28 -0
  68. package/dist/pin-cli.js +103 -0
  69. package/dist/probe-upstream.d.ts +31 -0
  70. package/dist/probe-upstream.js +377 -0
  71. package/dist/registry-map.d.ts +39 -0
  72. package/dist/registry-map.js +390 -0
  73. package/dist/rule-cli.d.ts +51 -0
  74. package/dist/rule-cli.js +412 -0
  75. package/dist/serve-http.d.ts +67 -0
  76. package/dist/serve-http.js +478 -0
  77. package/dist/snippet.d.ts +20 -0
  78. package/dist/snippet.js +826 -0
  79. package/dist/status-cli.d.ts +61 -0
  80. package/dist/status-cli.js +195 -0
  81. package/dist/suggest-cli.d.ts +43 -0
  82. package/dist/suggest-cli.js +279 -0
  83. package/dist/toolname.d.ts +47 -0
  84. package/dist/toolname.js +149 -0
  85. package/dist/upstream-errors.d.ts +54 -0
  86. package/dist/upstream-errors.js +330 -0
  87. package/dist/upstream.d.ts +128 -0
  88. package/dist/upstream.js +413 -0
  89. package/dist/version.d.ts +10 -0
  90. package/dist/version.js +11 -0
  91. package/package.json +50 -6
  92. package/packs/brave-search.yaml +20 -0
  93. package/packs/context7.yaml +13 -0
  94. package/packs/fetch.yaml +14 -0
  95. package/packs/filesystem.yaml +79 -0
  96. package/packs/git.yaml +29 -0
  97. package/packs/github.yaml +47 -0
  98. package/packs/huggingface.yaml +16 -0
  99. package/packs/memory.yaml +23 -0
  100. package/packs/playwright.yaml +41 -0
  101. package/packs/sequential-thinking.yaml +13 -0
  102. package/packs/time.yaml +14 -0
@@ -0,0 +1,390 @@
1
+ import { addressKind, localAddressWarning, safeName } from "./draft.js";
2
+ const RUNNERS = { npm: "node", pypi: "uv", oci: "docker" };
3
+ /** A setting name a program can be given; never one that starts like an option ("--privileged"). */
4
+ const ENV_NAME = /^[A-Za-z_][A-Za-z0-9_.-]*$/;
5
+ /* ------------------------------------------------------------------ docker */
6
+ /** `docker run` options that take no value. */
7
+ const DOCKER_SWITCHES = new Set(["-i", "--interactive", "-t", "--tty", "--rm", "--init", "--read-only", "-d", "--detach", "-it", "-ti"]);
8
+ /**
9
+ * `docker run` options that take away what keeps a container apart from the
10
+ * computer: the whole disk, the host's network, its processes, its devices,
11
+ * extra powers. Picking the Docker option because it is the contained one is
12
+ * pointless with any of these.
13
+ */
14
+ const DOCKER_OPENS_UP = [
15
+ { test: (f) => f === "--privileged", words: "gives it full control of this computer (--privileged)" },
16
+ {
17
+ // A named volume ("data:/app") is Docker's own storage; a path is a folder of this computer.
18
+ test: (f, v) => ((f === "-v" || f === "--volume") && /^([/~.$]|[A-Za-z]:[\\/])/.test(v)) ||
19
+ // Every `type=` in it, not the first: `type=volume,type=bind` is a bind.
20
+ (f === "--mount" && v.split(",").some((part) => /^type=/.test(part) && !/^type=(volume|tmpfs)$/.test(part))) ||
21
+ (f === "--mount" && /(^|,)(source|src)=([/~.$]|[A-Za-z]:[\\/])/.test(v) && !/(^|,)type=tmpfs(,|$)/.test(v)) ||
22
+ f === "--volumes-from",
23
+ words: "mounts folders of this computer into it"
24
+ },
25
+ { test: (f, v) => (f === "--network" || f === "--net") && /^(host|container:)/.test(v), words: "puts it on this computer's own network" },
26
+ { test: (f, v) => ["--pid", "--ipc", "--uts", "--userns", "--cgroupns"].includes(f) && /^(host|container:)/.test(v), words: "lets it see this computer's own programs" },
27
+ { test: (f) => f === "--cap-add", words: "gives it extra powers (--cap-add)" },
28
+ { test: (f) => f === "--device" || f === "--device-cgroup-rule" || f === "--gpus", words: "gives it this computer's devices" },
29
+ { test: (f, v) => f === "--security-opt" && /(unconfined|disable|label[:=]disable)/i.test(v), words: "switches off Docker's own protection" },
30
+ { test: (f) => f === "--env-file", words: "reads a file from this computer into it" }
31
+ ];
32
+ /**
33
+ * Why a `docker run …` command line is not contained, in plain words, or
34
+ * null when it is. Only the options before the image are looked at: what
35
+ * comes after the image goes to the server itself, not to Docker.
36
+ */
37
+ export function dockerArgsProblem(args) {
38
+ const found = [];
39
+ for (const { flag, value } of dockerRunOptions(args)) {
40
+ for (const rule of DOCKER_OPENS_UP)
41
+ if (rule.test(flag, value) && !found.includes(rule.words))
42
+ found.push(rule.words);
43
+ }
44
+ if (found.length === 0)
45
+ return null;
46
+ return `This runs in Docker with options that take away Docker's walls: it ${found.join(", ")}.`;
47
+ }
48
+ /** `docker run` one-letter options that take no value; every other letter takes one. */
49
+ const DOCKER_SHORT_SWITCHES = new Set(["i", "t", "d", "P", "q"]);
50
+ /**
51
+ * The options before the image, read the way Docker's own parser reads them
52
+ * (R2 N2): `-v/:/host` is `-v` with the value attached, `-itv /:/host` is
53
+ * `-i`, `-t` and `-v /:/host`, and `--volume=/:/host` is `--volume`. Reading
54
+ * whole tokens only let the first two through. A letter this doesn't know is
55
+ * taken to take a value, so nothing after it is mistaken for the image.
56
+ */
57
+ export function dockerRunOptions(args) {
58
+ const out = [];
59
+ const start = args[0] === "run" ? 1 : 0;
60
+ for (let i = start; i < args.length; i++) {
61
+ const a = args[i];
62
+ if (a === "--")
63
+ break;
64
+ if (!a.startsWith("-") || a === "-")
65
+ break; // the image
66
+ if (a.startsWith("--")) {
67
+ const eq = a.indexOf("=");
68
+ const flag = eq > 0 ? a.slice(0, eq) : a;
69
+ const value = eq > 0 ? a.slice(eq + 1) : DOCKER_SWITCHES.has(flag) ? "" : (args[++i] ?? "");
70
+ out.push({ flag, value });
71
+ continue;
72
+ }
73
+ // One dash: a run of letters, the first that takes a value ending it.
74
+ const letters = a.slice(1);
75
+ for (let k = 0; k < letters.length; k++) {
76
+ const c = letters[k];
77
+ if (DOCKER_SHORT_SWITCHES.has(c)) {
78
+ out.push({ flag: `-${c}`, value: "" });
79
+ continue;
80
+ }
81
+ let rest = letters.slice(k + 1);
82
+ if (rest.startsWith("="))
83
+ rest = rest.slice(1);
84
+ out.push({ flag: `-${c}`, value: rest !== "" ? rest : (args[++i] ?? "") });
85
+ break;
86
+ }
87
+ }
88
+ return out;
89
+ }
90
+ const str = (v) => (typeof v === "string" && v.trim() !== "" ? v : undefined);
91
+ const arr = (v) => (Array.isArray(v) ? v : []);
92
+ export function mapServerJson(item, catalogNames = new Map()) {
93
+ const s = item.server ?? {};
94
+ const name = str(s["name"]) ?? "unknown";
95
+ const title = str(s["title"]);
96
+ const description = str(s["description"]) ?? "";
97
+ const version = str(s["version"]) ?? "";
98
+ const repoUrl = str(s["repository"]?.url);
99
+ const catalogId = catalogNames.get(name);
100
+ const base = {
101
+ name,
102
+ ...(title ? { title } : {}),
103
+ description,
104
+ version,
105
+ ...(repoUrl ? { repository: repoUrl } : {}),
106
+ ...(catalogId ? { catalogId } : {}),
107
+ draft: null
108
+ };
109
+ const packages = arr(s["packages"]);
110
+ const remotes = arr(s["remotes"]);
111
+ /*
112
+ * A hosted address first: nothing to install is the easiest thing to get
113
+ * working. Then a package, npm before PyPI before a container, in the
114
+ * order a typical machine is most likely to already have the runner for.
115
+ */
116
+ const remote = remotes.find((r) => r.type === "streamable-http" && str(r.url));
117
+ const pkg = ["npm", "pypi", "oci"]
118
+ .map((t) => packages.find((p) => p.registryType === t && (p.transport?.type ?? "stdio") === "stdio" && str(p.identifier)))
119
+ .find(Boolean);
120
+ const attempts = [];
121
+ if (remote)
122
+ attempts.push(() => fromRemote(remote));
123
+ if (pkg)
124
+ attempts.push(() => fromPackage(pkg));
125
+ let refusal;
126
+ for (const attempt of attempts) {
127
+ const built = attempt();
128
+ if ("refused" in built) {
129
+ refusal ??= built.refused;
130
+ continue;
131
+ }
132
+ return { ...base, draft: toDraft(name, title, version, repoUrl, built) };
133
+ }
134
+ return { ...base, unsupported: refusal ?? whyUnsupported(packages, remotes) };
135
+ }
136
+ class Fields {
137
+ list = [];
138
+ ids = new Set();
139
+ add(raw, make) {
140
+ let id = raw.toLowerCase().replace(/[^a-z0-9_]+/g, "_").replace(/^_+|_+$/g, "");
141
+ if (!/^[a-z]/.test(id))
142
+ id = `f_${id}`;
143
+ if (id === "f_")
144
+ id = "value";
145
+ let unique = id;
146
+ for (let i = 2; this.ids.has(unique); i++)
147
+ unique = `${id}_${i}`;
148
+ this.ids.add(unique);
149
+ this.list.push({ id: unique, ...make(unique) });
150
+ return unique;
151
+ }
152
+ }
153
+ /** Plain field for a setting the server reads. */
154
+ function fieldFor(input, label, technical) {
155
+ const help = str(input.description);
156
+ const choices = arr(input.choices).filter((c) => typeof c === "string");
157
+ // A folder is offered the folder picker; a file path ("..._FILE") stays text.
158
+ const nameSaysFile = /file/i.test(input.name ?? "");
159
+ const looksLikeFolder = !nameSaysFile &&
160
+ (/(^|[_-])(dir|directory|folder|path|root)s?($|[_-])/i.test(input.name ?? "") ||
161
+ /\b(directory|folder|root)\b/i.test(input.description ?? ""));
162
+ const kind = input.isSecret
163
+ ? "secret"
164
+ : input.format === "boolean"
165
+ ? "toggle"
166
+ : choices.length > 0
167
+ ? "choice"
168
+ : looksLikeFolder
169
+ ? "folder"
170
+ : "text";
171
+ return {
172
+ kind,
173
+ label,
174
+ ...(help ? { help } : {}),
175
+ ...(input.isRequired ? { required: true } : {}),
176
+ ...(!input.isSecret && str(input.default)
177
+ ? { default: input.format === "boolean" ? /^(true|1|yes)$/i.test(input.default) : input.default }
178
+ : {}),
179
+ ...(kind === "choice" ? { choices: choices.map((c) => ({ value: c, label: c })) } : {}),
180
+ ...(technical ? { technical } : {})
181
+ };
182
+ }
183
+ /** Arguments as the template's args; refused when a key would have to be one. */
184
+ function argsFor(inputs, fields) {
185
+ const out = [];
186
+ for (const a of inputs) {
187
+ const fixed = str(a.value);
188
+ if (a.isSecret && !fixed) {
189
+ if (!a.isRequired)
190
+ continue;
191
+ return {
192
+ refused: "This server wants its key typed on the command line, where it would be saved as plain text. " +
193
+ "hardened-mcp only keeps keys in the locked keys file, so it cannot add this one."
194
+ };
195
+ }
196
+ if (a.type === "named") {
197
+ const flag = str(a.name);
198
+ if (!flag)
199
+ continue;
200
+ if (fixed) {
201
+ out.push(flag, fixed);
202
+ continue;
203
+ }
204
+ if (!a.isRequired && !str(a.default))
205
+ continue; // optional and unset: leave it to the server's own default
206
+ if (a.format === "boolean") {
207
+ out.push(flag);
208
+ continue;
209
+ }
210
+ const id = fields.add(flag.replace(/^-+/, ""), () => fieldFor(a, labelFor(flag, a), flag));
211
+ out.push(flag, `{{fields.${id}}}`);
212
+ continue;
213
+ }
214
+ // positional
215
+ if (fixed) {
216
+ out.push(fixed);
217
+ continue;
218
+ }
219
+ if (!a.isRequired && !str(a.default))
220
+ continue;
221
+ const id = fields.add(str(a.valueHint) ?? str(a.name) ?? "argument", () => fieldFor(a, labelFor(str(a.valueHint) ?? str(a.name) ?? "Setting", a), undefined));
222
+ out.push(`{{fields.${id}}}`);
223
+ }
224
+ return out;
225
+ }
226
+ function envFor(vars, fields) {
227
+ const env = {};
228
+ for (const v of vars) {
229
+ const key = str(v.name);
230
+ if (!key)
231
+ continue;
232
+ if (!ENV_NAME.test(key)) {
233
+ return { refused: `This server asks for a setting called “${key.slice(0, 40)}”, which is not a name a setting can have, so it can't be added safely.` };
234
+ }
235
+ const fixed = str(v.value);
236
+ if (fixed && !v.isSecret) {
237
+ env[key] = fixed;
238
+ continue;
239
+ }
240
+ const id = fields.add(key, () => fieldFor(v, labelFor(key, v), key));
241
+ env[key] = v.isSecret ? { field: id } : `{{fields.${id}}}`;
242
+ }
243
+ return { env };
244
+ }
245
+ function fromPackage(p) {
246
+ const fields = new Fields();
247
+ const type = p.registryType;
248
+ const version = str(p.version);
249
+ const runtimeArgs = argsFor(arr(p.runtimeArguments), fields);
250
+ if ("refused" in runtimeArgs)
251
+ return runtimeArgs;
252
+ const packageArgs = argsFor(arr(p.packageArguments), fields);
253
+ if ("refused" in packageArgs)
254
+ return packageArgs;
255
+ const envOrRefusal = envFor(arr(p.environmentVariables), fields);
256
+ if ("refused" in envOrRefusal)
257
+ return envOrRefusal;
258
+ const env = envOrRefusal.env;
259
+ const id = p.identifier;
260
+ // An identifier that starts with "-" is an option in disguise (npx --call=…).
261
+ if (/^-/.test(id) || /\s/.test(id)) {
262
+ return { refused: "This server's package name is not a real package name, so it can't be added safely." };
263
+ }
264
+ let launch;
265
+ if (type === "npm") {
266
+ // "@scope/name" has an @ at 0; one further along means a version is already given.
267
+ const spec = version && id.lastIndexOf("@") <= 0 ? `${id}@${version}` : id;
268
+ const pre = runtimeArgs.includes("-y") || runtimeArgs.includes("--yes") ? runtimeArgs : ["-y", ...runtimeArgs];
269
+ launch = { transport: "stdio", command: "npx", args: [...pre, spec, ...packageArgs], env };
270
+ }
271
+ else if (type === "pypi") {
272
+ const spec = version && !id.includes("==") ? `${id}==${version}` : id;
273
+ launch = { transport: "stdio", command: "uvx", args: [...runtimeArgs, spec, ...packageArgs], env };
274
+ }
275
+ else {
276
+ // The image's own tag wins; the version is only added to a bare image name.
277
+ const lastSegment = id.split("/").pop() ?? id;
278
+ const image = version && !lastSegment.includes(":") && !id.includes("@sha256:") ? `${id}:${version}` : id;
279
+ const passEnv = Object.keys(env).flatMap((k) => ["-e", k]);
280
+ const opens = dockerArgsProblem(["run", ...runtimeArgs, image]);
281
+ if (opens)
282
+ return { refused: `${opens} A server from the public list can't be added like that.` };
283
+ launch = { transport: "stdio", command: "docker", args: ["run", "-i", "--rm", ...passEnv, ...runtimeArgs, image, ...packageArgs], env };
284
+ }
285
+ return { launch, fields: fields.list, requires: [RUNNERS[type]], warnings: [] };
286
+ }
287
+ function fromRemote(r) {
288
+ const fields = new Fields();
289
+ const warnings = [];
290
+ let url = r.url;
291
+ // `{region}` in the address is a setting the person fills in.
292
+ for (const [key, input] of Object.entries(r.variables ?? {})) {
293
+ const id = fields.add(key, () => fieldFor({ ...input, name: key }, labelFor(key, input), key));
294
+ url = url.split(`{${key}}`).join(`{{fields.${id}}}`);
295
+ }
296
+ if (/\{[a-z0-9_]+\}/i.test(url.replace(/\{\{[^}]*\}\}/g, ""))) {
297
+ return { refused: "This server's address has a part to fill in that the public list does not describe." };
298
+ }
299
+ try {
300
+ const kind = addressKind(new URL(url.replace(/\{\{[^}]*\}\}/g, "x")).hostname);
301
+ if (kind === "link-local")
302
+ return { refused: localAddressWarning(kind) };
303
+ const words = localAddressWarning(kind);
304
+ if (words)
305
+ warnings.push(words);
306
+ }
307
+ catch {
308
+ /* a templated address is checked when it is filled in */
309
+ }
310
+ const headers = {};
311
+ for (const h of arr(r.headers)) {
312
+ const key = str(h.name);
313
+ if (!key)
314
+ continue;
315
+ const fixed = str(h.value);
316
+ if (fixed && !h.isSecret && !/\{[^}]*\}/.test(fixed)) {
317
+ headers[key] = fixed;
318
+ continue;
319
+ }
320
+ const bearer = /^authorization$/i.test(key) && (/bearer/i.test(`${h.description ?? ""} ${fixed ?? ""}`) || h.isSecret);
321
+ const id = fields.add(key, () => fieldFor({ ...h, isSecret: h.isSecret || /^authorization$/i.test(key) }, labelFor(key, h), key));
322
+ const field = fields.list.find((f) => f.id === id);
323
+ headers[key] = field.kind === "secret" ? { field: id, ...(bearer ? { prefix: "Bearer " } : {}) } : `{{fields.${id}}}`;
324
+ }
325
+ return {
326
+ launch: { transport: "http", url, ...(Object.keys(headers).length ? { headers } : {}) },
327
+ fields: fields.list,
328
+ requires: [],
329
+ warnings
330
+ };
331
+ }
332
+ function whyUnsupported(packages, remotes) {
333
+ if (remotes.some((r) => r.type === "sse")) {
334
+ return "This server only offers an older kind of connection (SSE) that hardened-mcp does not support. Ask its makers for a Streamable HTTP address.";
335
+ }
336
+ if (packages.some((p) => ["npm", "pypi", "oci"].includes(p.registryType ?? "") && p.transport?.type && p.transport.type !== "stdio")) {
337
+ return "This server has to be started separately before anything can connect to it, which hardened-mcp cannot do for you yet.";
338
+ }
339
+ const kinds = [...new Set(packages.map((p) => p.registryType).filter(Boolean))];
340
+ if (kinds.length > 0) {
341
+ return `This server is only published as a package of a kind hardened-mcp cannot start yet (${kinds.join(", ")}).`;
342
+ }
343
+ return "The public list does not say how to start or reach this server.";
344
+ }
345
+ /* ------------------------------------------------------------------ the draft */
346
+ /** "playwright-stealth" -> "Playwright stealth": a public-list name as a title. */
347
+ function readable(short) {
348
+ const t = short.replace(/[-_.]+/g, " ").trim();
349
+ return t ? t[0].toUpperCase() + t.slice(1) : short;
350
+ }
351
+ function labelFor(technicalName, input) {
352
+ const words = technicalName
353
+ .replace(/^-+/, "")
354
+ .replace(/[_-]+/g, " ")
355
+ .trim()
356
+ .toLowerCase();
357
+ const nice = words ? words[0].toUpperCase() + words.slice(1) : "Setting";
358
+ return input.isSecret ? `${nice} (kept locked)` : nice;
359
+ }
360
+ function toDraft(name, title, version, repo, built) {
361
+ const short = name.split("/").pop() ?? name;
362
+ const guide = [
363
+ {
364
+ title: "Check who made it",
365
+ body: "This server comes from the public MCP list. Nobody has checked it, including us. " +
366
+ "Look at who publishes it before you give it a key or a folder.",
367
+ ...(repo && repo.startsWith("https://") ? { link: { label: "Open its project page", url: repo } } : {})
368
+ },
369
+ {
370
+ title: built.fields.length > 0 ? "Fill in its settings" : "Nothing to fill in",
371
+ body: built.fields.length > 0
372
+ ? "Fill in the settings below. Anything marked as a key is kept in the locked keys file, never in a settings file."
373
+ : "The public list doesn't mention any settings for this server, so there's nothing to fill in."
374
+ },
375
+ {
376
+ title: "Test it",
377
+ body: "Click **Test it** to start it and see what it lets the AI do before you save anything."
378
+ }
379
+ ];
380
+ return {
381
+ source: { kind: "registry", name, ...(version ? { version } : {}) },
382
+ name: safeName(short),
383
+ displayName: title ?? readable(short),
384
+ launch: built.launch,
385
+ fields: built.fields,
386
+ guide,
387
+ requires: built.requires,
388
+ warnings: ["From the public list — not checked by us.", ...built.warnings]
389
+ };
390
+ }
@@ -0,0 +1,51 @@
1
+ import { type ArgConstraint } from "hmcp-core";
2
+ /**
3
+ * Setting a tool's rule from a terminal: what it is, what happens when it is
4
+ * called, and the bounds that qualify it.
5
+ *
6
+ * The console's dialog asks the same questions behind a form. This exists for
7
+ * the same reason `hmcp-gateway exposure` does: the person who owns the machine
8
+ * should not need a browser, and in an incident the console may be the thing
9
+ * that is down.
10
+ *
11
+ * Unlike `exposure`, this never connects an upstream. The tool names come from
12
+ * what a *running* gateway published into the approvals database -- the same
13
+ * source the console reads. Spawning an upstream to find out what it offers,
14
+ * only to write a line into a policy file, would start child processes for a
15
+ * text edit; and a name taken from a gateway that is not running is a rule
16
+ * about a tool nobody serves.
17
+ */
18
+ export interface RuleCommandOptions {
19
+ readonly config: string;
20
+ /** Omitted with `list`. */
21
+ readonly tool?: string | undefined;
22
+ readonly effect?: string | undefined;
23
+ readonly decision?: string | undefined;
24
+ readonly reason?: string | undefined;
25
+ /** `body.maxLength=120`, repeatable. */
26
+ readonly bound?: readonly string[] | undefined;
27
+ readonly onViolation?: string | undefined;
28
+ readonly unknownArgs?: string | undefined;
29
+ /** Keep or drop the bounds the governing rule sets. */
30
+ readonly keepBounds?: boolean | undefined;
31
+ readonly dropBounds?: boolean | undefined;
32
+ /** Names the rule whose decision is being reversed. */
33
+ readonly overrideDeny?: string | undefined;
34
+ /** Remove the console's rule and hand the tool back to policy. */
35
+ readonly clear?: boolean | undefined;
36
+ /** List what is unclassified and what the console has set, then stop. */
37
+ readonly list?: boolean | undefined;
38
+ /** Print the rule and the outcome, write nothing. */
39
+ readonly dryRun?: boolean | undefined;
40
+ /** Required for `--effect destructive --decision allow`. */
41
+ readonly yesReally?: boolean | undefined;
42
+ readonly json?: boolean | undefined;
43
+ /** Injected by the CLI; the tests capture it. */
44
+ readonly write?: ((line: string) => void) | undefined;
45
+ /** Injected by the tests in place of a terminal. */
46
+ readonly ask?: ((question: string) => Promise<string>) | undefined;
47
+ }
48
+ export declare class RuleCommandError extends Error {
49
+ }
50
+ export declare function parseBound(spec: string, into: Record<string, ArgConstraint>): void;
51
+ export declare function runRuleCommand(options: RuleCommandOptions): Promise<void>;