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,106 @@
|
|
|
1
|
+
import { type GatewayConfig } from "./config.js";
|
|
2
|
+
/**
|
|
3
|
+
* Watching gateway.yaml for servers being added, changed or removed.
|
|
4
|
+
*
|
|
5
|
+
* The console's "Save and turn on" writes gateway.yaml, and the person who
|
|
6
|
+
* clicked it is looking at an AI app that is already running this gateway.
|
|
7
|
+
* Before this, that app had to be restarted -- which for Claude Desktop means
|
|
8
|
+
* quitting it -- before the new server existed. Now the running gateway
|
|
9
|
+
* notices, connects the new server, and tells the app its tool list changed.
|
|
10
|
+
*
|
|
11
|
+
* Only `upstreams` is live. Everything else in this file was consumed when
|
|
12
|
+
* the process started -- the name that is half of every storage key, the
|
|
13
|
+
* policy path, `namespace`, which changes every tool's name -- so a change to
|
|
14
|
+
* any of it is refused in full, the same position `PolicySource` takes: never
|
|
15
|
+
* half-apply an edit and report it as applied. The refusal is published so the
|
|
16
|
+
* console can say "restart your AI app to finish this change" instead of
|
|
17
|
+
* leaving someone wondering why nothing happened.
|
|
18
|
+
*
|
|
19
|
+
* Polled, like the policy file, because the safe way to write a config is a
|
|
20
|
+
* temporary file renamed over the original, and a watch on the file would be
|
|
21
|
+
* left following an inode nobody writes again.
|
|
22
|
+
*/
|
|
23
|
+
export type ConfigChange =
|
|
24
|
+
/** Nothing new since the last look. */
|
|
25
|
+
{
|
|
26
|
+
readonly kind: "unchanged";
|
|
27
|
+
}
|
|
28
|
+
/** The file does not parse or does not validate. What is running stays. */
|
|
29
|
+
| {
|
|
30
|
+
readonly kind: "invalid";
|
|
31
|
+
readonly digest: string;
|
|
32
|
+
readonly error: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Valid, but changes something outside `upstreams`, so the file as a whole
|
|
36
|
+
* is not applied and the refusal stands until a restart.
|
|
37
|
+
*
|
|
38
|
+
* `upstreams` is set when the servers moved: one restart-only edit (a
|
|
39
|
+
* timeout, say) must not freeze every later "Save and turn on". The server
|
|
40
|
+
* list it carries is the file's, on top of the settings this process is
|
|
41
|
+
* running; whoever applies it keeps the refusal (and the old digest), since
|
|
42
|
+
* the rest of the file is still not in force.
|
|
43
|
+
*
|
|
44
|
+
* Carried whether or not the refused part is the same as last time. Polled
|
|
45
|
+
* once a second, one look can take in a setting edit and the servers added
|
|
46
|
+
* after it together; carrying only "since the last refusal" then left those
|
|
47
|
+
* servers out for good, because the file never changed again (R3 NEW-1).
|
|
48
|
+
*/
|
|
49
|
+
| {
|
|
50
|
+
readonly kind: "refused";
|
|
51
|
+
readonly digest: string;
|
|
52
|
+
readonly fields: readonly string[];
|
|
53
|
+
readonly refusal: string;
|
|
54
|
+
readonly upstreams?: {
|
|
55
|
+
readonly config: GatewayConfig;
|
|
56
|
+
readonly added: readonly string[];
|
|
57
|
+
readonly removed: readonly string[];
|
|
58
|
+
readonly changed: readonly string[];
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/** Only `upstreams` changed (or nothing that matters did). */
|
|
62
|
+
| {
|
|
63
|
+
readonly kind: "apply";
|
|
64
|
+
readonly digest: string;
|
|
65
|
+
readonly config: GatewayConfig;
|
|
66
|
+
readonly added: readonly string[];
|
|
67
|
+
readonly removed: readonly string[];
|
|
68
|
+
readonly changed: readonly string[];
|
|
69
|
+
};
|
|
70
|
+
/** The digest the console compares against the file on disk: of the text, exactly as written. */
|
|
71
|
+
export declare function configTextDigest(text: string): string;
|
|
72
|
+
/** Which servers were added, removed or changed, by name. A change is any difference in the parsed entry. */
|
|
73
|
+
export declare function diffUpstreams(from: GatewayConfig, to: GatewayConfig): {
|
|
74
|
+
added: string[];
|
|
75
|
+
removed: string[];
|
|
76
|
+
changed: string[];
|
|
77
|
+
};
|
|
78
|
+
/** The top-level settings, other than `upstreams`, that differ. */
|
|
79
|
+
export declare function nonUpstreamChanges(from: GatewayConfig, to: GatewayConfig): string[];
|
|
80
|
+
/** Parses gateway.yaml text the way the loader does, without reading the policy it points at. */
|
|
81
|
+
export declare function parseConfigText(text: string): GatewayConfig;
|
|
82
|
+
export declare class ConfigSource {
|
|
83
|
+
readonly path: string;
|
|
84
|
+
private applied;
|
|
85
|
+
private lastDigest;
|
|
86
|
+
private last;
|
|
87
|
+
private timer;
|
|
88
|
+
private busy;
|
|
89
|
+
/**
|
|
90
|
+
* `applied` is the config this process is running, `appliedDigest` the
|
|
91
|
+
* digest of the text it came from. The file is not re-read here: the
|
|
92
|
+
* baseline is what is running, not what happens to be on disk now.
|
|
93
|
+
*/
|
|
94
|
+
constructor(path: string, applied: GatewayConfig, appliedDigest: string);
|
|
95
|
+
/** Reads the file once and says what, if anything, should happen. */
|
|
96
|
+
check(): ConfigChange;
|
|
97
|
+
/** Makes `config` the baseline the next change is compared against. */
|
|
98
|
+
accept(config: GatewayConfig): void;
|
|
99
|
+
/**
|
|
100
|
+
* Polls for a change. `onChange` may be async; ticks are skipped while it
|
|
101
|
+
* runs, and the stamp is taken again afterwards, so an edit that lands
|
|
102
|
+
* during a slow reconnect is seen on the next tick rather than lost.
|
|
103
|
+
*/
|
|
104
|
+
watch(onChange: (change: ConfigChange) => void | Promise<void>, intervalMs?: number): void;
|
|
105
|
+
stop(): void;
|
|
106
|
+
}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { readFileSync, statSync } from "node:fs";
|
|
2
|
+
import { parse as parseYaml } from "yaml";
|
|
3
|
+
import { canonicalJson, sha256 } from "hmcp-core";
|
|
4
|
+
import { GatewayConfigSchema } from "./config.js";
|
|
5
|
+
/** The digest the console compares against the file on disk: of the text, exactly as written. */
|
|
6
|
+
export function configTextDigest(text) {
|
|
7
|
+
return sha256(text);
|
|
8
|
+
}
|
|
9
|
+
/** Which servers were added, removed or changed, by name. A change is any difference in the parsed entry. */
|
|
10
|
+
export function diffUpstreams(from, to) {
|
|
11
|
+
const before = new Map(from.upstreams.map((u) => [u.name, canonicalJson(u)]));
|
|
12
|
+
const after = new Map(to.upstreams.map((u) => [u.name, canonicalJson(u)]));
|
|
13
|
+
return {
|
|
14
|
+
added: [...after.keys()].filter((n) => !before.has(n)),
|
|
15
|
+
removed: [...before.keys()].filter((n) => !after.has(n)),
|
|
16
|
+
changed: [...after.keys()].filter((n) => before.has(n) && before.get(n) !== after.get(n))
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/** The top-level settings, other than `upstreams`, that differ. */
|
|
20
|
+
export function nonUpstreamChanges(from, to) {
|
|
21
|
+
const keys = new Set([...Object.keys(from), ...Object.keys(to)]);
|
|
22
|
+
keys.delete("upstreams");
|
|
23
|
+
return [...keys]
|
|
24
|
+
.sort()
|
|
25
|
+
.filter((k) => canonicalJson(from[k] ?? null) !==
|
|
26
|
+
canonicalJson(to[k] ?? null));
|
|
27
|
+
}
|
|
28
|
+
/** Parses gateway.yaml text the way the loader does, without reading the policy it points at. */
|
|
29
|
+
export function parseConfigText(text) {
|
|
30
|
+
const result = GatewayConfigSchema.safeParse(parseYaml(text));
|
|
31
|
+
if (!result.success) {
|
|
32
|
+
throw new Error(result.error.issues.map((i) => `${i.path.join(".") || "(root)"}: ${i.message}`).join("; "));
|
|
33
|
+
}
|
|
34
|
+
return result.data;
|
|
35
|
+
}
|
|
36
|
+
/** Settings that change how a server's tools are named or judged: servers are not carried past these. */
|
|
37
|
+
const IDENTITY_FIELDS = new Set(["name", "namespace", "policy", "max_tool_name_length"]);
|
|
38
|
+
function stamp(path) {
|
|
39
|
+
try {
|
|
40
|
+
const s = statSync(path);
|
|
41
|
+
return { mtimeMs: s.mtimeMs, size: s.size, ino: Number(s.ino) };
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const sameStamp = (a, b) => a === null || b === null ? a === b : a.mtimeMs === b.mtimeMs && a.size === b.size && a.ino === b.ino;
|
|
48
|
+
export class ConfigSource {
|
|
49
|
+
path;
|
|
50
|
+
applied;
|
|
51
|
+
lastDigest;
|
|
52
|
+
last;
|
|
53
|
+
timer = null;
|
|
54
|
+
busy = false;
|
|
55
|
+
/**
|
|
56
|
+
* `applied` is the config this process is running, `appliedDigest` the
|
|
57
|
+
* digest of the text it came from. The file is not re-read here: the
|
|
58
|
+
* baseline is what is running, not what happens to be on disk now.
|
|
59
|
+
*/
|
|
60
|
+
constructor(path, applied, appliedDigest) {
|
|
61
|
+
this.path = path;
|
|
62
|
+
this.applied = applied;
|
|
63
|
+
this.lastDigest = appliedDigest;
|
|
64
|
+
this.last = stamp(path);
|
|
65
|
+
}
|
|
66
|
+
/** Reads the file once and says what, if anything, should happen. */
|
|
67
|
+
check() {
|
|
68
|
+
let text;
|
|
69
|
+
try {
|
|
70
|
+
text = readFileSync(this.path, "utf8");
|
|
71
|
+
}
|
|
72
|
+
catch (err) {
|
|
73
|
+
// Gone, mid-rename, unreadable: leave what is running alone.
|
|
74
|
+
return { kind: "invalid", digest: this.lastDigest, error: err.message };
|
|
75
|
+
}
|
|
76
|
+
const digest = configTextDigest(text);
|
|
77
|
+
if (digest === this.lastDigest)
|
|
78
|
+
return { kind: "unchanged" };
|
|
79
|
+
this.lastDigest = digest;
|
|
80
|
+
let next;
|
|
81
|
+
try {
|
|
82
|
+
next = parseConfigText(text);
|
|
83
|
+
}
|
|
84
|
+
catch (err) {
|
|
85
|
+
return { kind: "invalid", digest, error: err.message };
|
|
86
|
+
}
|
|
87
|
+
const fields = nonUpstreamChanges(this.applied, next);
|
|
88
|
+
if (fields.length > 0) {
|
|
89
|
+
const carried = { ...this.applied, upstreams: next.upstreams };
|
|
90
|
+
const diff = diffUpstreams(this.applied, carried);
|
|
91
|
+
const moved = diff.added.length + diff.removed.length + diff.changed.length > 0;
|
|
92
|
+
/*
|
|
93
|
+
* Servers are carried past a setting that only waits for a restart (a
|
|
94
|
+
* timeout, the injection handling). Not past one that changes what the
|
|
95
|
+
* servers' tools are called or which rules judge them -- the toolbox's
|
|
96
|
+
* name, `namespace`, the policy file -- since a server carried under the
|
|
97
|
+
* old one would be judged by rules written for the new.
|
|
98
|
+
*/
|
|
99
|
+
const live = this.applied.upstream_reload && next.upstream_reload && !fields.some((f) => IDENTITY_FIELDS.has(f));
|
|
100
|
+
const carry = live && moved;
|
|
101
|
+
return {
|
|
102
|
+
kind: "refused",
|
|
103
|
+
digest,
|
|
104
|
+
fields,
|
|
105
|
+
refusal: carry
|
|
106
|
+
? `gateway.yaml changed ${fields.join(", ")}, which a running gateway cannot pick up. The servers ` +
|
|
107
|
+
`were updated, but that setting waits for a restart of the AI app.`
|
|
108
|
+
: live
|
|
109
|
+
? `gateway.yaml changed ${fields.join(", ")}, which a running gateway cannot pick up. That setting ` +
|
|
110
|
+
`waits for a restart of the AI app. Server changes are still applied straight away.`
|
|
111
|
+
: `gateway.yaml changed ${fields.join(", ")}, which a running gateway cannot pick up. Nothing in ` +
|
|
112
|
+
`that change was applied, including any change to the servers. Restart the AI app to apply it.`,
|
|
113
|
+
...(carry ? { upstreams: { config: carried, ...diff } } : {})
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
return { kind: "apply", digest, config: next, ...diffUpstreams(this.applied, next) };
|
|
117
|
+
}
|
|
118
|
+
/** Makes `config` the baseline the next change is compared against. */
|
|
119
|
+
accept(config) {
|
|
120
|
+
this.applied = config;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Polls for a change. `onChange` may be async; ticks are skipped while it
|
|
124
|
+
* runs, and the stamp is taken again afterwards, so an edit that lands
|
|
125
|
+
* during a slow reconnect is seen on the next tick rather than lost.
|
|
126
|
+
*/
|
|
127
|
+
watch(onChange, intervalMs = 1000) {
|
|
128
|
+
if (this.timer)
|
|
129
|
+
return;
|
|
130
|
+
this.timer = setInterval(() => {
|
|
131
|
+
if (this.busy)
|
|
132
|
+
return;
|
|
133
|
+
const seen = stamp(this.path);
|
|
134
|
+
if (sameStamp(seen, this.last))
|
|
135
|
+
return;
|
|
136
|
+
this.last = seen;
|
|
137
|
+
const change = this.check();
|
|
138
|
+
if (change.kind === "unchanged")
|
|
139
|
+
return;
|
|
140
|
+
this.busy = true;
|
|
141
|
+
void Promise.resolve()
|
|
142
|
+
.then(() => onChange(change))
|
|
143
|
+
.catch(() => undefined)
|
|
144
|
+
.finally(() => {
|
|
145
|
+
this.busy = false;
|
|
146
|
+
});
|
|
147
|
+
}, intervalMs);
|
|
148
|
+
this.timer.unref?.();
|
|
149
|
+
}
|
|
150
|
+
stop() {
|
|
151
|
+
if (this.timer) {
|
|
152
|
+
clearInterval(this.timer);
|
|
153
|
+
this.timer = null;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { type Policy } from "hmcp-core";
|
|
3
|
+
/** One MCP server the gateway sits in front of. */
|
|
4
|
+
/**
|
|
5
|
+
* Relaying the caller's own credential to this upstream instead of holding
|
|
6
|
+
* one for it.
|
|
7
|
+
*
|
|
8
|
+
* Off by default: forwarding a credential somewhere is a decision, and an
|
|
9
|
+
* upstream that was configured with a static header should keep behaving the
|
|
10
|
+
* way it does until someone says otherwise.
|
|
11
|
+
*/
|
|
12
|
+
export declare const CredentialPassthroughSchema: z.ZodObject<{
|
|
13
|
+
enabled: z.ZodDefault<z.ZodBoolean>;
|
|
14
|
+
header: z.ZodDefault<z.ZodString>;
|
|
15
|
+
required: z.ZodDefault<z.ZodBoolean>;
|
|
16
|
+
session: z.ZodDefault<z.ZodEnum<{
|
|
17
|
+
shared: "shared";
|
|
18
|
+
"per-tenant": "per-tenant";
|
|
19
|
+
}>>;
|
|
20
|
+
}, z.core.$strict>;
|
|
21
|
+
export type CredentialPassthrough = z.infer<typeof CredentialPassthroughSchema>;
|
|
22
|
+
export declare const UpstreamSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
23
|
+
name: z.ZodString;
|
|
24
|
+
transport: z.ZodLiteral<"stdio">;
|
|
25
|
+
on_injection: z.ZodOptional<z.ZodEnum<{
|
|
26
|
+
strip: "strip";
|
|
27
|
+
deny: "deny";
|
|
28
|
+
annotate: "annotate";
|
|
29
|
+
}>>;
|
|
30
|
+
command: z.ZodString;
|
|
31
|
+
args: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
32
|
+
env: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
33
|
+
secret: z.ZodString;
|
|
34
|
+
prefix: z.ZodOptional<z.ZodString>;
|
|
35
|
+
}, z.core.$strict>]>>>;
|
|
36
|
+
pass_env: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
37
|
+
cwd: z.ZodOptional<z.ZodString>;
|
|
38
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
39
|
+
name: z.ZodString;
|
|
40
|
+
transport: z.ZodLiteral<"http">;
|
|
41
|
+
on_injection: z.ZodOptional<z.ZodEnum<{
|
|
42
|
+
strip: "strip";
|
|
43
|
+
deny: "deny";
|
|
44
|
+
annotate: "annotate";
|
|
45
|
+
}>>;
|
|
46
|
+
url: z.ZodString;
|
|
47
|
+
headers: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
48
|
+
secret: z.ZodString;
|
|
49
|
+
prefix: z.ZodOptional<z.ZodString>;
|
|
50
|
+
}, z.core.$strict>]>>>;
|
|
51
|
+
credential_passthrough: z.ZodDefault<z.ZodObject<{
|
|
52
|
+
enabled: z.ZodDefault<z.ZodBoolean>;
|
|
53
|
+
header: z.ZodDefault<z.ZodString>;
|
|
54
|
+
required: z.ZodDefault<z.ZodBoolean>;
|
|
55
|
+
session: z.ZodDefault<z.ZodEnum<{
|
|
56
|
+
shared: "shared";
|
|
57
|
+
"per-tenant": "per-tenant";
|
|
58
|
+
}>>;
|
|
59
|
+
}, z.core.$strict>>;
|
|
60
|
+
oauth: z.ZodOptional<z.ZodObject<{
|
|
61
|
+
secret: z.ZodString;
|
|
62
|
+
}, z.core.$strict>>;
|
|
63
|
+
}, z.core.$strict>], "transport">;
|
|
64
|
+
export type Upstream = z.infer<typeof UpstreamSchema>;
|
|
65
|
+
export declare const GatewayConfigSchema: z.ZodObject<{
|
|
66
|
+
version: z.ZodLiteral<1>;
|
|
67
|
+
name: z.ZodDefault<z.ZodString>;
|
|
68
|
+
policy: z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnknown>]>;
|
|
69
|
+
upstreams: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
70
|
+
name: z.ZodString;
|
|
71
|
+
transport: z.ZodLiteral<"stdio">;
|
|
72
|
+
on_injection: z.ZodOptional<z.ZodEnum<{
|
|
73
|
+
strip: "strip";
|
|
74
|
+
deny: "deny";
|
|
75
|
+
annotate: "annotate";
|
|
76
|
+
}>>;
|
|
77
|
+
command: z.ZodString;
|
|
78
|
+
args: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
79
|
+
env: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
80
|
+
secret: z.ZodString;
|
|
81
|
+
prefix: z.ZodOptional<z.ZodString>;
|
|
82
|
+
}, z.core.$strict>]>>>;
|
|
83
|
+
pass_env: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
84
|
+
cwd: z.ZodOptional<z.ZodString>;
|
|
85
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
86
|
+
name: z.ZodString;
|
|
87
|
+
transport: z.ZodLiteral<"http">;
|
|
88
|
+
on_injection: z.ZodOptional<z.ZodEnum<{
|
|
89
|
+
strip: "strip";
|
|
90
|
+
deny: "deny";
|
|
91
|
+
annotate: "annotate";
|
|
92
|
+
}>>;
|
|
93
|
+
url: z.ZodString;
|
|
94
|
+
headers: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
95
|
+
secret: z.ZodString;
|
|
96
|
+
prefix: z.ZodOptional<z.ZodString>;
|
|
97
|
+
}, z.core.$strict>]>>>;
|
|
98
|
+
credential_passthrough: z.ZodDefault<z.ZodObject<{
|
|
99
|
+
enabled: z.ZodDefault<z.ZodBoolean>;
|
|
100
|
+
header: z.ZodDefault<z.ZodString>;
|
|
101
|
+
required: z.ZodDefault<z.ZodBoolean>;
|
|
102
|
+
session: z.ZodDefault<z.ZodEnum<{
|
|
103
|
+
shared: "shared";
|
|
104
|
+
"per-tenant": "per-tenant";
|
|
105
|
+
}>>;
|
|
106
|
+
}, z.core.$strict>>;
|
|
107
|
+
oauth: z.ZodOptional<z.ZodObject<{
|
|
108
|
+
secret: z.ZodString;
|
|
109
|
+
}, z.core.$strict>>;
|
|
110
|
+
}, z.core.$strict>], "transport">>;
|
|
111
|
+
connect_timeout_ms: z.ZodDefault<z.ZodNumber>;
|
|
112
|
+
startup: z.ZodDefault<z.ZodEnum<{
|
|
113
|
+
degraded: "degraded";
|
|
114
|
+
strict: "strict";
|
|
115
|
+
}>>;
|
|
116
|
+
upstream_reload: z.ZodDefault<z.ZodBoolean>;
|
|
117
|
+
on_injection: z.ZodDefault<z.ZodEnum<{
|
|
118
|
+
strip: "strip";
|
|
119
|
+
deny: "deny";
|
|
120
|
+
annotate: "annotate";
|
|
121
|
+
}>>;
|
|
122
|
+
injection_overrides: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodEnum<{
|
|
123
|
+
strip: "strip";
|
|
124
|
+
deny: "deny";
|
|
125
|
+
annotate: "annotate";
|
|
126
|
+
accept: "accept";
|
|
127
|
+
}>>>;
|
|
128
|
+
namespace: z.ZodDefault<z.ZodBoolean>;
|
|
129
|
+
policy_reload: z.ZodDefault<z.ZodBoolean>;
|
|
130
|
+
policy_writes: z.ZodDefault<z.ZodBoolean>;
|
|
131
|
+
max_tool_name_length: z.ZodOptional<z.ZodNumber>;
|
|
132
|
+
notify: z.ZodOptional<z.ZodBoolean>;
|
|
133
|
+
policy_overrides: z.ZodDefault<z.ZodBoolean>;
|
|
134
|
+
}, z.core.$strict>;
|
|
135
|
+
export type GatewayConfig = z.infer<typeof GatewayConfigSchema>;
|
|
136
|
+
export interface LoadedGatewayConfig {
|
|
137
|
+
readonly config: GatewayConfig;
|
|
138
|
+
readonly policy: Policy;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* The path every command falls back to when `-c` is not given. Compared
|
|
142
|
+
* against so a missing config can tell "there is nothing here yet" from "the
|
|
143
|
+
* path you typed is wrong" -- two mistakes with different remedies, which both
|
|
144
|
+
* arrived as the same `ENOENT`.
|
|
145
|
+
*/
|
|
146
|
+
export declare const DEFAULT_CONFIG_PATH = "gateway.yaml";
|
|
147
|
+
/** A config or policy file that is not there. Reported as a message. */
|
|
148
|
+
export declare class ConfigNotFound extends Error {
|
|
149
|
+
}
|
|
150
|
+
export declare function loadGatewayConfig(path: string, options?: {
|
|
151
|
+
/**
|
|
152
|
+
* Whether this path came from `-c` rather than the fallback. A path
|
|
153
|
+
* somebody typed that is missing is a typo; the fallback being missing
|
|
154
|
+
* means there is no config here yet, and `adopt` is what writes one.
|
|
155
|
+
* Decided by the caller, because by this point the path has been
|
|
156
|
+
* expanded and the two look identical.
|
|
157
|
+
*/
|
|
158
|
+
readonly typed?: boolean;
|
|
159
|
+
}): LoadedGatewayConfig;
|