hmcp-web 0.0.1 → 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 +48 -2
- package/THIRD-PARTY-NOTICES.md +110 -0
- package/bin/hmcp-web.js +20 -0
- package/dist/api.d.ts +11 -0
- package/dist/api.js +1404 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +40 -0
- package/dist/contracts/onboarding.d.ts +233 -0
- package/dist/contracts/onboarding.js +1 -0
- package/dist/http.d.ts +72 -0
- package/dist/http.js +319 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +7 -0
- package/dist/model/console-settings.d.ts +37 -0
- package/dist/model/console-settings.js +74 -0
- package/dist/model/doctor.d.ts +68 -0
- package/dist/model/doctor.js +254 -0
- package/dist/model/fs-browse.d.ts +9 -0
- package/dist/model/fs-browse.js +184 -0
- package/dist/model/gateway-config.d.ts +287 -0
- package/dist/model/gateway-config.js +760 -0
- package/dist/model/metrics.d.ts +65 -0
- package/dist/model/metrics.js +198 -0
- package/dist/model/oauth-flows.d.ts +60 -0
- package/dist/model/oauth-flows.js +79 -0
- package/dist/model/pipeline.d.ts +58 -0
- package/dist/model/pipeline.js +84 -0
- package/dist/model/probe.d.ts +155 -0
- package/dist/model/probe.js +385 -0
- package/dist/model/process.d.ts +100 -0
- package/dist/model/process.js +278 -0
- package/dist/model/protection.d.ts +378 -0
- package/dist/model/protection.js +470 -0
- package/dist/model/registry-cache.d.ts +59 -0
- package/dist/model/registry-cache.js +238 -0
- package/dist/model/scan.d.ts +48 -0
- package/dist/model/scan.js +59 -0
- package/dist/model/server.d.ts +127 -0
- package/dist/model/server.js +243 -0
- package/dist/model/tools.d.ts +61 -0
- package/dist/model/tools.js +72 -0
- package/dist/routes/catalog.d.ts +8 -0
- package/dist/routes/catalog.js +47 -0
- package/dist/routes/connect.d.ts +14 -0
- package/dist/routes/connect.js +633 -0
- package/dist/routes/oauth.d.ts +55 -0
- package/dist/routes/oauth.js +406 -0
- package/dist/routes/policy.d.ts +34 -0
- package/dist/routes/policy.js +513 -0
- package/dist/routes/runtime.d.ts +6 -0
- package/dist/routes/runtime.js +921 -0
- package/dist/routes/servers-add.d.ts +24 -0
- package/dist/routes/servers-add.js +1091 -0
- package/dist/routes/system.d.ts +4 -0
- package/dist/routes/system.js +13 -0
- package/dist/start.d.ts +56 -0
- package/dist/start.js +164 -0
- package/dist-ui/assets/Activity-BqKGpXMN.js +1 -0
- package/dist-ui/assets/Approvals-Qo7bCcli.js +1 -0
- package/dist-ui/assets/AttachApp-0zRSPgSY.js +5 -0
- package/dist-ui/assets/Connections-CE0JGe8c.js +2 -0
- package/dist-ui/assets/Gallery-B39L2Yma.js +17 -0
- package/dist-ui/assets/PreApprovals-BsIhjMqb.js +1 -0
- package/dist-ui/assets/Protection-DlB09ABa.js +1 -0
- package/dist-ui/assets/Safety-CN-oHO2h.js +1 -0
- package/dist-ui/assets/Settings-BLD7G1Ag.js +1 -0
- package/dist-ui/assets/StartPage-HuZSnmSr.js +1 -0
- package/dist-ui/assets/Suggestions-Dp7pofcs.js +1 -0
- package/dist-ui/assets/Tools-Bfot3bx5.js +4 -0
- package/dist-ui/assets/index-Khp0l1zp.js +16 -0
- package/dist-ui/assets/index-Ylyt4DEr.css +2 -0
- package/dist-ui/assets/kit-DQ7Oxf5n.js +4 -0
- package/dist-ui/brand/logo-256.png +0 -0
- package/dist-ui/brand/logo-512.png +0 -0
- package/dist-ui/brand/logo.svg +6 -0
- package/dist-ui/brand/mark.svg +5 -0
- package/dist-ui/fonts/OFL.txt +99 -0
- package/dist-ui/fonts/README.md +21 -0
- package/dist-ui/fonts/jetbrainsmono-latin.woff2 +0 -0
- package/dist-ui/fonts/manrope-latin.woff2 +0 -0
- package/dist-ui/index.html +51 -0
- package/package.json +69 -6
- package/bin/notice.js +0 -7
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import { EgressConfigSchema, EgressGuard } from "hmcp-core";
|
|
2
|
+
import { catalogRegistryNames, loadCatalog, mapServerJson } from "hmcp-gateway";
|
|
3
|
+
/**
|
|
4
|
+
* Searching the public MCP Registry, live.
|
|
5
|
+
*
|
|
6
|
+
* The list is about 71,000 servers, too many to keep a copy of, so each search
|
|
7
|
+
* is sent to the registry as it is typed (the UI waits for a pause first).
|
|
8
|
+
* What leaves this computer is the search words and a page cursor, and
|
|
9
|
+
* nothing else: no cookie, no referer, a generic User-Agent, through an
|
|
10
|
+
* EgressGuard that can reach the registry host and no other, GET only.
|
|
11
|
+
*
|
|
12
|
+
* Answers are kept in memory for ten minutes, so paging back and forth or
|
|
13
|
+
* retyping a word does not ask again.
|
|
14
|
+
*/
|
|
15
|
+
export const REGISTRY_URL = "https://registry.modelcontextprotocol.io";
|
|
16
|
+
const USER_AGENT = "hardened-mcp-console";
|
|
17
|
+
const PAGE = 30;
|
|
18
|
+
const TTL_MS = 10 * 60 * 1000;
|
|
19
|
+
const MAX_ENTRIES = 100;
|
|
20
|
+
const TIMEOUT_MS = 5_000;
|
|
21
|
+
export class RegistrySearch {
|
|
22
|
+
baseUrl;
|
|
23
|
+
guard;
|
|
24
|
+
timeoutMs;
|
|
25
|
+
now;
|
|
26
|
+
/** q + cursor -> answer. A Map keeps insertion order, which makes it a small LRU. */
|
|
27
|
+
cache = new Map();
|
|
28
|
+
catalogNames;
|
|
29
|
+
constructor(options = {}) {
|
|
30
|
+
this.baseUrl = (options.baseUrl ?? REGISTRY_URL).replace(/\/+$/, "");
|
|
31
|
+
this.timeoutMs = options.timeoutMs ?? TIMEOUT_MS;
|
|
32
|
+
this.now = options.now ?? Date.now;
|
|
33
|
+
this.guard = new EgressGuard(EgressConfigSchema.parse({
|
|
34
|
+
allow: [new URL(this.baseUrl).host],
|
|
35
|
+
methods: ["GET"],
|
|
36
|
+
max_body_bytes: 4 * 1024 * 1024,
|
|
37
|
+
timeout_ms: this.timeoutMs,
|
|
38
|
+
...options.egress
|
|
39
|
+
}));
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* One page of results. An empty query gives the registry's own first page. Never throws.
|
|
43
|
+
* The registry matches names only, so "brave search" finds nothing; with no
|
|
44
|
+
* hits, each word is tried alone (longest first), ranked by all of them.
|
|
45
|
+
*/
|
|
46
|
+
async search(query, cursor = null) {
|
|
47
|
+
const first = await this.searchOnce(query, cursor);
|
|
48
|
+
const words = query.trim().split(/\s+/).filter(Boolean);
|
|
49
|
+
if (first.hits.length > 0 || first.problem || cursor || words.length < 2)
|
|
50
|
+
return first;
|
|
51
|
+
// Longest word first: it is the most telling one. At most three more asks.
|
|
52
|
+
for (const word of [...new Set(words)].sort((a, b) => b.length - a.length).slice(0, 3)) {
|
|
53
|
+
const again = await this.searchOnce(word, null, query);
|
|
54
|
+
if (again.hits.length > 0 || again.problem)
|
|
55
|
+
return again;
|
|
56
|
+
}
|
|
57
|
+
return first;
|
|
58
|
+
}
|
|
59
|
+
async searchOnce(query, cursor, rankBy = query) {
|
|
60
|
+
const q = query.trim().replace(/\s+/g, " ");
|
|
61
|
+
const key = `${q}\u0000${cursor ?? ""}\u0000${rankBy}`;
|
|
62
|
+
const hit = this.cache.get(key);
|
|
63
|
+
if (hit && this.now() - hit.at < TTL_MS) {
|
|
64
|
+
this.cache.delete(key);
|
|
65
|
+
this.cache.set(key, hit);
|
|
66
|
+
return hit.value;
|
|
67
|
+
}
|
|
68
|
+
const url = new URL(`${this.baseUrl}/v0/servers`);
|
|
69
|
+
if (q)
|
|
70
|
+
url.searchParams.set("search", q);
|
|
71
|
+
url.searchParams.set("version", "latest");
|
|
72
|
+
url.searchParams.set("limit", String(PAGE));
|
|
73
|
+
if (cursor)
|
|
74
|
+
url.searchParams.set("cursor", cursor);
|
|
75
|
+
let page;
|
|
76
|
+
try {
|
|
77
|
+
const response = await this.guard.fetch(url.toString(), {
|
|
78
|
+
method: "GET",
|
|
79
|
+
// Nothing about the person: no cookie, no referer, a generic agent.
|
|
80
|
+
headers: { "user-agent": USER_AGENT, accept: "application/json" },
|
|
81
|
+
signal: AbortSignal.timeout(this.timeoutMs)
|
|
82
|
+
});
|
|
83
|
+
if (response.status !== 200)
|
|
84
|
+
throw new Error(`it answered ${response.status}`);
|
|
85
|
+
if (response.truncated)
|
|
86
|
+
throw new Error("its answer was too large");
|
|
87
|
+
page = JSON.parse(response.body.toString("utf8"));
|
|
88
|
+
}
|
|
89
|
+
catch (err) {
|
|
90
|
+
return {
|
|
91
|
+
hits: [],
|
|
92
|
+
updatedAt: null,
|
|
93
|
+
loading: false,
|
|
94
|
+
total: 0,
|
|
95
|
+
nextCursor: null,
|
|
96
|
+
problem: plainProblem(err)
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
this.catalogNames ??= catalogRegistryNames();
|
|
100
|
+
const seen = new Set();
|
|
101
|
+
const hits = [];
|
|
102
|
+
for (const raw of page.servers ?? []) {
|
|
103
|
+
const item = raw;
|
|
104
|
+
const name = item?.server?.["name"];
|
|
105
|
+
if (typeof name !== "string" || seen.has(name))
|
|
106
|
+
continue;
|
|
107
|
+
const official = (item._meta?.["io.modelcontextprotocol.registry/official"] ?? {});
|
|
108
|
+
if (official.isLatest === false || official.status === "deleted")
|
|
109
|
+
continue;
|
|
110
|
+
seen.add(name);
|
|
111
|
+
hits.push(mapServerJson(item, this.catalogNames));
|
|
112
|
+
}
|
|
113
|
+
const ranked = rankHits(hits, rankBy, services());
|
|
114
|
+
const next = page.metadata?.nextCursor;
|
|
115
|
+
const value = {
|
|
116
|
+
hits: ranked,
|
|
117
|
+
updatedAt: null,
|
|
118
|
+
loading: false,
|
|
119
|
+
total: ranked.length,
|
|
120
|
+
nextCursor: typeof next === "string" && next !== "" && hits.length > 0 ? next : null
|
|
121
|
+
};
|
|
122
|
+
this.cache.set(key, { at: this.now(), value });
|
|
123
|
+
while (this.cache.size > MAX_ENTRIES)
|
|
124
|
+
this.cache.delete(this.cache.keys().next().value);
|
|
125
|
+
return value;
|
|
126
|
+
}
|
|
127
|
+
async close() {
|
|
128
|
+
await this.guard.close();
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
let serviceCache;
|
|
132
|
+
function services() {
|
|
133
|
+
// Only where the catalog entry is the service itself (GitHub's own server), so "git" is not taken for GitHub.
|
|
134
|
+
serviceCache ??= loadCatalog()
|
|
135
|
+
.filter((e) => e.publisher.official)
|
|
136
|
+
.map((e) => ({ id: e.id.split("-")[0], name: e.publisher.name }))
|
|
137
|
+
.filter((x) => x.name.toLowerCase().replace(/[^a-z0-9]/g, "").includes(x.id));
|
|
138
|
+
return serviceCache;
|
|
139
|
+
}
|
|
140
|
+
/** "io.github.github/github-mcp-server" -> owner "github", short "github-mcp-server". */
|
|
141
|
+
function parts(name) {
|
|
142
|
+
const slash = name.indexOf("/");
|
|
143
|
+
const ns = slash >= 0 ? name.slice(0, slash) : "";
|
|
144
|
+
const short = (slash >= 0 ? name.slice(slash + 1) : name).toLowerCase();
|
|
145
|
+
const owner = ns.startsWith("io.github.") ? ns.slice("io.github.".length) : ns.split(".").slice(1).join(".") || ns;
|
|
146
|
+
return { owner: owner.toLowerCase(), short };
|
|
147
|
+
}
|
|
148
|
+
/** The address a hit reaches or the package it runs, to spot the same server listed twice. */
|
|
149
|
+
function sameServerKey(h) {
|
|
150
|
+
const l = h.draft?.launch;
|
|
151
|
+
if (!l)
|
|
152
|
+
return null;
|
|
153
|
+
return l.transport === "http" ? `url ${l.url}` : `run ${l.command} ${(l.args ?? []).filter((a) => !a.startsWith("-")).join(" ")}`;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* The public list answers alphabetically, and "github" matches every
|
|
157
|
+
* `io.github.*` name, so its first page is proxies and look-alikes. Ranked
|
|
158
|
+
* here instead: our own catalog's entry first, then the service's own
|
|
159
|
+
* publisher, then names that are the words typed, then names that contain
|
|
160
|
+
* them; matching only the `io.github.` prefix counts for nothing. One
|
|
161
|
+
* publisher with many hits keeps its best two near the top. The same server
|
|
162
|
+
* listed twice is shown once. And a server not made by a service but asking
|
|
163
|
+
* for that service's key says so.
|
|
164
|
+
*/
|
|
165
|
+
export function rankHits(hits, query, known = []) {
|
|
166
|
+
const q = query.trim().toLowerCase();
|
|
167
|
+
const words = q.split(/\s+/).filter(Boolean);
|
|
168
|
+
const dupes = new Set();
|
|
169
|
+
const kept = [];
|
|
170
|
+
for (const h of hits) {
|
|
171
|
+
const k = sameServerKey(h);
|
|
172
|
+
if (k && dupes.has(k))
|
|
173
|
+
continue;
|
|
174
|
+
if (k)
|
|
175
|
+
dupes.add(k);
|
|
176
|
+
kept.push(withCaution(h, known));
|
|
177
|
+
}
|
|
178
|
+
const score = (h) => {
|
|
179
|
+
if (h.catalogId)
|
|
180
|
+
return 10_000;
|
|
181
|
+
if (!words.length)
|
|
182
|
+
return 0;
|
|
183
|
+
const { owner, short } = parts(h.name);
|
|
184
|
+
const title = (h.title ?? "").toLowerCase();
|
|
185
|
+
const shortWords = short.replace(/[-_.]+/g, " ");
|
|
186
|
+
let s = 0;
|
|
187
|
+
for (const w of words) {
|
|
188
|
+
if (owner === w || owner.split(/[.-]/)[0] === w)
|
|
189
|
+
s += 400; // the service's own publisher
|
|
190
|
+
if (short === w || title === w || shortWords.split(" ").includes(w) || title.split(/\s+/).includes(w))
|
|
191
|
+
s += 300;
|
|
192
|
+
else if (short.startsWith(w) || title.startsWith(w))
|
|
193
|
+
s += 150;
|
|
194
|
+
else if (short.includes(w) || title.includes(w))
|
|
195
|
+
s += 80;
|
|
196
|
+
else if (h.description.toLowerCase().includes(w))
|
|
197
|
+
s += 20;
|
|
198
|
+
}
|
|
199
|
+
if (!h.draft)
|
|
200
|
+
s -= 50; // can't be added: below the ones that can
|
|
201
|
+
return s;
|
|
202
|
+
};
|
|
203
|
+
const scored = kept.map((h, i) => ({ h, i, s: score(h) }));
|
|
204
|
+
// A publisher's third and later hits sink below everyone else's.
|
|
205
|
+
const perOwner = new Map();
|
|
206
|
+
for (const x of [...scored].sort((a, b) => b.s - a.s || a.i - b.i)) {
|
|
207
|
+
const o = parts(x.h.name).owner;
|
|
208
|
+
const n = (perOwner.get(o) ?? 0) + 1;
|
|
209
|
+
perOwner.set(o, n);
|
|
210
|
+
if (n > 2 && !x.h.catalogId)
|
|
211
|
+
x.s -= 1_000;
|
|
212
|
+
}
|
|
213
|
+
return scored.sort((a, b) => b.s - a.s || a.i - b.i).map((x) => x.h);
|
|
214
|
+
}
|
|
215
|
+
/** "This isn't made by GitHub, but asks for your GitHub key." */
|
|
216
|
+
function withCaution(h, known) {
|
|
217
|
+
if (!h.draft || h.catalogId)
|
|
218
|
+
return h;
|
|
219
|
+
const { owner } = parts(h.name);
|
|
220
|
+
const keys = h.draft.fields.filter((f) => f.kind === "secret").map((f) => `${f.id} ${f.label} ${f.technical ?? ""} ${f.help ?? ""}`.toLowerCase());
|
|
221
|
+
if (keys.length === 0)
|
|
222
|
+
return h;
|
|
223
|
+
for (const svc of known) {
|
|
224
|
+
if (owner === svc.id || owner.split(/[.-]/)[0] === svc.id)
|
|
225
|
+
continue;
|
|
226
|
+
if (!keys.some((k) => k.includes(svc.id)))
|
|
227
|
+
continue;
|
|
228
|
+
const words = `This isn't made by ${svc.name}, but asks for your ${svc.name} key. Only give it one if you trust who made it.`;
|
|
229
|
+
return { ...h, caution: words, draft: { ...h.draft, warnings: [...h.draft.warnings, words] } };
|
|
230
|
+
}
|
|
231
|
+
return h;
|
|
232
|
+
}
|
|
233
|
+
function plainProblem(err) {
|
|
234
|
+
const timedOut = err instanceof Error && (err.name === "TimeoutError" || err.name === "AbortError" || /timeout|timed out/i.test(err.message));
|
|
235
|
+
return timedOut
|
|
236
|
+
? "The public server list did not answer in time. The catalog still works; try the search again in a moment."
|
|
237
|
+
: `The public server list could not be searched (${err instanceof Error ? err.message : String(err)}). The catalog still works; try again later.`;
|
|
238
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { type Finding } from "hmcp-scanner";
|
|
2
|
+
import type { LoadedServer } from "./server.js";
|
|
3
|
+
/**
|
|
4
|
+
* Runs the scanner rules over the surface a gateway published.
|
|
5
|
+
*
|
|
6
|
+
* The gateway has its own `scanUpstreams()` (gateway.ts) which builds a
|
|
7
|
+
* `ScanTarget` from the tools it holds in memory. This builds the same target
|
|
8
|
+
* from the inventory that gateway *published*, so the console reports what
|
|
9
|
+
* `hmcp-gateway scan` reports rather than a second, differently-shaped answer.
|
|
10
|
+
* Two scanners that disagree about one gateway would be worse than one.
|
|
11
|
+
*
|
|
12
|
+
* Two things are deliberate:
|
|
13
|
+
*
|
|
14
|
+
* **It scans `rawDescription`, not `description`.** The rewritten text is what
|
|
15
|
+
* the model is told, and it is clean precisely because injection was found in
|
|
16
|
+
* the original. Scanning it would mean HMCP004 and HMCP005 reporting nothing on
|
|
17
|
+
* exactly the surfaces they exist for — a scanner that passes because something
|
|
18
|
+
* else already caught the problem.
|
|
19
|
+
*
|
|
20
|
+
* **It scans the whole published surface, not one tenant's view of it.** A tool
|
|
21
|
+
* one tenant switched off is still advertised to the others, and a credential in
|
|
22
|
+
* its description is disclosed either way. The tenant subtracts rows from what a
|
|
23
|
+
* *caller* can reach; it does not subtract them from what is true about the
|
|
24
|
+
* gateway.
|
|
25
|
+
*/
|
|
26
|
+
/** A `ScanTool` field the console cannot fill, and what that costs. */
|
|
27
|
+
export interface ScanGap {
|
|
28
|
+
readonly field: string;
|
|
29
|
+
readonly rules: readonly string[];
|
|
30
|
+
readonly why: string;
|
|
31
|
+
}
|
|
32
|
+
export interface ScanReport {
|
|
33
|
+
readonly findings: readonly Finding[];
|
|
34
|
+
readonly counts: Readonly<Record<string, number>>;
|
|
35
|
+
readonly ok: boolean;
|
|
36
|
+
/** Tools actually scanned. Zero means the surface, not the scanner, is empty. */
|
|
37
|
+
readonly scanned: number;
|
|
38
|
+
/** Where the surface came from, so a clean report cannot be mistaken for a confirmed one. */
|
|
39
|
+
readonly surface: {
|
|
40
|
+
readonly live: boolean;
|
|
41
|
+
readonly stale: boolean;
|
|
42
|
+
readonly neverPublished: boolean;
|
|
43
|
+
readonly publishedAt: number | null;
|
|
44
|
+
};
|
|
45
|
+
readonly policyPath: string;
|
|
46
|
+
readonly gaps: readonly ScanGap[];
|
|
47
|
+
}
|
|
48
|
+
export declare function buildScan(server: LoadedServer, tenant: string): ScanReport;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { scan } from "hmcp-scanner";
|
|
2
|
+
import { toolSurfaceFor } from "./tools.js";
|
|
3
|
+
/**
|
|
4
|
+
* What the published inventory cannot say.
|
|
5
|
+
*
|
|
6
|
+
* The gateway's own scan does not fill these either — it passes exactly `name`,
|
|
7
|
+
* `description`, `effect`, `inputSchema` and `server` — so this is not the
|
|
8
|
+
* console being a degraded client. It is the honest statement that an upstream
|
|
9
|
+
* MCP server advertises a tool's name, description and schema, and nothing
|
|
10
|
+
* about HTTP verbs, pagination or which argument carries a tenant. Those rules
|
|
11
|
+
* have something to say only about a surface generated from an API spec.
|
|
12
|
+
*/
|
|
13
|
+
const GAPS = [
|
|
14
|
+
{
|
|
15
|
+
field: "hasPaginationCap",
|
|
16
|
+
rules: ["HMCP003"],
|
|
17
|
+
why: "An MCP tool does not declare whether it caps a collection read. Nothing in tools/list carries it, so the pagination-ceiling rule has no input and stays quiet."
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
field: "tenantParams",
|
|
21
|
+
rules: ["HMCP002"],
|
|
22
|
+
why: "Which argument carries a tenant is known for a surface generated from an API spec, not for one discovered over MCP. The tenant policy half of HMCP002 still runs; the agent-settable-boundary half needs this."
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
field: "method / path",
|
|
26
|
+
rules: ["HMCP007", "HMCP008"],
|
|
27
|
+
why: "An MCP tool has no HTTP verb or path of its own. Upstream and egress checks still run from the policy's egress block; the per-operation authentication rule needs a spec."
|
|
28
|
+
}
|
|
29
|
+
];
|
|
30
|
+
export function buildScan(server, tenant) {
|
|
31
|
+
const surface = toolSurfaceFor(server, tenant);
|
|
32
|
+
const tools = surface.entries.map((entry) => ({
|
|
33
|
+
name: entry.name,
|
|
34
|
+
description: entry.rawDescription,
|
|
35
|
+
...(entry.effect !== null ? { effect: entry.effect } : {}),
|
|
36
|
+
inputSchema: entry.inputSchema,
|
|
37
|
+
server: entry.upstream
|
|
38
|
+
}));
|
|
39
|
+
const file = server.policyPath;
|
|
40
|
+
// `upstream`, matching the gateway: these tools were discovered over MCP from
|
|
41
|
+
// a server we did not write, not assembled from a surface we declared. The
|
|
42
|
+
// rules gated on `generated` are the ones that need a spec to say anything,
|
|
43
|
+
// and claiming otherwise would turn their silence into a false pass.
|
|
44
|
+
const result = scan({ kind: "upstream", file, policy: server.policy, tools });
|
|
45
|
+
return {
|
|
46
|
+
findings: result.findings,
|
|
47
|
+
counts: result.counts,
|
|
48
|
+
ok: result.ok,
|
|
49
|
+
scanned: tools.length,
|
|
50
|
+
surface: {
|
|
51
|
+
live: surface.live,
|
|
52
|
+
stale: surface.stale,
|
|
53
|
+
neverPublished: surface.neverPublished,
|
|
54
|
+
publishedAt: surface.publishedAt
|
|
55
|
+
},
|
|
56
|
+
policyPath: server.policyPath,
|
|
57
|
+
gaps: GAPS
|
|
58
|
+
};
|
|
59
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { ApprovalStore, type Policy, type RegistryEntry, type Scope, type ScopedApprovals } from "hmcp-core";
|
|
2
|
+
import { type LoadedGatewayConfig } from "hmcp-gateway";
|
|
3
|
+
/**
|
|
4
|
+
* One registered gateway, resolved from disk.
|
|
5
|
+
*
|
|
6
|
+
* Parsing goes through the gateway's own `loadGatewayConfig`, so the console
|
|
7
|
+
* cannot show a gateway that the gateway itself would refuse to start.
|
|
8
|
+
*
|
|
9
|
+
* Note what is *not* here: the tool surface. A gateway's tools come from its
|
|
10
|
+
* upstreams over MCP, which only the gateway process has spoken to, so they are
|
|
11
|
+
* read separately from what that process publishes rather than from a file next
|
|
12
|
+
* to the config.
|
|
13
|
+
*/
|
|
14
|
+
export interface LoadedServer {
|
|
15
|
+
readonly entry: RegistryEntry;
|
|
16
|
+
/** Base for resolving relative paths in the policy. */
|
|
17
|
+
readonly cwd: string;
|
|
18
|
+
readonly policy: Policy;
|
|
19
|
+
readonly policyPath: string;
|
|
20
|
+
/**
|
|
21
|
+
* The standalone policy file, when there is one, and `null` for a policy
|
|
22
|
+
* written inline in `gateway.yaml`.
|
|
23
|
+
*
|
|
24
|
+
* `policyPath` above is the *gateway config* path, which is what a warning
|
|
25
|
+
* about drift wants to name. This is the file a classification is appended
|
|
26
|
+
* to, and the two are only the same file when the policy is inline -- the
|
|
27
|
+
* case where nothing may be appended at all.
|
|
28
|
+
*/
|
|
29
|
+
readonly policyFile: string | null;
|
|
30
|
+
/**
|
|
31
|
+
* Whether a classification may be written for this server, and why not when
|
|
32
|
+
* it may not. Answered here because it is a property of the server's
|
|
33
|
+
* configuration, and the console has to be able to explain the absence of a
|
|
34
|
+
* control rather than offer one that will be refused.
|
|
35
|
+
*/
|
|
36
|
+
readonly policyWritable: {
|
|
37
|
+
readonly ok: boolean;
|
|
38
|
+
readonly why: string | null;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Whether this gateway permits *reversing* a decision its policy already
|
|
42
|
+
* makes, as against classifying a tool nothing classified. Separate from
|
|
43
|
+
* `policyWritable` because a deployment can allow the second and refuse the
|
|
44
|
+
* first.
|
|
45
|
+
*/
|
|
46
|
+
readonly policyOverrides: boolean;
|
|
47
|
+
readonly gateway: LoadedGatewayConfig;
|
|
48
|
+
/** The audit `component` records from this server are expected to carry. */
|
|
49
|
+
readonly component: string;
|
|
50
|
+
readonly auditPath: string;
|
|
51
|
+
readonly storePath: string;
|
|
52
|
+
readonly tenantValue: string | undefined;
|
|
53
|
+
/**
|
|
54
|
+
* Why the tenant could not be resolved. The console resolves from its *own*
|
|
55
|
+
* environment, so this is advisory: it means this server would fail to start
|
|
56
|
+
* in this process, which is worth saying but is not the server's verdict.
|
|
57
|
+
*/
|
|
58
|
+
readonly tenantError: string | null;
|
|
59
|
+
readonly mtimes: Readonly<Record<string, number>>;
|
|
60
|
+
}
|
|
61
|
+
export declare function loadServer(entry: RegistryEntry): LoadedServer;
|
|
62
|
+
export declare function describeTenantSource(policy: Policy): string;
|
|
63
|
+
export declare function storeFor(server: LoadedServer): ApprovalStore;
|
|
64
|
+
/**
|
|
65
|
+
* Whose rows a request is asking about.
|
|
66
|
+
*
|
|
67
|
+
* This is the console's single most dangerous input, so it is a decision rather
|
|
68
|
+
* than a default. Approvals, grants and the exposure switch are all keyed
|
|
69
|
+
* `(component, tenant)`, and the gateway reads them under the tenant it
|
|
70
|
+
* resolved from the *caller's* token. If the console guesses a different one,
|
|
71
|
+
* every read looks empty and — far worse — every write lands on a row nothing
|
|
72
|
+
* will ever read. A kill switch written into the wrong tenant looks exactly
|
|
73
|
+
* like protection and is none.
|
|
74
|
+
*
|
|
75
|
+
* `hmcp-gateway exposure` already refuses to guess here for the same reason.
|
|
76
|
+
* The console used to guess, from `resolveTenant` over its own environment,
|
|
77
|
+
* while its own comment described that value as advisory.
|
|
78
|
+
*/
|
|
79
|
+
export type TenantChoice = {
|
|
80
|
+
readonly ok: true;
|
|
81
|
+
readonly tenant: string;
|
|
82
|
+
readonly explicit: boolean;
|
|
83
|
+
} | {
|
|
84
|
+
readonly ok: false;
|
|
85
|
+
readonly why: string;
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* Settles the tenant for one request.
|
|
89
|
+
*
|
|
90
|
+
* Three cases, and they differ in whether the console can legitimately know
|
|
91
|
+
* the answer:
|
|
92
|
+
*
|
|
93
|
+
* - **No tenant configured.** The gateway scopes everything to `NO_TENANT`, so
|
|
94
|
+
* that is the only correct key and naming another one is a mistake worth
|
|
95
|
+
* refusing rather than honouring.
|
|
96
|
+
* - **`jwt-verified`.** Resolved per request from the caller's token. One
|
|
97
|
+
* gateway serves every tenant at once and the console's own environment says
|
|
98
|
+
* nothing about any of them, so the request has to name one.
|
|
99
|
+
* - **`static`, `env` or `jwt-claim`.** A property of the deployment, resolved
|
|
100
|
+
* once at startup, and the console reads it from the same place the gateway
|
|
101
|
+
* does. Defaulting is legitimate here — but an explicit value still wins, so
|
|
102
|
+
* an operator whose console environment differs from the gateway's can say
|
|
103
|
+
* so instead of being quietly wrong.
|
|
104
|
+
*/
|
|
105
|
+
export declare function chooseTenant(server: LoadedServer, requested: string | null): TenantChoice;
|
|
106
|
+
/**
|
|
107
|
+
* The scope this gateway's rows live under in that store.
|
|
108
|
+
*
|
|
109
|
+
* The console reads a shared database — one file commonly holds rows for
|
|
110
|
+
* several gateways and several tenants — so every read it makes has to say
|
|
111
|
+
* whose rows it wants.
|
|
112
|
+
*/
|
|
113
|
+
export declare function scopeFor(server: LoadedServer, tenant: string): Scope;
|
|
114
|
+
/** `storeFor` already narrowed to this gateway and one named tenant. */
|
|
115
|
+
export declare function scopedFor(server: LoadedServer, tenant: string): ScopedApprovals;
|
|
116
|
+
/**
|
|
117
|
+
* Which tenants this gateway has any trace of, so a selector can be offered
|
|
118
|
+
* rather than a free-text box with no hint in it.
|
|
119
|
+
*
|
|
120
|
+
* Two sources, because neither alone is complete. `listScopes` covers tenants
|
|
121
|
+
* with approvals, grants or exposure rows; the audit log covers one that has
|
|
122
|
+
* only ever made calls, which has rows in none of those three. Both are
|
|
123
|
+
* historical — a tenant that has never been seen will not appear, which is why
|
|
124
|
+
* naming one by hand stays possible.
|
|
125
|
+
*/
|
|
126
|
+
export declare function knownTenants(server: LoadedServer, auditSample?: number): string[];
|
|
127
|
+
export declare function closeStores(): void;
|