hmcp-web 0.0.1 → 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.
- package/LICENSE +77 -0
- package/README.md +49 -2
- package/THIRD-PARTY-NOTICES.md +110 -0
- package/bin/hmcp-web.js +20 -0
- package/dist/api.d.ts +22 -0
- package/dist/api.js +1458 -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/app-servers.d.ts +85 -0
- package/dist/model/app-servers.js +109 -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/import-record.d.ts +80 -0
- package/dist/model/import-record.js +179 -0
- package/dist/model/metrics.d.ts +65 -0
- package/dist/model/metrics.js +213 -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-import.d.ts +9 -0
- package/dist/routes/connect-import.js +594 -0
- package/dist/routes/connect.d.ts +50 -0
- package/dist/routes/connect.js +691 -0
- package/dist/routes/github.d.ts +97 -0
- package/dist/routes/github.js +587 -0
- package/dist/routes/guard.d.ts +3 -0
- package/dist/routes/guard.js +166 -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 +12 -0
- package/dist/routes/runtime.js +921 -0
- package/dist/routes/servers-add.d.ts +32 -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-CZ78RyRO.js +1 -0
- package/dist-ui/assets/Approvals-DPIlNZsv.js +1 -0
- package/dist-ui/assets/AttachApp-DjSeWCbS.js +5 -0
- package/dist-ui/assets/Connections-qcA96lXh.js +2 -0
- package/dist-ui/assets/Gallery-DB_OO7Vw.js +17 -0
- package/dist-ui/assets/PreApprovals-C4cKajcK.js +1 -0
- package/dist-ui/assets/Protection-B8h-5YAb.js +1 -0
- package/dist-ui/assets/Safety-BQqHyYdo.js +1 -0
- package/dist-ui/assets/Settings-Cx50zZSt.js +1 -0
- package/dist-ui/assets/StartPage-CdX-v7ej.js +1 -0
- package/dist-ui/assets/Suggestions-CRo5UOTT.js +1 -0
- package/dist-ui/assets/Tools-xo39lPKB.js +4 -0
- package/dist-ui/assets/index-DttDjRpu.js +16 -0
- package/dist-ui/assets/index-QeJyD5z2.css +2 -0
- package/dist-ui/assets/kit-DRVm92_t.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,470 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { decide, globMatch, parseArgPath, grantBoundGaps, grantConstraints, grantCoversTool, policyDigest, queryAuditLog, resolveEffect, runtimeStateIsLive, verifyAuditLog } from "hmcp-core";
|
|
3
|
+
import { describeTenantSource, scopedFor, storeFor } from "./server.js";
|
|
4
|
+
import { ENFORCEMENT_PIPELINE } from "./pipeline.js";
|
|
5
|
+
import { toolSurfaceFor } from "./tools.js";
|
|
6
|
+
/** Which of `decide()`'s four stages produced a verdict, named from its rule id. */
|
|
7
|
+
function verdictStage(ruleId) {
|
|
8
|
+
if (ruleId.startsWith("tenant."))
|
|
9
|
+
return "tenant integrity, checked before anything else";
|
|
10
|
+
if (ruleId === "defaults.on_unclassified")
|
|
11
|
+
return "no effect classification, so the default applied";
|
|
12
|
+
if (ruleId === "defaults.mode")
|
|
13
|
+
return "no rule matched, so the posture decided";
|
|
14
|
+
return `policy rule "${ruleId}"`;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* `null` when the surface is unknown, which is not the same as `"locked"`.
|
|
18
|
+
*
|
|
19
|
+
* A gateway that has never published, or whose process is gone, tells us
|
|
20
|
+
* nothing about what is reachable. Reporting `"locked"` for that case — which
|
|
21
|
+
* is what deriving reach from an empty tool list used to do — states that
|
|
22
|
+
* nothing can run, about a gateway that may be serving every tool it has.
|
|
23
|
+
*/
|
|
24
|
+
export function effectiveReach(server, tenant, surface) {
|
|
25
|
+
const policy = server.policy;
|
|
26
|
+
const view = surface ?? toolSurfaceFor(server, tenant);
|
|
27
|
+
if (!view.live)
|
|
28
|
+
return null;
|
|
29
|
+
let reachable = 0;
|
|
30
|
+
let mutating = 0;
|
|
31
|
+
for (const tool of view.entries) {
|
|
32
|
+
// Switched off here is not reachable, whatever policy would have said, and
|
|
33
|
+
// neither is a tool gateway policy hides from everyone.
|
|
34
|
+
if (tool.disabled || tool.hiddenByPolicy)
|
|
35
|
+
continue;
|
|
36
|
+
const decision = decide({
|
|
37
|
+
tool: tool.name,
|
|
38
|
+
effect: tool.effect ?? undefined,
|
|
39
|
+
argsUnknown: true,
|
|
40
|
+
policy,
|
|
41
|
+
...(policy.tenant ? { tenant: { expected: server.tenantValue } } : {})
|
|
42
|
+
});
|
|
43
|
+
if (decision.kind === "deny")
|
|
44
|
+
continue;
|
|
45
|
+
// An approval nobody is able to give is not reach either — this is the
|
|
46
|
+
// same condition `unreachable` reports on each row.
|
|
47
|
+
if (decision.kind === "approve" && policy.approvals.mode === "deny")
|
|
48
|
+
continue;
|
|
49
|
+
reachable++;
|
|
50
|
+
// The effective effect, so a rule that reclassifies a tool as a write is
|
|
51
|
+
// counted as the write it is treated as rather than the read it was built.
|
|
52
|
+
const effect = resolveEffect({ tool: tool.name, effect: tool.effect ?? undefined, policy });
|
|
53
|
+
if (effect === "write" || effect === "destructive")
|
|
54
|
+
mutating++;
|
|
55
|
+
}
|
|
56
|
+
if (reachable === 0)
|
|
57
|
+
return "locked";
|
|
58
|
+
return mutating > 0 ? "approve-writes" : "read-only";
|
|
59
|
+
}
|
|
60
|
+
/** The bounds a rule sets, for the Functions page to show alongside the verdict. */
|
|
61
|
+
function boundsView(rule) {
|
|
62
|
+
if (!rule)
|
|
63
|
+
return null;
|
|
64
|
+
const paths = Object.keys(rule.args ?? {});
|
|
65
|
+
if (paths.length === 0 && rule.unknown_args === "allow")
|
|
66
|
+
return null;
|
|
67
|
+
return {
|
|
68
|
+
ruleId: rule.id,
|
|
69
|
+
paths,
|
|
70
|
+
/*
|
|
71
|
+
* The values, not only the paths. Without them the console can say a tool
|
|
72
|
+
* is bounded on `body` and not that the bound is 120 characters — which is
|
|
73
|
+
* the thing a reviewer is deciding about, and what an editor has to
|
|
74
|
+
* pre-fill so that opening it and saving does not silently change it.
|
|
75
|
+
*/
|
|
76
|
+
constraints: rule.args ?? {},
|
|
77
|
+
onViolation: rule.on_violation,
|
|
78
|
+
unknownArgs: rule.unknown_args
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
/** True when any of the rule's bounds reach into this top-level argument. */
|
|
82
|
+
function boundsArg(rule, name) {
|
|
83
|
+
for (const spec of Object.keys(rule.args ?? {})) {
|
|
84
|
+
const parsed = parseArgPath(spec);
|
|
85
|
+
if (!parsed.ok)
|
|
86
|
+
continue;
|
|
87
|
+
const first = parsed.segments[0];
|
|
88
|
+
if (first && first.kind === "key" && first.name === name)
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
export function toolProtection(server, tool, grants) {
|
|
94
|
+
const policy = server.policy;
|
|
95
|
+
const effect = tool.effect ?? undefined;
|
|
96
|
+
const decision = decide({
|
|
97
|
+
tool: tool.name,
|
|
98
|
+
effect,
|
|
99
|
+
argsUnknown: true,
|
|
100
|
+
policy,
|
|
101
|
+
...(policy.tenant ? { tenant: { expected: server.tenantValue } } : {})
|
|
102
|
+
});
|
|
103
|
+
const effective = resolveEffect({ tool: tool.name, effect, policy });
|
|
104
|
+
const matchedRule = policy.rules.find((r) => globMatch(r.match, tool.name));
|
|
105
|
+
const schema = asObjectSchema(tool.inputSchema);
|
|
106
|
+
const required = new Set(schema.required);
|
|
107
|
+
return {
|
|
108
|
+
name: tool.name,
|
|
109
|
+
description: tool.description,
|
|
110
|
+
rawDescription: tool.rawDescription,
|
|
111
|
+
upstream: tool.upstream,
|
|
112
|
+
effect: tool.effect,
|
|
113
|
+
effectSource: tool.effectSource,
|
|
114
|
+
hiddenByPolicy: tool.hiddenByPolicy,
|
|
115
|
+
injection: tool.injection,
|
|
116
|
+
verdict: { kind: decision.kind, ruleId: decision.ruleId, reason: decision.reason },
|
|
117
|
+
bounds: boundsView(matchedRule),
|
|
118
|
+
verdictStage: verdictStage(decision.ruleId),
|
|
119
|
+
reclassifiedTo: effective && effective !== tool.effect ? effective : null,
|
|
120
|
+
consoleRule: matchedRule && matchedRule.id === `console-${tool.name}` ? { ruleId: matchedRule.id } : null,
|
|
121
|
+
boundsDrift: boundsDrift(policy, tool.name, matchedRule),
|
|
122
|
+
requiresApproval: decision.kind === "approve",
|
|
123
|
+
unreachable: decision.kind === "approve" && policy.approvals.mode === "deny",
|
|
124
|
+
exposure: {
|
|
125
|
+
disabled: tool.disabled !== null,
|
|
126
|
+
setBy: tool.disabled?.setBy ?? null,
|
|
127
|
+
setAt: tool.disabled?.setAt ?? null,
|
|
128
|
+
reason: tool.disabled?.reason || null,
|
|
129
|
+
policyWouldExpose: decision.kind !== "deny"
|
|
130
|
+
},
|
|
131
|
+
args: Object.entries(schema.properties).map(([name, node]) => ({
|
|
132
|
+
name,
|
|
133
|
+
type: node.type,
|
|
134
|
+
required: required.has(name),
|
|
135
|
+
description: node.description,
|
|
136
|
+
// Matched on the path's first segment, not on the whole key: a bound
|
|
137
|
+
// written as `transfer.amount` constrains the `transfer` argument, and a
|
|
138
|
+
// flat lookup would report it as unconstrained.
|
|
139
|
+
constrainedByRule: matchedRule && boundsArg(matchedRule, name) ? matchedRule.id : null,
|
|
140
|
+
enumValues: node.enumValues ?? null,
|
|
141
|
+
format: node.format,
|
|
142
|
+
defaultValue: node.defaultValue ?? null,
|
|
143
|
+
defaultIsUrl: isHttpUrl(node.defaultValue)
|
|
144
|
+
})),
|
|
145
|
+
schemaClosed: schema.additionalProperties === false ? true : schema.additionalProperties === true ? false : null,
|
|
146
|
+
standingGrants: grants.map((grant) => {
|
|
147
|
+
const match = grantCoversTool(grant, tool.name, tool.effect);
|
|
148
|
+
return {
|
|
149
|
+
grantId: grant.id,
|
|
150
|
+
reason: grant.reason,
|
|
151
|
+
covers: match.matches,
|
|
152
|
+
why: match.reason,
|
|
153
|
+
heldBounds: match.matches ? grantBoundGaps(grantConstraints(grant), matchedRule?.args) : [],
|
|
154
|
+
uses: grant.uses,
|
|
155
|
+
maxUses: grant.max_uses,
|
|
156
|
+
expiresAt: grant.expires_at
|
|
157
|
+
};
|
|
158
|
+
}),
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Reads an upstream `inputSchema` without trusting its shape.
|
|
163
|
+
*
|
|
164
|
+
* It is whatever a third-party server advertised, passed through verbatim
|
|
165
|
+
* because converting it would mean either losing constraints or widening what
|
|
166
|
+
* is accepted. So it may be any JSON at all, and this narrows it to the parts
|
|
167
|
+
* the view needs without asserting a type it has not checked.
|
|
168
|
+
*/
|
|
169
|
+
function asObjectSchema(raw) {
|
|
170
|
+
const schema = (typeof raw === "object" && raw !== null ? raw : {});
|
|
171
|
+
const rawProps = schema["properties"];
|
|
172
|
+
const properties = {};
|
|
173
|
+
if (typeof rawProps === "object" && rawProps !== null) {
|
|
174
|
+
for (const [name, node] of Object.entries(rawProps)) {
|
|
175
|
+
const n = (typeof node === "object" && node !== null ? node : {});
|
|
176
|
+
const enumValues = asEnumValues(n["enum"]);
|
|
177
|
+
const defaultValue = asScalarText(n["default"]);
|
|
178
|
+
properties[name] = {
|
|
179
|
+
...(typeof n["type"] === "string" ? { type: n["type"] } : {}),
|
|
180
|
+
...(typeof n["description"] === "string" ? { description: n["description"] } : {}),
|
|
181
|
+
...(typeof n["format"] === "string" ? { format: n["format"] } : {}),
|
|
182
|
+
...(enumValues ? { enumValues } : {}),
|
|
183
|
+
...(defaultValue !== undefined ? { defaultValue } : {})
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
const rawRequired = schema["required"];
|
|
188
|
+
return {
|
|
189
|
+
properties,
|
|
190
|
+
required: Array.isArray(rawRequired) ? rawRequired.filter((r) => typeof r === "string") : [],
|
|
191
|
+
additionalProperties: schema["additionalProperties"]
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* An `enum` reduced to display strings, or undefined where there is nothing
|
|
196
|
+
* to show. JSON Schema permits any value in an `enum`, so a non-scalar member
|
|
197
|
+
* is rendered as its JSON rather than dropped: an argument bounded to one of
|
|
198
|
+
* three objects is still bounded, and hiding that would overstate the freedom
|
|
199
|
+
* the model has.
|
|
200
|
+
*/
|
|
201
|
+
function asEnumValues(raw) {
|
|
202
|
+
if (!Array.isArray(raw) || raw.length === 0)
|
|
203
|
+
return undefined;
|
|
204
|
+
const values = raw.map((v) => asScalarText(v) ?? safeJson(v)).filter((v) => v !== undefined);
|
|
205
|
+
return values.length > 0 ? values : undefined;
|
|
206
|
+
}
|
|
207
|
+
/** A JSON scalar as text. Objects and arrays are not this function's business. */
|
|
208
|
+
function asScalarText(raw) {
|
|
209
|
+
if (typeof raw === "string")
|
|
210
|
+
return raw;
|
|
211
|
+
if (typeof raw === "number" || typeof raw === "boolean")
|
|
212
|
+
return String(raw);
|
|
213
|
+
if (raw === null)
|
|
214
|
+
return "null";
|
|
215
|
+
return undefined;
|
|
216
|
+
}
|
|
217
|
+
function safeJson(raw) {
|
|
218
|
+
try {
|
|
219
|
+
return JSON.stringify(raw);
|
|
220
|
+
}
|
|
221
|
+
catch {
|
|
222
|
+
return undefined;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Whether a default is an absolute `http(s)` URL.
|
|
227
|
+
*
|
|
228
|
+
* Only those two schemes. A `data:` or `file:` default is a different problem
|
|
229
|
+
* and saying "this argument defaults to a URL" about one would send a reviewer
|
|
230
|
+
* looking for network traffic that is not there.
|
|
231
|
+
*/
|
|
232
|
+
function isHttpUrl(raw) {
|
|
233
|
+
if (raw === undefined)
|
|
234
|
+
return false;
|
|
235
|
+
try {
|
|
236
|
+
const protocol = new URL(raw).protocol;
|
|
237
|
+
return protocol === "http:" || protocol === "https:";
|
|
238
|
+
}
|
|
239
|
+
catch {
|
|
240
|
+
return false;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Whether the bounds a console rule copied still match the rule it copied them
|
|
245
|
+
* from.
|
|
246
|
+
*
|
|
247
|
+
* Answered from the policy alone: our rule, then the next rule after it that
|
|
248
|
+
* also matches the tool. If that rule bounds the tool differently, the copy has
|
|
249
|
+
* drifted. Nothing is stored, so there is no second piece of state to keep
|
|
250
|
+
* right.
|
|
251
|
+
*/
|
|
252
|
+
function boundsDrift(policy, tool, matched) {
|
|
253
|
+
if (!matched || matched.id !== `console-${tool}`)
|
|
254
|
+
return null;
|
|
255
|
+
const at = policy.rules.indexOf(matched);
|
|
256
|
+
const source = policy.rules.slice(at + 1).find((r) => globMatch(r.match, tool));
|
|
257
|
+
if (!source)
|
|
258
|
+
return null;
|
|
259
|
+
const differences = [];
|
|
260
|
+
const ours = matched.args ?? {};
|
|
261
|
+
const theirs = source.args ?? {};
|
|
262
|
+
for (const path of new Set([...Object.keys(ours), ...Object.keys(theirs)])) {
|
|
263
|
+
const a = ours[path];
|
|
264
|
+
const b = theirs[path];
|
|
265
|
+
if (JSON.stringify(a ?? null) === JSON.stringify(b ?? null))
|
|
266
|
+
continue;
|
|
267
|
+
if (a === undefined)
|
|
268
|
+
differences.push(`"${source.id}" bounds ${path} and this rule does not`);
|
|
269
|
+
else if (b === undefined)
|
|
270
|
+
differences.push(`this rule bounds ${path} and "${source.id}" no longer does`);
|
|
271
|
+
else
|
|
272
|
+
differences.push(`${path}: this rule says ${describeConstraint(a)}, "${source.id}" says ${describeConstraint(b)}`);
|
|
273
|
+
}
|
|
274
|
+
if (matched.unknown_args !== source.unknown_args) {
|
|
275
|
+
differences.push(`an argument no bound claims: this rule ${matched.unknown_args}s it, "${source.id}" ${source.unknown_args}s it`);
|
|
276
|
+
}
|
|
277
|
+
if (matched.on_violation !== source.on_violation) {
|
|
278
|
+
differences.push(`a call outside the bounds: this rule says ${matched.on_violation}, "${source.id}" says ${source.on_violation}`);
|
|
279
|
+
}
|
|
280
|
+
return differences.length > 0 ? { ruleId: source.id, differences } : null;
|
|
281
|
+
}
|
|
282
|
+
/** One constraint in a few words, for the drift list. */
|
|
283
|
+
function describeConstraint(c) {
|
|
284
|
+
const parts = [];
|
|
285
|
+
if (c.min !== undefined)
|
|
286
|
+
parts.push(`at least ${c.min}`);
|
|
287
|
+
if (c.max !== undefined)
|
|
288
|
+
parts.push(`at most ${c.max}`);
|
|
289
|
+
if (c.maxLength !== undefined)
|
|
290
|
+
parts.push(`at most ${c.maxLength} characters`);
|
|
291
|
+
if (c.maxItems !== undefined)
|
|
292
|
+
parts.push(`at most ${c.maxItems} items`);
|
|
293
|
+
if (c.sum_max !== undefined)
|
|
294
|
+
parts.push(`${c.sum_max} in total`);
|
|
295
|
+
if (c.enum)
|
|
296
|
+
parts.push(`one of ${c.enum.join(", ")}`);
|
|
297
|
+
if (c.pattern)
|
|
298
|
+
parts.push("matching a pattern");
|
|
299
|
+
if (c.optional)
|
|
300
|
+
parts.push("or absent");
|
|
301
|
+
return parts.join(", ") || "bounded";
|
|
302
|
+
}
|
|
303
|
+
function ruleRows(policy, toolNames) {
|
|
304
|
+
return policy.rules.map((rule, index) => {
|
|
305
|
+
const matched = toolNames.filter((name) => globMatch(rule.match, name));
|
|
306
|
+
/*
|
|
307
|
+
* An earlier rule claims every tool *currently served* that this one
|
|
308
|
+
* matches, so nothing reaches it today. Deliberately not "never fires":
|
|
309
|
+
* for a glob, a tool that appears tomorrow and matches it but not the
|
|
310
|
+
* earlier rule still would. That distinction used to be academic and is
|
|
311
|
+
* not any more — a per-tool rule written from the console sits above the
|
|
312
|
+
* glob that used to decide that tool, so this renders routinely, and a
|
|
313
|
+
* reviewer told a live rule "never fires" would delete it.
|
|
314
|
+
*/
|
|
315
|
+
const earlier = policy.rules.slice(0, index);
|
|
316
|
+
const shadow = matched.length > 0
|
|
317
|
+
? earlier.find((prev) => matched.every((name) => globMatch(prev.match, name)))
|
|
318
|
+
: undefined;
|
|
319
|
+
return {
|
|
320
|
+
id: rule.id,
|
|
321
|
+
match: rule.match,
|
|
322
|
+
decision: rule.decision,
|
|
323
|
+
effect: rule.effect ?? null,
|
|
324
|
+
reason: rule.reason ?? null,
|
|
325
|
+
argConstraints: Object.keys(rule.args ?? {}),
|
|
326
|
+
onViolation: rule.on_violation,
|
|
327
|
+
unknownArgs: rule.unknown_args,
|
|
328
|
+
matchedTools: matched,
|
|
329
|
+
shadowedBy: shadow?.id ?? null
|
|
330
|
+
};
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
export function buildProtection(server, tenant, explicit = false) {
|
|
334
|
+
const policy = server.policy;
|
|
335
|
+
const surface = toolSurfaceFor(server, tenant);
|
|
336
|
+
const toolNames = surface.entries.map((t) => t.name);
|
|
337
|
+
const store = storeFor(server);
|
|
338
|
+
const scoped = scopedFor(server, tenant);
|
|
339
|
+
const grants = scoped.listGrants({ activeOnly: true });
|
|
340
|
+
/*
|
|
341
|
+
* One database commonly holds several servers' rows, so "waiting" has two
|
|
342
|
+
* meanings and the console reports both. `own` is this component and this
|
|
343
|
+
* tenant, which the database filters; `others` is the remainder of the file,
|
|
344
|
+
* shown so that a queue someone else is responsible for is visible rather
|
|
345
|
+
* than invisible. This used to be a tool-name heuristic, which could not
|
|
346
|
+
* tell two tenants of the same server apart at all.
|
|
347
|
+
*/
|
|
348
|
+
const ownPending = scoped.listPending(500);
|
|
349
|
+
const allPending = store.listPendingAll(500);
|
|
350
|
+
const pending = { own: ownPending.length, others: allPending.length - ownPending.length };
|
|
351
|
+
const written = policy.audit.enabled && existsSync(server.auditPath);
|
|
352
|
+
const verified = written
|
|
353
|
+
? verifyAuditLog(server.auditPath)
|
|
354
|
+
: { ok: false, count: 0, problems: [] };
|
|
355
|
+
/*
|
|
356
|
+
* Compare what a running server says it parsed against what was just read
|
|
357
|
+
* from disk. The digests are of the *parsed* policies, so reformatting or a
|
|
358
|
+
* changed comment is correctly silent and only a difference in what would be
|
|
359
|
+
* enforced shows up.
|
|
360
|
+
*
|
|
361
|
+
* A row from a process that has stopped refreshing is ignored rather than
|
|
362
|
+
* trusted: it describes a server that is no longer deciding anything, and
|
|
363
|
+
* quoting it would be a second way of saying something untrue about what is
|
|
364
|
+
* in force.
|
|
365
|
+
*/
|
|
366
|
+
const announced = store.runtimeState(server.component);
|
|
367
|
+
const live = announced && runtimeStateIsLive(announced) ? announced : undefined;
|
|
368
|
+
const runtime = {
|
|
369
|
+
running: live !== undefined,
|
|
370
|
+
startedAt: live?.started_at ?? null,
|
|
371
|
+
policyApplied: live ? live.policy_digest === policyDigest(policy) : null,
|
|
372
|
+
policyPath: live?.policy_path || server.policyPath
|
|
373
|
+
};
|
|
374
|
+
return {
|
|
375
|
+
id: server.entry.id,
|
|
376
|
+
label: server.entry.label,
|
|
377
|
+
kind: server.entry.kind,
|
|
378
|
+
tenant_scope: tenant,
|
|
379
|
+
explicitTenant: explicit,
|
|
380
|
+
posture: policy.defaults.mode,
|
|
381
|
+
reach: effectiveReach(server, tenant, surface),
|
|
382
|
+
surface: {
|
|
383
|
+
live: surface.live,
|
|
384
|
+
stale: surface.stale,
|
|
385
|
+
neverPublished: surface.neverPublished,
|
|
386
|
+
publishedAt: surface.publishedAt,
|
|
387
|
+
toolCount: surface.entries.length,
|
|
388
|
+
injectionCount: surface.entries.filter((t) => t.injection && t.injection.length > 0).length,
|
|
389
|
+
hiddenCount: surface.entries.filter((t) => t.hiddenByPolicy).length,
|
|
390
|
+
unclassifiedCount: surface.entries.filter((t) => t.effect === null).length
|
|
391
|
+
},
|
|
392
|
+
onUnclassified: policy.defaults.on_unclassified,
|
|
393
|
+
enforcement: policy.enforcement,
|
|
394
|
+
onToolChange: policy.on_tool_change,
|
|
395
|
+
results: { onInjection: policy.results.on_injection, onSecret: policy.results.on_secret },
|
|
396
|
+
defaults: { mode: policy.defaults.mode, onUnclassified: policy.defaults.on_unclassified },
|
|
397
|
+
/*
|
|
398
|
+
* Whether this gateway's policy file may be appended to, and the digest any
|
|
399
|
+
* write must be given back. Carried on the view the page already loads, so
|
|
400
|
+
* the posture control does not have to ask about a tool to find out whether
|
|
401
|
+
* it can be offered at all.
|
|
402
|
+
*/
|
|
403
|
+
policyWrite: {
|
|
404
|
+
ok: server.policyWritable.ok,
|
|
405
|
+
why: server.policyWritable.why,
|
|
406
|
+
path: server.policyFile,
|
|
407
|
+
digest: policyDigest(policy),
|
|
408
|
+
/* Reversing an existing decision is a separate permission; see config. */
|
|
409
|
+
overrides: server.policyOverrides
|
|
410
|
+
},
|
|
411
|
+
toolBudget: {
|
|
412
|
+
budget: policy.tool_budget,
|
|
413
|
+
enabled: surface.entries.length,
|
|
414
|
+
ok: surface.entries.length <= policy.tool_budget
|
|
415
|
+
},
|
|
416
|
+
rules: ruleRows(policy, toolNames),
|
|
417
|
+
tenant: policy.tenant
|
|
418
|
+
? {
|
|
419
|
+
field: policy.tenant.field,
|
|
420
|
+
aliases: policy.tenant.aliases,
|
|
421
|
+
sourceKind: policy.tenant.source.kind,
|
|
422
|
+
sourceName: "name" in policy.tenant.source ? policy.tenant.source.name : null,
|
|
423
|
+
sourceProse: describeTenantSource(policy),
|
|
424
|
+
inject: policy.tenant.inject,
|
|
425
|
+
onMismatch: policy.tenant.on_mismatch,
|
|
426
|
+
required: policy.tenant.required,
|
|
427
|
+
resolved: server.tenantValue !== undefined,
|
|
428
|
+
error: server.tenantError
|
|
429
|
+
}
|
|
430
|
+
: null,
|
|
431
|
+
egress: {
|
|
432
|
+
allow: policy.egress.allow,
|
|
433
|
+
methods: policy.egress.methods,
|
|
434
|
+
maxBodyBytes: policy.egress.max_body_bytes,
|
|
435
|
+
maxRequestBodyBytes: policy.egress.max_request_body_bytes,
|
|
436
|
+
timeoutMs: policy.egress.timeout_ms,
|
|
437
|
+
maxRedirects: policy.egress.max_redirects,
|
|
438
|
+
blockPrivateIps: policy.egress.block_private_ips,
|
|
439
|
+
allowHttp: policy.egress.allow_http,
|
|
440
|
+
allowIpLiterals: policy.egress.allow_ip_literals
|
|
441
|
+
},
|
|
442
|
+
approvals: {
|
|
443
|
+
mode: policy.approvals.mode,
|
|
444
|
+
ttlSeconds: policy.approvals.ttl_seconds,
|
|
445
|
+
singleUse: policy.approvals.single_use,
|
|
446
|
+
storePath: server.storePath,
|
|
447
|
+
pendingCount: pending.own,
|
|
448
|
+
pendingElsewhere: pending.others,
|
|
449
|
+
activeGrantCount: grants.length
|
|
450
|
+
},
|
|
451
|
+
audit: {
|
|
452
|
+
enabled: policy.audit.enabled,
|
|
453
|
+
path: server.auditPath,
|
|
454
|
+
hashChain: policy.audit.hash_chain,
|
|
455
|
+
recordArgs: policy.audit.record_args,
|
|
456
|
+
redact: policy.audit.redact,
|
|
457
|
+
onFailure: policy.audit.on_failure,
|
|
458
|
+
verify: { ok: verified.ok, written, count: verified.count, problemCount: verified.problems.length }
|
|
459
|
+
},
|
|
460
|
+
runtime,
|
|
461
|
+
pipeline: ENFORCEMENT_PIPELINE,
|
|
462
|
+
tools: surface.entries.map((tool) => toolProtection(server, tool, grants))
|
|
463
|
+
};
|
|
464
|
+
}
|
|
465
|
+
/** The last few decisions recorded for one tool. */
|
|
466
|
+
export function recentActivity(server, tool, limit = 10, otherComponents = []) {
|
|
467
|
+
if (!server.policy.audit.enabled)
|
|
468
|
+
return [];
|
|
469
|
+
return queryAuditLog(server.auditPath, { tool, limit, ...(otherComponents.length > 0 ? { excludeComponent: otherComponents } : {}) }).records;
|
|
470
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { type EgressConfig } from "hmcp-core";
|
|
2
|
+
import type { RegistrySearchResponse } from "../contracts/onboarding.js";
|
|
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 declare const REGISTRY_URL = "https://registry.modelcontextprotocol.io";
|
|
16
|
+
export interface RegistrySearchOptions {
|
|
17
|
+
/** The registry's base address; a test points this at a local stub. */
|
|
18
|
+
readonly baseUrl?: string;
|
|
19
|
+
/** Egress overrides, for a local stub (allow_http, block_private_ips...). */
|
|
20
|
+
readonly egress?: Partial<EgressConfig>;
|
|
21
|
+
readonly timeoutMs?: number;
|
|
22
|
+
readonly now?: () => number;
|
|
23
|
+
}
|
|
24
|
+
export declare class RegistrySearch {
|
|
25
|
+
private readonly baseUrl;
|
|
26
|
+
private readonly guard;
|
|
27
|
+
private readonly timeoutMs;
|
|
28
|
+
private readonly now;
|
|
29
|
+
/** q + cursor -> answer. A Map keeps insertion order, which makes it a small LRU. */
|
|
30
|
+
private readonly cache;
|
|
31
|
+
private catalogNames;
|
|
32
|
+
constructor(options?: RegistrySearchOptions);
|
|
33
|
+
/**
|
|
34
|
+
* One page of results. An empty query gives the registry's own first page. Never throws.
|
|
35
|
+
* The registry matches names only, so "brave search" finds nothing; with no
|
|
36
|
+
* hits, each word is tried alone (longest first), ranked by all of them.
|
|
37
|
+
*/
|
|
38
|
+
search(query: string, cursor?: string | null): Promise<RegistrySearchResponse>;
|
|
39
|
+
private searchOnce;
|
|
40
|
+
close(): Promise<void>;
|
|
41
|
+
}
|
|
42
|
+
type Hit = RegistrySearchResponse["hits"][number];
|
|
43
|
+
/** A service people already trust by name, from our own catalog: "github" is GitHub. */
|
|
44
|
+
export interface Service {
|
|
45
|
+
readonly id: string;
|
|
46
|
+
readonly name: string;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* The public list answers alphabetically, and "github" matches every
|
|
50
|
+
* `io.github.*` name, so its first page is proxies and look-alikes. Ranked
|
|
51
|
+
* here instead: our own catalog's entry first, then the service's own
|
|
52
|
+
* publisher, then names that are the words typed, then names that contain
|
|
53
|
+
* them; matching only the `io.github.` prefix counts for nothing. One
|
|
54
|
+
* publisher with many hits keeps its best two near the top. The same server
|
|
55
|
+
* listed twice is shown once. And a server not made by a service but asking
|
|
56
|
+
* for that service's key says so.
|
|
57
|
+
*/
|
|
58
|
+
export declare function rankHits(hits: Hit[], query: string, known?: readonly Service[]): Hit[];
|
|
59
|
+
export {};
|