hmcp-gateway 0.0.2 → 0.2.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 (114) hide show
  1. package/LICENSE +77 -0
  2. package/README.md +135 -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 +355 -0
  24. package/dist/adopt-cli.js +1885 -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 +501 -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 +656 -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 +263 -0
  38. package/dist/client-config.js +995 -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 +51 -0
  44. package/dist/connect-client.js +299 -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/desktop-extensions.d.ts +53 -0
  50. package/dist/desktop-extensions.js +126 -0
  51. package/dist/draft.d.ts +71 -0
  52. package/dist/draft.js +596 -0
  53. package/dist/exposure-cli.d.ts +28 -0
  54. package/dist/exposure-cli.js +119 -0
  55. package/dist/gateway.d.ts +766 -0
  56. package/dist/gateway.js +2122 -0
  57. package/dist/github-doors.d.ts +162 -0
  58. package/dist/github-doors.js +780 -0
  59. package/dist/guard-install.d.ts +109 -0
  60. package/dist/guard-install.js +396 -0
  61. package/dist/guard.d.ts +265 -0
  62. package/dist/guard.js +975 -0
  63. package/dist/import-client.d.ts +184 -0
  64. package/dist/import-client.js +578 -0
  65. package/dist/index.d.ts +31 -0
  66. package/dist/index.js +31 -0
  67. package/dist/notify.d.ts +44 -0
  68. package/dist/notify.js +93 -0
  69. package/dist/oauth.d.ts +139 -0
  70. package/dist/oauth.js +641 -0
  71. package/dist/observe.d.ts +10 -0
  72. package/dist/observe.js +26 -0
  73. package/dist/open.d.ts +24 -0
  74. package/dist/open.js +31 -0
  75. package/dist/packs.d.ts +119 -0
  76. package/dist/packs.js +131 -0
  77. package/dist/pin-cli.d.ts +28 -0
  78. package/dist/pin-cli.js +103 -0
  79. package/dist/probe-upstream.d.ts +31 -0
  80. package/dist/probe-upstream.js +377 -0
  81. package/dist/registry-map.d.ts +39 -0
  82. package/dist/registry-map.js +390 -0
  83. package/dist/rule-cli.d.ts +51 -0
  84. package/dist/rule-cli.js +412 -0
  85. package/dist/serve-http.d.ts +67 -0
  86. package/dist/serve-http.js +478 -0
  87. package/dist/snippet.d.ts +20 -0
  88. package/dist/snippet.js +826 -0
  89. package/dist/status-cli.d.ts +61 -0
  90. package/dist/status-cli.js +195 -0
  91. package/dist/suggest-cli.d.ts +43 -0
  92. package/dist/suggest-cli.js +279 -0
  93. package/dist/toml-edit.d.ts +43 -0
  94. package/dist/toml-edit.js +363 -0
  95. package/dist/toolname.d.ts +47 -0
  96. package/dist/toolname.js +149 -0
  97. package/dist/upstream-errors.d.ts +54 -0
  98. package/dist/upstream-errors.js +330 -0
  99. package/dist/upstream.d.ts +128 -0
  100. package/dist/upstream.js +413 -0
  101. package/dist/version.d.ts +10 -0
  102. package/dist/version.js +11 -0
  103. package/package.json +51 -6
  104. package/packs/brave-search.yaml +20 -0
  105. package/packs/context7.yaml +13 -0
  106. package/packs/fetch.yaml +14 -0
  107. package/packs/filesystem.yaml +79 -0
  108. package/packs/git.yaml +29 -0
  109. package/packs/github.yaml +47 -0
  110. package/packs/huggingface.yaml +16 -0
  111. package/packs/memory.yaml +23 -0
  112. package/packs/playwright.yaml +41 -0
  113. package/packs/sequential-thinking.yaml +13 -0
  114. package/packs/time.yaml +14 -0
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Flipping a gateway's exposure switch from a terminal.
3
+ *
4
+ * The admin API is for a customer of a hosted gateway. This is for the
5
+ * person who owns the machine, and it exists for the cases that one cannot
6
+ * serve: a gateway with no identity provider configured at all, a gateway
7
+ * speaking stdio, and the incident where the identity provider is itself the
8
+ * thing that is down. A kill switch reachable only through a dependency is
9
+ * not much of a kill switch.
10
+ *
11
+ * Factored out of `cli.ts` so the tests can call it rather than shelling out,
12
+ * which is how every other gateway test works.
13
+ */
14
+ export interface ExposureCommandOptions {
15
+ readonly config: string;
16
+ readonly action: "list" | "off" | "on";
17
+ readonly tool?: string | undefined;
18
+ readonly tenant?: string | undefined;
19
+ readonly reason?: string | undefined;
20
+ /** Skip connecting upstreams, and so skip validating the tool name. */
21
+ readonly force?: boolean | undefined;
22
+ readonly json?: boolean | undefined;
23
+ /** Injected by the CLI; the tests capture it. */
24
+ readonly write?: (line: string) => void;
25
+ }
26
+ export declare class ExposureCommandError extends Error {
27
+ }
28
+ export declare function runExposureCommand(options: ExposureCommandOptions): Promise<void>;
@@ -0,0 +1,119 @@
1
+ import { ApprovalStore, AuditLog, NO_TENANT, applyExposureChange, normalizeTenantKey, parseExposureChange, requireTenant } from "hmcp-core";
2
+ import { dirname } from "node:path";
3
+ import { randomUUID } from "node:crypto";
4
+ import { loadGatewayConfig } from "./config.js";
5
+ import { Gateway } from "./gateway.js";
6
+ export class ExposureCommandError extends Error {
7
+ }
8
+ /** A human at a terminal with the database file: the OS user really is who. */
9
+ function operator() {
10
+ return process.env["HMCP_ACTOR"] ?? process.env["USER"] ?? "operator";
11
+ }
12
+ /**
13
+ * Which tenant's switch this is.
14
+ *
15
+ * Under `jwt-verified` there is no process tenant to resolve — the running
16
+ * gateway gets one per request — so the operator has to say. Guessing `""`
17
+ * here would write a row the gateway never reads, which looks exactly like
18
+ * protection and is none: the most likely bug in this whole design, and the
19
+ * reason this refuses rather than defaults.
20
+ */
21
+ function resolveTenantKey(policy, supplied) {
22
+ if (supplied !== undefined)
23
+ return normalizeTenantKey(supplied);
24
+ if (!policy.tenant)
25
+ return NO_TENANT;
26
+ if (policy.tenant.source.kind === "jwt-verified") {
27
+ throw new ExposureCommandError("this gateway resolves its tenant from each caller's token, so there is no single tenant to act on. " +
28
+ "Pass --tenant <id> to say whose switch you mean.");
29
+ }
30
+ return normalizeTenantKey(requireTenant(policy.tenant) ?? NO_TENANT);
31
+ }
32
+ function describe(row) {
33
+ return `${row.tool} off since ${new Date(row.set_at).toISOString()} by ${row.set_by}${row.reason ? ` — ${row.reason}` : ""}`;
34
+ }
35
+ export async function runExposureCommand(options) {
36
+ const write = options.write ?? ((line) => process.stdout.write(`${line}\n`));
37
+ const { config, policy } = loadGatewayConfig(options.config);
38
+ const tenant = resolveTenantKey(policy, options.tenant);
39
+ const cwd = dirname(options.config);
40
+ const component = `gateway:${config.name}`;
41
+ const store = new ApprovalStore(policy.approvals.store_path, cwd);
42
+ const scoped = store.scoped({ component, tenant });
43
+ /*
44
+ * Connecting spawns or dials every upstream, which is how the tool names
45
+ * are known. `--force` skips it precisely because in an incident the
46
+ * upstream may be the broken thing, and starting it just to flip a bit is
47
+ * the wrong trade.
48
+ */
49
+ let gateway;
50
+ let names;
51
+ if (options.action !== "list" && options.force) {
52
+ write(`[hmcp-gateway] --force: not connecting upstreams, so "${options.tool}" is taken on trust`);
53
+ }
54
+ else {
55
+ gateway = new Gateway({ config, policy, cwd });
56
+ await gateway.connectUpstreams();
57
+ names = gateway.inventory().map((e) => e.localName);
58
+ }
59
+ try {
60
+ if (options.action === "list") {
61
+ const rows = scoped.listDisabledTools();
62
+ if (options.json) {
63
+ write(JSON.stringify({ component, tenant, disabled: rows }, null, 2));
64
+ return;
65
+ }
66
+ write(`${component}${tenant ? ` / ${tenant}` : " (no tenant)"}`);
67
+ if (rows.length === 0) {
68
+ write(" nothing is switched off.");
69
+ }
70
+ else {
71
+ for (const row of rows)
72
+ write(` ${describe(row)}`);
73
+ }
74
+ if (names)
75
+ write(` ${names.length} tool(s) exposed upstream.`);
76
+ return;
77
+ }
78
+ const tool = options.tool;
79
+ if (names && !names.includes(tool)) {
80
+ throw new ExposureCommandError(`this gateway exposes no tool named "${tool}". Run "hmcp-gateway tools" to see what it does, ` +
81
+ `or pass --force if the upstream is down and you are sure of the name.`);
82
+ }
83
+ const change = parseExposureChange({
84
+ tool,
85
+ disabled: options.action === "off",
86
+ reason: options.reason ?? ""
87
+ });
88
+ const { changed, warning } = applyExposureChange({
89
+ scoped,
90
+ audit: new AuditLog({
91
+ config: policy.audit,
92
+ session: `cli:${randomUUID()}`,
93
+ component,
94
+ actor: operator(),
95
+ cwd
96
+ }),
97
+ change,
98
+ actor: operator(),
99
+ effect: gateway?.inventory().find((e) => e.localName === tool)?.effect ?? null,
100
+ channel: "the gateway CLI"
101
+ });
102
+ if (!changed) {
103
+ write(`${tool} was already ${options.action === "off" ? "switched off" : "on"}; nothing changed.`);
104
+ }
105
+ else if (options.action === "off") {
106
+ write(`${tool} is switched off for ${tenant || "this gateway"}. It takes effect on the next call; no restart.`);
107
+ }
108
+ else {
109
+ write(`${tool} is handed back to policy, which may still refuse it.`);
110
+ }
111
+ if (warning)
112
+ write(`warning: ${warning}`);
113
+ }
114
+ finally {
115
+ store.close();
116
+ if (gateway)
117
+ await gateway.close().catch(() => undefined);
118
+ }
119
+ }