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.
- package/LICENSE +77 -0
- package/README.md +41 -9
- package/bin/hmcp-gateway.js +20 -0
- package/catalog/atlassian.yaml +41 -0
- package/catalog/brave-search.yaml +57 -0
- package/catalog/context7.yaml +42 -0
- package/catalog/fetch.yaml +37 -0
- package/catalog/figma.yaml +48 -0
- package/catalog/filesystem.yaml +48 -0
- package/catalog/git.yaml +48 -0
- package/catalog/github.yaml +103 -0
- package/catalog/huggingface.yaml +59 -0
- package/catalog/linear.yaml +47 -0
- package/catalog/memory.yaml +47 -0
- package/catalog/notion.yaml +41 -0
- package/catalog/playwright.yaml +38 -0
- package/catalog/postgres.yaml +66 -0
- package/catalog/sentry.yaml +39 -0
- package/catalog/sequential-thinking.yaml +29 -0
- package/catalog/stripe.yaml +41 -0
- package/catalog/supabase.yaml +45 -0
- package/catalog/time.yaml +49 -0
- package/dist/adopt-cli.d.ts +351 -0
- package/dist/adopt-cli.js +1857 -0
- package/dist/adopt-emit.d.ts +64 -0
- package/dist/adopt-emit.js +248 -0
- package/dist/adopt-plan.d.ts +108 -0
- package/dist/adopt-plan.js +386 -0
- package/dist/catalog.d.ts +140 -0
- package/dist/catalog.js +250 -0
- package/dist/classify.d.ts +23 -0
- package/dist/classify.js +47 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +535 -0
- package/dist/client-allow.d.ts +42 -0
- package/dist/client-allow.js +95 -0
- package/dist/client-config.d.ts +200 -0
- package/dist/client-config.js +784 -0
- package/dist/config-source.d.ts +106 -0
- package/dist/config-source.js +156 -0
- package/dist/config.d.ts +159 -0
- package/dist/config.js +330 -0
- package/dist/connect-client.d.ts +49 -0
- package/dist/connect-client.js +249 -0
- package/dist/contracts.d.ts +251 -0
- package/dist/contracts.js +9 -0
- package/dist/credential.d.ts +63 -0
- package/dist/credential.js +136 -0
- package/dist/draft.d.ts +71 -0
- package/dist/draft.js +596 -0
- package/dist/exposure-cli.d.ts +28 -0
- package/dist/exposure-cli.js +119 -0
- package/dist/gateway.d.ts +756 -0
- package/dist/gateway.js +2106 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.js +26 -0
- package/dist/notify.d.ts +44 -0
- package/dist/notify.js +93 -0
- package/dist/oauth.d.ts +139 -0
- package/dist/oauth.js +641 -0
- package/dist/observe.d.ts +10 -0
- package/dist/observe.js +26 -0
- package/dist/open.d.ts +24 -0
- package/dist/open.js +31 -0
- package/dist/packs.d.ts +119 -0
- package/dist/packs.js +131 -0
- package/dist/pin-cli.d.ts +28 -0
- package/dist/pin-cli.js +103 -0
- package/dist/probe-upstream.d.ts +31 -0
- package/dist/probe-upstream.js +377 -0
- package/dist/registry-map.d.ts +39 -0
- package/dist/registry-map.js +390 -0
- package/dist/rule-cli.d.ts +51 -0
- package/dist/rule-cli.js +412 -0
- package/dist/serve-http.d.ts +67 -0
- package/dist/serve-http.js +478 -0
- package/dist/snippet.d.ts +20 -0
- package/dist/snippet.js +826 -0
- package/dist/status-cli.d.ts +61 -0
- package/dist/status-cli.js +195 -0
- package/dist/suggest-cli.d.ts +43 -0
- package/dist/suggest-cli.js +279 -0
- package/dist/toolname.d.ts +47 -0
- package/dist/toolname.js +149 -0
- package/dist/upstream-errors.d.ts +54 -0
- package/dist/upstream-errors.js +330 -0
- package/dist/upstream.d.ts +128 -0
- package/dist/upstream.js +413 -0
- package/dist/version.d.ts +10 -0
- package/dist/version.js +11 -0
- package/package.json +50 -6
- package/packs/brave-search.yaml +20 -0
- package/packs/context7.yaml +13 -0
- package/packs/fetch.yaml +14 -0
- package/packs/filesystem.yaml +79 -0
- package/packs/git.yaml +29 -0
- package/packs/github.yaml +47 -0
- package/packs/huggingface.yaml +16 -0
- package/packs/memory.yaml +23 -0
- package/packs/playwright.yaml +41 -0
- package/packs/sequential-thinking.yaml +13 -0
- package/packs/time.yaml +14 -0
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
import { classifyAddress, isIpLiteral } from "hmcp-core";
|
|
2
|
+
import { UpstreamSchema } from "./config.js";
|
|
3
|
+
import { isRemote } from "./client-config.js";
|
|
4
|
+
/** Headers that carry no credential, left as they are. Everything else literal is treated as a key. */
|
|
5
|
+
const HARMLESS_HEADERS = new Set(["accept", "accept-language", "content-type", "user-agent", "mcp-protocol-version"]);
|
|
6
|
+
const UPSTREAM_NAME = /^[a-z0-9_]+$/;
|
|
7
|
+
const INTERPOLATION = /\$\{[^}]*\}/;
|
|
8
|
+
/**
|
|
9
|
+
* An upstream name legal under `UpstreamSchema`: lowercase letters, digits and
|
|
10
|
+
* underscores.
|
|
11
|
+
*
|
|
12
|
+
* This is not cosmetic. The result becomes the `<server>__` prefix on every
|
|
13
|
+
* tool name, and that name is a storage key -- the exposure switch, every
|
|
14
|
+
* approval row and each binding hash are stored under it. So it has to be
|
|
15
|
+
* stable across runs, which is why collisions resolve by sorted original name
|
|
16
|
+
* rather than by whatever order the client's JSON happened to be in.
|
|
17
|
+
*/
|
|
18
|
+
export function normalizeUpstreamName(name) {
|
|
19
|
+
return name
|
|
20
|
+
.normalize("NFC")
|
|
21
|
+
.toLowerCase()
|
|
22
|
+
.replace(/[^a-z0-9]+/g, "_")
|
|
23
|
+
.replace(/^_+|_+$/g, "");
|
|
24
|
+
}
|
|
25
|
+
function assignNames(originals, overrides, reserved) {
|
|
26
|
+
const map = new Map();
|
|
27
|
+
const problems = new Map();
|
|
28
|
+
const taken = new Set(reserved);
|
|
29
|
+
let anonymous = 0;
|
|
30
|
+
// Sorted, so two runs over the same set produce the same prefixes.
|
|
31
|
+
for (const original of [...originals].sort()) {
|
|
32
|
+
const override = overrides.get(original);
|
|
33
|
+
if (override !== undefined) {
|
|
34
|
+
if (!UPSTREAM_NAME.test(override)) {
|
|
35
|
+
problems.set(original, `--name ${original}=${override} is not a legal upstream name (${UPSTREAM_NAME})`);
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
if (taken.has(override)) {
|
|
39
|
+
problems.set(original, `--name ${original}=${override} collides with another upstream`);
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
taken.add(override);
|
|
43
|
+
map.set(original, override);
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
let base = normalizeUpstreamName(original);
|
|
47
|
+
if (base === "")
|
|
48
|
+
base = `server_${++anonymous}`;
|
|
49
|
+
let candidate = base;
|
|
50
|
+
for (let n = 2; taken.has(candidate); n++)
|
|
51
|
+
candidate = `${base}_${n}`;
|
|
52
|
+
taken.add(candidate);
|
|
53
|
+
map.set(original, candidate);
|
|
54
|
+
}
|
|
55
|
+
return { map, problems };
|
|
56
|
+
}
|
|
57
|
+
/** Hostname of a URL, or undefined when it will not parse. */
|
|
58
|
+
function hostOf(url) {
|
|
59
|
+
try {
|
|
60
|
+
const parsed = new URL(url);
|
|
61
|
+
return { hostname: parsed.hostname, host: parsed.host, protocol: parsed.protocol };
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Whether this host is one the egress guard refuses without the SSRF
|
|
69
|
+
* protections turned off.
|
|
70
|
+
*
|
|
71
|
+
* `localhost` counts even though it is not a literal: `resolveVerified`
|
|
72
|
+
* resolves it and then refuses the loopback address it gets back, so the
|
|
73
|
+
* hostname form is no more adoptable than `127.0.0.1`.
|
|
74
|
+
*/
|
|
75
|
+
export function isLocalTarget(hostname) {
|
|
76
|
+
const bare = hostname.replace(/^\[|\]$/g, "");
|
|
77
|
+
if (bare === "localhost" || bare.endsWith(".localhost"))
|
|
78
|
+
return true;
|
|
79
|
+
if (!isIpLiteral(bare))
|
|
80
|
+
return false;
|
|
81
|
+
return classifyAddress(bare).blocked;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Whether this entry is the gateway itself.
|
|
85
|
+
*
|
|
86
|
+
* Three independent checks because any one of them can be defeated by a user
|
|
87
|
+
* who renamed something: the entry's name, the command it runs, and the config
|
|
88
|
+
* it points at. Adopting the gateway would make it an upstream of itself.
|
|
89
|
+
*/
|
|
90
|
+
function isGatewayItself(name, server, options) {
|
|
91
|
+
if (name === options.gatewayEntryName)
|
|
92
|
+
return true;
|
|
93
|
+
if (isRemote(server))
|
|
94
|
+
return false;
|
|
95
|
+
const words = [server.command, ...server.args];
|
|
96
|
+
if (words.some((w) => w.includes("hmcp-gateway")))
|
|
97
|
+
return true;
|
|
98
|
+
if (options.gatewayConfigPath !== undefined && words.includes(options.gatewayConfigPath))
|
|
99
|
+
return true;
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
export function planAdoption(servers, options) {
|
|
103
|
+
const upstreams = [];
|
|
104
|
+
const skipped = [];
|
|
105
|
+
const gatewayEnv = {};
|
|
106
|
+
/** Which server claimed each env name, so a collision can name both. */
|
|
107
|
+
const envOwner = new Map();
|
|
108
|
+
const egressAllow = new Set();
|
|
109
|
+
const nameMap = new Map();
|
|
110
|
+
let egressNeedsLocalHttp = false;
|
|
111
|
+
let secretsOnDisk = false;
|
|
112
|
+
const { map: names, problems: nameProblems } = assignNames([...servers.keys()], options.names ?? new Map(), options.reservedNames ?? []);
|
|
113
|
+
for (const [original, problem] of nameProblems) {
|
|
114
|
+
skipped.push({
|
|
115
|
+
name: original,
|
|
116
|
+
reason: problem,
|
|
117
|
+
remedy: `pass a different --name ${original}=<name> using lowercase letters, digits and underscores`
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
for (const original of [...servers.keys()].sort()) {
|
|
121
|
+
const server = servers.get(original);
|
|
122
|
+
const name = names.get(original);
|
|
123
|
+
if (name === undefined)
|
|
124
|
+
continue; // already reported as a name problem
|
|
125
|
+
if (isGatewayItself(original, server, options)) {
|
|
126
|
+
skipped.push({
|
|
127
|
+
name: original,
|
|
128
|
+
reason: "this entry is the gateway itself",
|
|
129
|
+
remedy: "nothing to do; the gateway cannot be an upstream of itself"
|
|
130
|
+
});
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
if (isRemote(server)) {
|
|
134
|
+
const planned = planRemote(original, name, server, options, egressAllow);
|
|
135
|
+
if ("skip" in planned) {
|
|
136
|
+
skipped.push(planned.skip);
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
if (planned.needsLocalHttp)
|
|
140
|
+
egressNeedsLocalHttp = true;
|
|
141
|
+
if (planned.secretOnDisk)
|
|
142
|
+
secretsOnDisk = true;
|
|
143
|
+
upstreams.push(planned.planned);
|
|
144
|
+
if (name !== original)
|
|
145
|
+
nameMap.set(original, name);
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
const planned = planStdio(original, name, server, options, gatewayEnv, envOwner);
|
|
149
|
+
if ("skip" in planned) {
|
|
150
|
+
skipped.push(planned.skip);
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
if (planned.secretOnDisk)
|
|
154
|
+
secretsOnDisk = true;
|
|
155
|
+
upstreams.push(planned.planned);
|
|
156
|
+
if (name !== original)
|
|
157
|
+
nameMap.set(original, name);
|
|
158
|
+
}
|
|
159
|
+
/*
|
|
160
|
+
* The translator and the schema must not be able to drift. Validating here
|
|
161
|
+
* means a tightened `UpstreamSchema` fails in this package's tests rather
|
|
162
|
+
* than in a user's terminal as a zod dump halfway through adoption.
|
|
163
|
+
*/
|
|
164
|
+
for (const { upstream, originalName } of upstreams) {
|
|
165
|
+
const result = UpstreamSchema.safeParse(upstream);
|
|
166
|
+
if (!result.success) {
|
|
167
|
+
throw new Error(`internal: the upstream planned for "${originalName}" does not satisfy UpstreamSchema:\n` +
|
|
168
|
+
result.error.issues.map((i) => ` ${i.path.join(".") || "(root)"}: ${i.message}`).join("\n"));
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return {
|
|
172
|
+
upstreams,
|
|
173
|
+
skipped,
|
|
174
|
+
gatewayEnv,
|
|
175
|
+
egressAllow: [...egressAllow].sort(),
|
|
176
|
+
egressNeedsLocalHttp,
|
|
177
|
+
secretsOnDisk,
|
|
178
|
+
nameMap,
|
|
179
|
+
malformed: options.malformed ?? []
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
function planRemote(original, name, server, options, egressAllow) {
|
|
183
|
+
if (server.type === "sse") {
|
|
184
|
+
return {
|
|
185
|
+
skip: {
|
|
186
|
+
name: original,
|
|
187
|
+
reason: "it speaks SSE, and the gateway's upstream transports are stdio and Streamable HTTP only",
|
|
188
|
+
remedy: "ask the vendor for the Streamable HTTP endpoint, or leave this server configured directly and " +
|
|
189
|
+
"outside the gateway"
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
const parsed = hostOf(server.url);
|
|
194
|
+
if (!parsed) {
|
|
195
|
+
return {
|
|
196
|
+
skip: {
|
|
197
|
+
name: original,
|
|
198
|
+
reason: `its url ${JSON.stringify(server.url)} will not parse`,
|
|
199
|
+
remedy: "fix the url in the client config and run adopt again"
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
const warnings = [];
|
|
204
|
+
let secretOnDisk = false;
|
|
205
|
+
const headers = {};
|
|
206
|
+
const lockHeaders = [];
|
|
207
|
+
for (const [header, value] of Object.entries(server.headers)) {
|
|
208
|
+
if (!INTERPOLATION.test(value)) {
|
|
209
|
+
headers[header] = value;
|
|
210
|
+
if (!HARMLESS_HEADERS.has(header.toLowerCase())) {
|
|
211
|
+
lockHeaders.push(header);
|
|
212
|
+
warnings.push(`the ${header} header's value goes into your locked keys, and gateway.yaml only names it`);
|
|
213
|
+
}
|
|
214
|
+
continue;
|
|
215
|
+
}
|
|
216
|
+
/*
|
|
217
|
+
* `gateway.yaml` rejects `${...}` in a header rather than expanding it, so
|
|
218
|
+
* a config that looked like it was interpolating a secret would ship the
|
|
219
|
+
* word. Refusing here, with the name of the header, is the same refusal
|
|
220
|
+
* the schema would make later -- but as a line in a report instead of a
|
|
221
|
+
* zod dump mid-adoption.
|
|
222
|
+
*
|
|
223
|
+
* Note this is not a case for credential_passthrough, whatever the
|
|
224
|
+
* schema's own message suggests: that forwards the *caller's* token, and a
|
|
225
|
+
* client speaking stdio to the gateway presents no token at all.
|
|
226
|
+
*/
|
|
227
|
+
if (!options.copyEnv) {
|
|
228
|
+
return {
|
|
229
|
+
skip: {
|
|
230
|
+
name: original,
|
|
231
|
+
reason: `its ${header} header interpolates ${value.match(INTERPOLATION)[0]}, which gateway.yaml refuses because the value would be sent literally`,
|
|
232
|
+
remedy: "re-run with --copy-env to resolve it from this shell now, or add the upstream by hand with the " +
|
|
233
|
+
"literal value in place"
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
const resolved = expandInterpolation(value, options.env ?? process.env);
|
|
238
|
+
if (resolved === undefined) {
|
|
239
|
+
return {
|
|
240
|
+
skip: {
|
|
241
|
+
name: original,
|
|
242
|
+
reason: `its ${header} header interpolates a variable that is not set in this shell`,
|
|
243
|
+
remedy: `export it and run adopt again, or add the upstream by hand with the literal value`
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
headers[header] = resolved;
|
|
248
|
+
secretOnDisk = true;
|
|
249
|
+
warnings.push(`the ${header} header was resolved to a literal value in the generated config`);
|
|
250
|
+
}
|
|
251
|
+
if (isLocalTarget(parsed.hostname) && !options.allowLocalHttp) {
|
|
252
|
+
return {
|
|
253
|
+
skip: {
|
|
254
|
+
name: original,
|
|
255
|
+
reason: `it listens on ${parsed.host}, and the egress guard refuses loopback and private addresses ` +
|
|
256
|
+
`(egress.block_private_ips, allow_ip_literals and allow_http all stand in the way)`,
|
|
257
|
+
remedy: "re-run with --allow-local-http, which turns those protections off for every HTTP upstream this " +
|
|
258
|
+
"gateway has -- not just this one"
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
const local = isLocalTarget(parsed.hostname);
|
|
263
|
+
if (local) {
|
|
264
|
+
warnings.push("adopting this upstream relaxes the SSRF protections for every HTTP upstream in this toolbox");
|
|
265
|
+
}
|
|
266
|
+
if (parsed.protocol === "http:") {
|
|
267
|
+
warnings.push("it is reached over plaintext HTTP, which the generated policy has to permit");
|
|
268
|
+
}
|
|
269
|
+
egressAllow.add(options.strictEgress ? parsed.host : parsed.hostname);
|
|
270
|
+
return {
|
|
271
|
+
planned: {
|
|
272
|
+
upstream: UpstreamSchema.parse({
|
|
273
|
+
name,
|
|
274
|
+
transport: "http",
|
|
275
|
+
url: server.url,
|
|
276
|
+
headers
|
|
277
|
+
}),
|
|
278
|
+
originalName: original,
|
|
279
|
+
warnings,
|
|
280
|
+
...(lockHeaders.length > 0 ? { lockHeaders } : {})
|
|
281
|
+
},
|
|
282
|
+
needsLocalHttp: local,
|
|
283
|
+
secretOnDisk
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
function planStdio(original, name, server, options, gatewayEnv, envOwner) {
|
|
287
|
+
const warnings = [];
|
|
288
|
+
const passEnv = [];
|
|
289
|
+
const ownEnv = {};
|
|
290
|
+
let secretOnDisk = false;
|
|
291
|
+
for (const key of Object.keys(server.env).sort()) {
|
|
292
|
+
const value = server.env[key];
|
|
293
|
+
if (options.copyEnv) {
|
|
294
|
+
/*
|
|
295
|
+
* `--copy-env` is the only place two upstreams can hold different values
|
|
296
|
+
* for the same variable name, because each gets its own `env` block.
|
|
297
|
+
*/
|
|
298
|
+
const resolved = INTERPOLATION.test(value) ? expandInterpolation(value, options.env ?? process.env) : value;
|
|
299
|
+
if (resolved === undefined) {
|
|
300
|
+
return {
|
|
301
|
+
skip: {
|
|
302
|
+
name: original,
|
|
303
|
+
reason: `its ${key} is set from a variable that is not set in this shell`,
|
|
304
|
+
remedy: "export it and run adopt again"
|
|
305
|
+
}
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
ownEnv[key] = resolved;
|
|
309
|
+
secretOnDisk = true;
|
|
310
|
+
continue;
|
|
311
|
+
}
|
|
312
|
+
/*
|
|
313
|
+
* The value moves to the gateway's own client entry and the upstream names
|
|
314
|
+
* it in `pass_env`. That keeps the secret in the file it was already in,
|
|
315
|
+
* at the permissions it already had, and keeps `gateway.yaml` free of
|
|
316
|
+
* secrets and safe to commit. It also works whether the original value was
|
|
317
|
+
* a literal or a `${VAR}` the client expands, because the value is carried
|
|
318
|
+
* across verbatim for the client to handle as it already did.
|
|
319
|
+
*
|
|
320
|
+
* Copying it into `gateway.yaml` instead would put a secret in a new file,
|
|
321
|
+
* and naming it in `pass_env` without moving it would read the *gateway's*
|
|
322
|
+
* environment, where a value that only ever lived in the client config is
|
|
323
|
+
* simply absent -- the server would then fail to authenticate with nothing
|
|
324
|
+
* to point at.
|
|
325
|
+
*/
|
|
326
|
+
const owner = envOwner.get(key);
|
|
327
|
+
if (owner !== undefined && gatewayEnv[key] !== value) {
|
|
328
|
+
/*
|
|
329
|
+
* `pass_env` is a list of names, so it cannot rename: one gateway entry
|
|
330
|
+
* can carry exactly one value for `API_KEY`. Both servers are skipped
|
|
331
|
+
* rather than one quietly getting the other's credential.
|
|
332
|
+
*/
|
|
333
|
+
return {
|
|
334
|
+
skip: {
|
|
335
|
+
name: original,
|
|
336
|
+
reason: `it sets ${key} to a different value than "${owner}" does, and the gateway forwards an ` +
|
|
337
|
+
`environment variable under its own name, so one entry cannot carry both`,
|
|
338
|
+
remedy: `re-run with --copy-env, which gives each upstream its own env block in gateway.yaml`
|
|
339
|
+
}
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
if (owner === undefined) {
|
|
343
|
+
gatewayEnv[key] = value;
|
|
344
|
+
envOwner.set(key, original);
|
|
345
|
+
}
|
|
346
|
+
passEnv.push(key);
|
|
347
|
+
}
|
|
348
|
+
if (passEnv.length > 0) {
|
|
349
|
+
warnings.push(`${passEnv.join(", ")} moved to the toolbox's own entry in your app and passed on by name`);
|
|
350
|
+
}
|
|
351
|
+
return {
|
|
352
|
+
planned: {
|
|
353
|
+
upstream: UpstreamSchema.parse({
|
|
354
|
+
name,
|
|
355
|
+
transport: "stdio",
|
|
356
|
+
command: server.command,
|
|
357
|
+
args: server.args,
|
|
358
|
+
env: ownEnv,
|
|
359
|
+
pass_env: passEnv
|
|
360
|
+
}),
|
|
361
|
+
originalName: original,
|
|
362
|
+
warnings
|
|
363
|
+
},
|
|
364
|
+
secretOnDisk
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Expands `${VAR}` and `${VAR:-default}`, the two forms the client supports.
|
|
369
|
+
*
|
|
370
|
+
* Returns undefined when a variable with no default is unset, so the caller
|
|
371
|
+
* can skip the server and say which one rather than writing an empty
|
|
372
|
+
* credential into a config.
|
|
373
|
+
*/
|
|
374
|
+
export function expandInterpolation(value, env) {
|
|
375
|
+
let missing = false;
|
|
376
|
+
const out = value.replace(/\$\{([^}:]+)(?::-([^}]*))?\}/g, (_match, name, fallback) => {
|
|
377
|
+
const resolved = env[name];
|
|
378
|
+
if (resolved !== undefined && resolved !== "")
|
|
379
|
+
return resolved;
|
|
380
|
+
if (fallback !== undefined)
|
|
381
|
+
return fallback;
|
|
382
|
+
missing = true;
|
|
383
|
+
return "";
|
|
384
|
+
});
|
|
385
|
+
return missing ? undefined : out;
|
|
386
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { CatalogEntry } from "./contracts.js";
|
|
3
|
+
declare const LaunchSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
4
|
+
transport: z.ZodLiteral<"stdio">;
|
|
5
|
+
command: z.ZodString;
|
|
6
|
+
args: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
7
|
+
env: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
8
|
+
field: z.ZodString;
|
|
9
|
+
prefix: z.ZodOptional<z.ZodString>;
|
|
10
|
+
}, z.core.$strict>]>>>;
|
|
11
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
12
|
+
transport: z.ZodLiteral<"http">;
|
|
13
|
+
url: z.ZodString;
|
|
14
|
+
headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
15
|
+
field: z.ZodString;
|
|
16
|
+
prefix: z.ZodOptional<z.ZodString>;
|
|
17
|
+
}, z.core.$strict>]>>>;
|
|
18
|
+
oauth: z.ZodOptional<z.ZodBoolean>;
|
|
19
|
+
}, z.core.$strict>], "transport">;
|
|
20
|
+
export declare const CatalogEntrySchema: z.ZodObject<{
|
|
21
|
+
id: z.ZodString;
|
|
22
|
+
name: z.ZodString;
|
|
23
|
+
category: z.ZodEnum<{
|
|
24
|
+
files: "files";
|
|
25
|
+
developer: "developer";
|
|
26
|
+
productivity: "productivity";
|
|
27
|
+
data: "data";
|
|
28
|
+
web: "web";
|
|
29
|
+
knowledge: "knowledge";
|
|
30
|
+
design: "design";
|
|
31
|
+
}>;
|
|
32
|
+
summary: z.ZodString;
|
|
33
|
+
description: z.ZodOptional<z.ZodString>;
|
|
34
|
+
publisher: z.ZodObject<{
|
|
35
|
+
name: z.ZodString;
|
|
36
|
+
official: z.ZodBoolean;
|
|
37
|
+
}, z.core.$strict>;
|
|
38
|
+
homepage: z.ZodString;
|
|
39
|
+
registry_name: z.ZodOptional<z.ZodString>;
|
|
40
|
+
requires: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
41
|
+
node: "node";
|
|
42
|
+
uv: "uv";
|
|
43
|
+
docker: "docker";
|
|
44
|
+
python: "python";
|
|
45
|
+
git: "git";
|
|
46
|
+
}>>>;
|
|
47
|
+
variants: z.ZodArray<z.ZodObject<{
|
|
48
|
+
id: z.ZodString;
|
|
49
|
+
label: z.ZodString;
|
|
50
|
+
summary: z.ZodOptional<z.ZodString>;
|
|
51
|
+
launch: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
52
|
+
transport: z.ZodLiteral<"stdio">;
|
|
53
|
+
command: z.ZodString;
|
|
54
|
+
args: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
55
|
+
env: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
56
|
+
field: z.ZodString;
|
|
57
|
+
prefix: z.ZodOptional<z.ZodString>;
|
|
58
|
+
}, z.core.$strict>]>>>;
|
|
59
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
60
|
+
transport: z.ZodLiteral<"http">;
|
|
61
|
+
url: z.ZodString;
|
|
62
|
+
headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
63
|
+
field: z.ZodString;
|
|
64
|
+
prefix: z.ZodOptional<z.ZodString>;
|
|
65
|
+
}, z.core.$strict>]>>>;
|
|
66
|
+
oauth: z.ZodOptional<z.ZodBoolean>;
|
|
67
|
+
}, z.core.$strict>], "transport">;
|
|
68
|
+
fields: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
69
|
+
requires: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
70
|
+
node: "node";
|
|
71
|
+
uv: "uv";
|
|
72
|
+
docker: "docker";
|
|
73
|
+
python: "python";
|
|
74
|
+
git: "git";
|
|
75
|
+
}>>>;
|
|
76
|
+
}, z.core.$strict>>;
|
|
77
|
+
fields: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
78
|
+
id: z.ZodString;
|
|
79
|
+
kind: z.ZodEnum<{
|
|
80
|
+
secret: "secret";
|
|
81
|
+
url: "url";
|
|
82
|
+
folder: "folder";
|
|
83
|
+
folders: "folders";
|
|
84
|
+
text: "text";
|
|
85
|
+
choice: "choice";
|
|
86
|
+
toggle: "toggle";
|
|
87
|
+
}>;
|
|
88
|
+
label: z.ZodString;
|
|
89
|
+
help: z.ZodOptional<z.ZodString>;
|
|
90
|
+
placeholder: z.ZodOptional<z.ZodString>;
|
|
91
|
+
required: z.ZodOptional<z.ZodBoolean>;
|
|
92
|
+
default: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodBoolean, z.ZodArray<z.ZodString>]>>;
|
|
93
|
+
choices: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
94
|
+
value: z.ZodString;
|
|
95
|
+
label: z.ZodString;
|
|
96
|
+
}, z.core.$strict>>>;
|
|
97
|
+
validate: z.ZodOptional<z.ZodObject<{
|
|
98
|
+
pattern: z.ZodString;
|
|
99
|
+
message: z.ZodString;
|
|
100
|
+
}, z.core.$strict>>;
|
|
101
|
+
technical: z.ZodOptional<z.ZodString>;
|
|
102
|
+
}, z.core.$strict>>>;
|
|
103
|
+
guide: z.ZodArray<z.ZodObject<{
|
|
104
|
+
title: z.ZodString;
|
|
105
|
+
body: z.ZodString;
|
|
106
|
+
link: z.ZodOptional<z.ZodObject<{
|
|
107
|
+
label: z.ZodString;
|
|
108
|
+
url: z.ZodString;
|
|
109
|
+
}, z.core.$strict>>;
|
|
110
|
+
image: z.ZodOptional<z.ZodString>;
|
|
111
|
+
}, z.core.$strict>>;
|
|
112
|
+
pack: z.ZodOptional<z.ZodString>;
|
|
113
|
+
pack_within_field: z.ZodOptional<z.ZodString>;
|
|
114
|
+
try_prompt: z.ZodOptional<z.ZodString>;
|
|
115
|
+
keywords: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
116
|
+
check: z.ZodOptional<z.ZodObject<{
|
|
117
|
+
tool: z.ZodString;
|
|
118
|
+
args: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
119
|
+
}, z.core.$strict>>;
|
|
120
|
+
}, z.core.$strict>;
|
|
121
|
+
/** Every `{{fields.x}}`, `{{...fields.x}}` and `{ field: x }` in a launch template. */
|
|
122
|
+
export declare function fieldsUsedBy(launch: z.infer<typeof LaunchSchema> | CatalogEntry["variants"][number]["launch"]): {
|
|
123
|
+
id: string;
|
|
124
|
+
how: "inline" | "spread" | "value";
|
|
125
|
+
}[];
|
|
126
|
+
/** The catalog folder shipped with the package; the same from src/ and dist/. */
|
|
127
|
+
export declare function catalogDir(): string;
|
|
128
|
+
/** Every entry, validated, sorted by name. Throws naming the file on a bad entry. */
|
|
129
|
+
export declare function loadCatalog(dir?: string): CatalogEntry[];
|
|
130
|
+
/** A catalog entry's check call (see the schema above). */
|
|
131
|
+
export interface CatalogCheck {
|
|
132
|
+
tool: string;
|
|
133
|
+
args: Record<string, unknown>;
|
|
134
|
+
}
|
|
135
|
+
/** The check call our own catalog sets for an entry, or undefined. Never taken from a request. */
|
|
136
|
+
export declare function catalogCheck(id: string, dir?: string): CatalogCheck | undefined;
|
|
137
|
+
export declare function catalogEntry(id: string, dir?: string): CatalogEntry | undefined;
|
|
138
|
+
/** registry_name -> catalog id, so a public-list result can open the curated entry instead. */
|
|
139
|
+
export declare function catalogRegistryNames(dir?: string): Map<string, string>;
|
|
140
|
+
export {};
|