@intutic/mcp-governance-proxy 2.2.0 → 2.3.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/README.md +7 -6
- package/dist/agentTools.d.ts +68 -0
- package/dist/agentTools.d.ts.map +1 -0
- package/dist/agentTools.js +150 -0
- package/dist/agentTools.js.map +1 -0
- package/dist/anomaly/detectors.js +1 -1
- package/dist/anomaly/detectors.js.map +1 -1
- package/dist/approvalHold.d.ts +8 -7
- package/dist/approvalHold.d.ts.map +1 -1
- package/dist/approvalHold.js +7 -6
- package/dist/approvalHold.js.map +1 -1
- package/dist/budget.d.ts +133 -0
- package/dist/budget.d.ts.map +1 -0
- package/dist/budget.js +191 -0
- package/dist/budget.js.map +1 -0
- package/dist/config.d.ts +1 -1
- package/dist/config.js +1 -1
- package/dist/config.js.map +1 -1
- package/dist/daemon/healthMonitor.d.ts.map +1 -1
- package/dist/daemon/healthMonitor.js +0 -1
- package/dist/daemon/healthMonitor.js.map +1 -1
- package/dist/daemon/index.d.ts +0 -2
- package/dist/daemon/index.d.ts.map +1 -1
- package/dist/daemon/index.js +0 -2
- package/dist/daemon/index.js.map +1 -1
- package/dist/daemon/policyCache.d.ts +15 -3
- package/dist/daemon/policyCache.d.ts.map +1 -1
- package/dist/daemon/policyCache.js +36 -15
- package/dist/daemon/policyCache.js.map +1 -1
- package/dist/daemon/socketServer.d.ts +0 -1
- package/dist/daemon/socketServer.d.ts.map +1 -1
- package/dist/daemon/socketServer.js +0 -1
- package/dist/daemon/socketServer.js.map +1 -1
- package/dist/daemon/statusReporter.d.ts.map +1 -1
- package/dist/daemon/statusReporter.js +0 -1
- package/dist/daemon/statusReporter.js.map +1 -1
- package/dist/daemon/telemetryBatcher.d.ts.map +1 -1
- package/dist/daemon/telemetryBatcher.js +0 -1
- package/dist/daemon/telemetryBatcher.js.map +1 -1
- package/dist/daemonClient.d.ts.map +1 -1
- package/dist/daemonClient.js +0 -1
- package/dist/daemonClient.js.map +1 -1
- package/dist/dlp.d.ts +32 -3
- package/dist/dlp.d.ts.map +1 -1
- package/dist/dlp.js +116 -18
- package/dist/dlp.js.map +1 -1
- package/dist/dlpPii.d.ts +66 -0
- package/dist/dlpPii.d.ts.map +1 -0
- package/dist/dlpPii.js +235 -0
- package/dist/dlpPii.js.map +1 -0
- package/dist/emitter.d.ts +27 -3
- package/dist/emitter.d.ts.map +1 -1
- package/dist/emitter.js +7 -1
- package/dist/emitter.js.map +1 -1
- package/dist/guardedValkey.d.ts +40 -0
- package/dist/guardedValkey.d.ts.map +1 -0
- package/dist/guardedValkey.js +84 -0
- package/dist/guardedValkey.js.map +1 -0
- package/dist/injection.js +1 -1
- package/dist/interceptor.d.ts +53 -10
- package/dist/interceptor.d.ts.map +1 -1
- package/dist/interceptor.js +154 -65
- package/dist/interceptor.js.map +1 -1
- package/dist/policy.d.ts +21 -1
- package/dist/policy.d.ts.map +1 -1
- package/dist/policy.js +29 -2
- package/dist/policy.js.map +1 -1
- package/dist/proxy.d.ts +25 -6
- package/dist/proxy.d.ts.map +1 -1
- package/dist/proxy.js +113 -51
- package/dist/proxy.js.map +1 -1
- package/dist/refusals.d.ts +26 -0
- package/dist/refusals.d.ts.map +1 -0
- package/dist/refusals.js +43 -0
- package/dist/refusals.js.map +1 -0
- package/dist/registryObserver.d.ts +9 -5
- package/dist/registryObserver.d.ts.map +1 -1
- package/dist/registryObserver.js +19 -8
- package/dist/registryObserver.js.map +1 -1
- package/dist/session.d.ts +1 -1
- package/dist/session.js +1 -1
- package/dist/sessionScope.d.ts +1 -1
- package/dist/sessionScope.js +1 -1
- package/dist/sessionStore.d.ts +10 -23
- package/dist/sessionStore.d.ts.map +1 -1
- package/dist/sessionStore.js +17 -76
- package/dist/sessionStore.js.map +1 -1
- package/dist/wasm/context.d.ts +10 -0
- package/dist/wasm/context.d.ts.map +1 -1
- package/dist/wasm/context.js +27 -0
- package/dist/wasm/context.js.map +1 -1
- package/dist/wasm/hostImports.d.ts +3 -3
- package/dist/wasm/hostImports.d.ts.map +1 -1
- package/dist/wasm/hostImports.js +8 -7
- package/dist/wasm/hostImports.js.map +1 -1
- package/dist/wasm/loader.d.ts +8 -1
- package/dist/wasm/loader.d.ts.map +1 -1
- package/dist/wasm/loader.js +2 -0
- package/dist/wasm/loader.js.map +1 -1
- package/dist/wasm/referencedFiles.d.ts +29 -4
- package/dist/wasm/referencedFiles.d.ts.map +1 -1
- package/dist/wasm/referencedFiles.js +48 -21
- package/dist/wasm/referencedFiles.js.map +1 -1
- package/dist/wasm/runner.d.ts +106 -22
- package/dist/wasm/runner.d.ts.map +1 -1
- package/dist/wasm/runner.js +194 -74
- package/dist/wasm/runner.js.map +1 -1
- package/dist/wasm/watch.js +1 -1
- package/dist/wasm/worker.d.ts +10 -6
- package/dist/wasm/worker.d.ts.map +1 -1
- package/dist/wasm/worker.js +93 -9
- package/dist/wasm/worker.js.map +1 -1
- package/package.json +5 -4
- package/dist/toolPoison.d.ts +0 -32
- package/dist/toolPoison.d.ts.map +0 -1
- package/dist/toolPoison.js +0 -81
- package/dist/toolPoison.js.map +0 -1
- package/dist/wasm/fuel.d.ts +0 -35
- package/dist/wasm/fuel.d.ts.map +0 -1
- package/dist/wasm/fuel.js +0 -299
- package/dist/wasm/fuel.js.map +0 -1
- package/dist/wasm/memoryCap.d.ts +0 -21
- package/dist/wasm/memoryCap.d.ts.map +0 -1
- package/dist/wasm/memoryCap.js +0 -54
- package/dist/wasm/memoryCap.js.map +0 -1
- package/dist/wasm/wasmBinary.d.ts +0 -25
- package/dist/wasm/wasmBinary.d.ts.map +0 -1
- package/dist/wasm/wasmBinary.js +0 -100
- package/dist/wasm/wasmBinary.js.map +0 -1
package/README.md
CHANGED
|
@@ -44,19 +44,20 @@ Every governance check proxy mode applies to a stdio server — allowlists, `too
|
|
|
44
44
|
|
|
45
45
|
### DLP Scanning
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
Built-in patterns, plus any the workspace adds. A match in a call's arguments blocks the call; a credential in a result is redacted before the agent reads it:
|
|
48
48
|
|
|
49
|
-
-
|
|
50
|
-
- PEM and EC private
|
|
51
|
-
-
|
|
52
|
-
|
|
49
|
+
- 9 secret patterns: OpenAI, Anthropic and Google API keys, GitHub personal access and server tokens, Slack bot and user tokens, AWS access key IDs, and long hex strings that look like secrets
|
|
50
|
+
- 2 private-key patterns: PEM and EC private key headers
|
|
51
|
+
- Destructive commands: `rm -rf /` and 4 SQL statements (`DROP TABLE`, `DROP DATABASE`, `DROP SCHEMA`, `TRUNCATE TABLE`) — arguments only, matched against each decoded argument string; whitespace, a line continuation, comments or an escaped `\n` between the SQL keywords do not hide them, and a quoted mention counts
|
|
52
|
+
|
|
53
|
+
**PII detectors**, the same validated detectors the LLM proxy runs: payment card numbers (Luhn check), IBANs (mod 97 check) and US Social Security numbers (checked against issued ranges) are on by default, email addresses and phone numbers off. Arguments are never rewritten, so an enabled detector blocks the call when it finds PII in the arguments; in a result, the PII is redacted. `INTUTIC_MCP_DLP_DETECTORS` sets this machine's actions, as a JSON object of detector id → `off`, `redact` or `block` (such as `{"pii.email":"redact"}`), and a connected workspace's `piiDetectors` setting sets the baseline, which the machine's own setting may only make stricter. See [PII detectors](https://docs.intutic.ai/guide/policies#pii-detectors).
|
|
53
54
|
|
|
54
55
|
### Policy Enforcement
|
|
55
56
|
|
|
56
57
|
- **MCP server registry**: a server an owner or admin blocked is refused; under the workspace's `deny` default, so is any server not yet approved; a tool switched off within a server is hidden and refused
|
|
57
58
|
- **Allowlists**: `mcpAllowedServers` / `mcpAllowedTools`, empty meaning unrestricted
|
|
58
59
|
- **SSO group policy**: the workspace's `sso_group_policy`, applied to the member the API key belongs to
|
|
59
|
-
- **SOP rules** matched on tool name and arguments: `block`, `warn`, or `require_approval` — a hold recorded in the workspace's review queue; the identical call passes
|
|
60
|
+
- **SOP rules** matched on tool name and arguments: `block`, `warn`, or `require_approval` — a hold recorded in the workspace's review queue; once it is approved, the identical call passes only while the workspace's review-hold bypass is on
|
|
60
61
|
- **Audit events** for every decision, carrying the caller: API key prefix, OS user, harness session and server
|
|
61
62
|
|
|
62
63
|
## Binaries
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* agentTools.ts — what the `intutic` MCP server's own tools answer.
|
|
3
|
+
*
|
|
4
|
+
* The standalone `intutic` entry (proxy.ts `runStandalone`) gives an agent
|
|
5
|
+
* tools to ask about governance instead of guessing from a refusal message:
|
|
6
|
+
* whether a hold it was given has been decided and whether a retry will
|
|
7
|
+
* pass, what the MCP server registry says about a server, and how much of
|
|
8
|
+
* each MCP call budget is left. The answers are built here, from what the
|
|
9
|
+
* control plane and Valkey return, so they can be tested without a server.
|
|
10
|
+
*
|
|
11
|
+
* @module
|
|
12
|
+
*/
|
|
13
|
+
import { type McpBudgetPolicy } from '@intutic/shared-types';
|
|
14
|
+
/** One control-plane read, never thrown: a failure degrades a tool's answer, it does not crash the server. */
|
|
15
|
+
export type ControlPlaneResult = {
|
|
16
|
+
ok: true;
|
|
17
|
+
data: unknown;
|
|
18
|
+
} | {
|
|
19
|
+
ok: false;
|
|
20
|
+
reason: 'forbidden' | 'not_found' | 'unreachable';
|
|
21
|
+
};
|
|
22
|
+
export declare function readControlPlane(controlPlaneUrl: string, apiKey: string, workspaceId: string, path: string): Promise<ControlPlaneResult>;
|
|
23
|
+
/** Renders a failed read as text for the agent, naming the actual cause. */
|
|
24
|
+
export declare function describeFailure(result: {
|
|
25
|
+
reason: 'forbidden' | 'not_found' | 'unreachable';
|
|
26
|
+
}, what: string): string;
|
|
27
|
+
export interface HoldStatus {
|
|
28
|
+
holdId: string;
|
|
29
|
+
status: 'PENDING_REVIEW' | 'APPROVED' | 'REJECTED' | string;
|
|
30
|
+
/** What the agent should do next. */
|
|
31
|
+
retry: 'wait' | 'passes' | 'held_again' | 'do_not_retry';
|
|
32
|
+
/** Until when a retry passes, when it does. */
|
|
33
|
+
bypassExpiresAt?: string;
|
|
34
|
+
message: string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Where a hold stands, from its decision row and the workspace's approved
|
|
38
|
+
* bypasses. An approval lets the identical retry through only while a bypass
|
|
39
|
+
* exists for it, which needs the workspace's review-hold bypass setting on.
|
|
40
|
+
*/
|
|
41
|
+
export declare function holdStatus(holdId: string, decision: {
|
|
42
|
+
status?: unknown;
|
|
43
|
+
}, bypasses: unknown): HoldStatus;
|
|
44
|
+
/**
|
|
45
|
+
* What the registry means for calls to each server: whether calls to it run,
|
|
46
|
+
* and which of its tools are switched off. `server` narrows it to one.
|
|
47
|
+
*/
|
|
48
|
+
export declare function registryStatus(data: unknown, server?: string): Record<string, unknown>;
|
|
49
|
+
export interface BudgetRemaining {
|
|
50
|
+
budgetId: string;
|
|
51
|
+
counts: string;
|
|
52
|
+
period: string;
|
|
53
|
+
limit: number;
|
|
54
|
+
/** `null` when the count could not be read. */
|
|
55
|
+
used: number | null;
|
|
56
|
+
remaining: number | null;
|
|
57
|
+
resetAt: string;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Every MCP call budget that can count this caller's calls, with what is
|
|
61
|
+
* left of it this period. `readUsed` reads the counters the proxies keep
|
|
62
|
+
* (budget.ts), returning `undefined` when it cannot.
|
|
63
|
+
*/
|
|
64
|
+
export declare function budgetRemaining(policy: McpBudgetPolicy, workspaceId: string, caller: {
|
|
65
|
+
memberId: string | null;
|
|
66
|
+
fallback: string;
|
|
67
|
+
}, readUsed: (keys: string[]) => Promise<number[] | undefined>, nowMs?: number): Promise<BudgetRemaining[]>;
|
|
68
|
+
//# sourceMappingURL=agentTools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agentTools.d.ts","sourceRoot":"","sources":["../src/agentTools.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAmC,KAAK,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAG7F,8GAA8G;AAC9G,MAAM,MAAM,kBAAkB,GAC1B;IA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AC/C,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;IACnB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;IACxB,OAAO,EAAE,MAAM,CAAA;CAChB;AAED;;;;GAIG;AACH,wBAAsB,eAAe,CACnC,MAAM,EAAE,eAAe,EACvB,WAAW,EAAE,MAAM,EACnB,MAAM,EAAE;IAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,EACrD,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,OAAO,CAAC,MAAM,EAAE,GAAG,SAAS,CAAC,EAC3D,KAAK,GAAE,MAAmB,GACzB,OAAO,CAAC,eAAe,EAAE,CAAC,CAoB5B"}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* agentTools.ts — what the `intutic` MCP server's own tools answer.
|
|
3
|
+
*
|
|
4
|
+
* The standalone `intutic` entry (proxy.ts `runStandalone`) gives an agent
|
|
5
|
+
* tools to ask about governance instead of guessing from a refusal message:
|
|
6
|
+
* whether a hold it was given has been decided and whether a retry will
|
|
7
|
+
* pass, what the MCP server registry says about a server, and how much of
|
|
8
|
+
* each MCP call budget is left. The answers are built here, from what the
|
|
9
|
+
* control plane and Valkey return, so they can be tested without a server.
|
|
10
|
+
*
|
|
11
|
+
* @module
|
|
12
|
+
*/
|
|
13
|
+
import { budgetWindow, describeMcpBudget } from '@intutic/shared-types';
|
|
14
|
+
import { budgetCounterKey } from './budget.js';
|
|
15
|
+
export async function readControlPlane(controlPlaneUrl, apiKey, workspaceId, path) {
|
|
16
|
+
try {
|
|
17
|
+
const res = await fetch(`${controlPlaneUrl}${path}`, {
|
|
18
|
+
headers: { Authorization: `Bearer ${apiKey}`, 'x-workspace-id': workspaceId },
|
|
19
|
+
signal: AbortSignal.timeout(5000),
|
|
20
|
+
});
|
|
21
|
+
// 403 and 404 are answers, not outages. Collapsing them into
|
|
22
|
+
// "unreachable" sends someone debugging their network for an hour.
|
|
23
|
+
if (res.status === 403)
|
|
24
|
+
return { ok: false, reason: 'forbidden' };
|
|
25
|
+
if (res.status === 404)
|
|
26
|
+
return { ok: false, reason: 'not_found' };
|
|
27
|
+
if (!res.ok)
|
|
28
|
+
return { ok: false, reason: 'unreachable' };
|
|
29
|
+
return { ok: true, data: await res.json() };
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return { ok: false, reason: 'unreachable' };
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/** Renders a failed read as text for the agent, naming the actual cause. */
|
|
36
|
+
export function describeFailure(result, what) {
|
|
37
|
+
if (result.reason === 'forbidden') {
|
|
38
|
+
return `Your Intutic role is not permitted to ${what}. This needs the OWNER, ADMIN or EM role.`;
|
|
39
|
+
}
|
|
40
|
+
if (result.reason === 'not_found')
|
|
41
|
+
return `The Intutic control plane answered 404 when asked to ${what}.`;
|
|
42
|
+
return `Could not reach control plane to ${what}.`;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Where a hold stands, from its decision row and the workspace's approved
|
|
46
|
+
* bypasses. An approval lets the identical retry through only while a bypass
|
|
47
|
+
* exists for it, which needs the workspace's review-hold bypass setting on.
|
|
48
|
+
*/
|
|
49
|
+
export function holdStatus(holdId, decision, bypasses) {
|
|
50
|
+
const status = typeof decision.status === 'string' ? decision.status : 'UNKNOWN';
|
|
51
|
+
if (status === 'PENDING_REVIEW') {
|
|
52
|
+
return {
|
|
53
|
+
holdId,
|
|
54
|
+
status,
|
|
55
|
+
retry: 'wait',
|
|
56
|
+
message: 'Waiting for an owner, admin or engineering manager to approve or reject it ' +
|
|
57
|
+
`(intutic decision approve ${holdId}, or the Slack card). Do not retry yet; tell the user the hold id.`,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
if (status === 'REJECTED') {
|
|
61
|
+
return { holdId, status, retry: 'do_not_retry', message: 'Rejected. Do not retry this call; continue without it or ask the user.' };
|
|
62
|
+
}
|
|
63
|
+
if (status === 'APPROVED') {
|
|
64
|
+
const list = bypasses?.bypasses;
|
|
65
|
+
const bypass = Array.isArray(list)
|
|
66
|
+
? list.find((b) => b.holdId === holdId && typeof b.expiresAt === 'string' && Date.parse(b.expiresAt) > Date.now())
|
|
67
|
+
: undefined;
|
|
68
|
+
if (bypass) {
|
|
69
|
+
return {
|
|
70
|
+
holdId,
|
|
71
|
+
status,
|
|
72
|
+
retry: 'passes',
|
|
73
|
+
bypassExpiresAt: bypass.expiresAt,
|
|
74
|
+
message: `Approved. Retry the identical call (same tool, same arguments) before ${String(bypass.expiresAt)}; any other call is not covered.`,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
holdId,
|
|
79
|
+
status,
|
|
80
|
+
retry: 'held_again',
|
|
81
|
+
message: "Approved, but a retry will be held again: the workspace's review-hold bypass " +
|
|
82
|
+
'(reviewHoldBypassEnabled) is off, or the approval window has passed. Tell the user the call was approved ' +
|
|
83
|
+
'and needs to be run another way, or ask an admin to turn the bypass on.',
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
return { holdId, status, retry: 'do_not_retry', message: `The hold is ${status}. Do not retry this call.` };
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* What the registry means for calls to each server: whether calls to it run,
|
|
90
|
+
* and which of its tools are switched off. `server` narrows it to one.
|
|
91
|
+
*/
|
|
92
|
+
export function registryStatus(data, server) {
|
|
93
|
+
const body = (data ?? {});
|
|
94
|
+
const defaultPolicy = body.defaultPolicy === 'deny' ? 'deny' : 'allow';
|
|
95
|
+
const servers = (Array.isArray(body.servers) ? body.servers : [])
|
|
96
|
+
.filter((s) => typeof s.serverName === 'string' && (!server || s.serverName === server))
|
|
97
|
+
.map((s) => {
|
|
98
|
+
const status = String(s.status);
|
|
99
|
+
const held = s.heldForReview === true;
|
|
100
|
+
const calls = held
|
|
101
|
+
? 'refused (SERVER_HELD): a high-risk tool change is waiting for an owner or admin'
|
|
102
|
+
: status === 'blocked'
|
|
103
|
+
? 'refused (SERVER_BLOCKED)'
|
|
104
|
+
: status === 'approved' || defaultPolicy === 'allow'
|
|
105
|
+
? 'allowed'
|
|
106
|
+
: 'refused (SERVER_NOT_APPROVED): waiting in the approval queue';
|
|
107
|
+
return {
|
|
108
|
+
server: s.serverName,
|
|
109
|
+
status,
|
|
110
|
+
calls,
|
|
111
|
+
disabledTools: Array.isArray(s.disabledTools) ? s.disabledTools : [],
|
|
112
|
+
};
|
|
113
|
+
});
|
|
114
|
+
return {
|
|
115
|
+
defaultPolicy,
|
|
116
|
+
servers,
|
|
117
|
+
...(server && servers.length === 0
|
|
118
|
+
? {
|
|
119
|
+
note: defaultPolicy === 'deny'
|
|
120
|
+
? `"${server}" is not in the registry; calls to it are refused (SERVER_NOT_APPROVED) until an owner or admin approves it.`
|
|
121
|
+
: `"${server}" is not in the registry yet; calls to it are allowed under the default policy.`,
|
|
122
|
+
}
|
|
123
|
+
: {}),
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Every MCP call budget that can count this caller's calls, with what is
|
|
128
|
+
* left of it this period. `readUsed` reads the counters the proxies keep
|
|
129
|
+
* (budget.ts), returning `undefined` when it cannot.
|
|
130
|
+
*/
|
|
131
|
+
export async function budgetRemaining(policy, workspaceId, caller, readUsed, nowMs = Date.now()) {
|
|
132
|
+
const mine = policy.budgets.filter((b) => b.memberId === undefined || b.memberId === caller.memberId);
|
|
133
|
+
const subject = caller.memberId ?? caller.fallback;
|
|
134
|
+
const windows = mine.map((b) => budgetWindow(b.period, nowMs));
|
|
135
|
+
const keys = mine.map((b, i) => budgetCounterKey(workspaceId, b.id, windows[i].startMs, b.scope === 'member' || b.scope === 'member_server' ? subject : ''));
|
|
136
|
+
const used = keys.length > 0 ? await readUsed(keys) : [];
|
|
137
|
+
return mine.map((b, i) => {
|
|
138
|
+
const n = used?.[i];
|
|
139
|
+
return {
|
|
140
|
+
budgetId: b.id,
|
|
141
|
+
counts: describeMcpBudget(b, b.memberId ? 'you' : undefined),
|
|
142
|
+
period: b.period,
|
|
143
|
+
limit: b.limit,
|
|
144
|
+
used: n ?? null,
|
|
145
|
+
remaining: n === undefined ? null : Math.max(0, b.limit - n),
|
|
146
|
+
resetAt: new Date(windows[i].resetAtMs).toISOString(),
|
|
147
|
+
};
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
//# sourceMappingURL=agentTools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agentTools.js","sourceRoot":"","sources":["../src/agentTools.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAwB,MAAM,uBAAuB,CAAA;AAC7F,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAO9C,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,eAAuB,EACvB,MAAc,EACd,WAAmB,EACnB,IAAY;IAEZ,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,GAAG,eAAe,GAAG,IAAI,EAAE,EAAE;YACnD,OAAO,EAAE,EAAE,aAAa,EAAE,UAAU,MAAM,EAAE,EAAE,gBAAgB,EAAE,WAAW,EAAE;YAC7E,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC;SAClC,CAAC,CAAA;QACF,6DAA6D;QAC7D,mEAAmE;QACnE,IAAI,GAAG,CAAC,MAAM,KAAK,GAAG;YAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,CAAA;QACjE,IAAI,GAAG,CAAC,MAAM,KAAK,GAAG;YAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,CAAA;QACjE,IAAI,CAAC,GAAG,CAAC,EAAE;YAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,CAA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CAAC,EAAE,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC;YAC5D,OAAO,EAAE,IAAI,IAAI,CAAC,OAAO,CAAC,CAAC,CAAE,CAAC,SAAS,CAAC,CAAC,WAAW,EAAE;SACvD,CAAA;IACH,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
*
|
|
18
18
|
* @module
|
|
19
19
|
*/
|
|
20
|
-
import { scanToolDescription } from '
|
|
20
|
+
import { scanToolDescription } from '@intutic/shared-types';
|
|
21
21
|
/** Severity order for sorting/clamping — mirrors `Disposition`'s derived
|
|
22
22
|
* `Ord` in mod.rs (`Steer < Reask < Ask < Kill`); this package never uses
|
|
23
23
|
* `Ask`, so the four-way order collapses to three. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"detectors.js","sourceRoot":"","sources":["../../src/anomaly/detectors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"detectors.js","sourceRoot":"","sources":["../../src/anomaly/detectors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AAK3D;;uDAEuD;AACvD,MAAM,CAAC,MAAM,oBAAoB,GAA0C;IACzE,KAAK,EAAE,CAAC;IACR,KAAK,EAAE,CAAC;IACR,IAAI,EAAE,CAAC;CACR,CAAA;AAgBD;;;;;GAKG;AACH,SAAS,mBAAmB,CAAC,QAAgB,EAAE,SAAiB;IAC9D,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,QAAQ,GAAG,SAAS,CAAC,CAAA;IAChD,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,GAAG,GAAG,GAAG,MAAM,EAAE,IAAI,CAAC,CAAA;AAC5C,CAAC;AAED,+EAA+E;A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UAAU,aAAa,CAAC,2BAA8C;IAC1E,MAAM,QAAQ,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,2BAA2B,CAAC,CAAC,CAAC,IAAI,EAAE,CAAA;IACxE,IAAI,QAAQ,CAAC,MAAM,GAAG,wBAAwB;QAAE,OAAO,IAAI,CAAA;IAC3D,OAAO;QACL,UAAU,EAAE,gBAAgB;QAC5B,IAAI,EAAE,mBAAmB;QACzB,MAAM,EAAE,qBAAqB,QAAQ,CAAC,MAAM,iDAAiD,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG;QACnH,UAAU,EAAE,GAAG;QACf,WAAW,EAAE,MAAM;KACpB,CAAA;AACH,CAAC"}
|
package/dist/approvalHold.d.ts
CHANGED
|
@@ -12,12 +12,13 @@
|
|
|
12
12
|
* (`POST /api/v1/decisions`), which puts it in the review queue, notifies
|
|
13
13
|
* the workspace (`decision.pending`, Slack included), and gives the agent a
|
|
14
14
|
* hold id to quote.
|
|
15
|
-
* 3. An
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* `
|
|
19
|
-
*
|
|
20
|
-
*
|
|
15
|
+
* 3. An Owner, Admin or EM approves it (`intutic decision approve <holdId>`, the review
|
|
16
|
+
* API, or the Slack card — all one code path in the control plane). The
|
|
17
|
+
* approval lets the identical retry pass only while the workspace's
|
|
18
|
+
* review-hold bypass (`reviewHoldBypassEnabled`) is on: approving then
|
|
19
|
+
* writes the bypass step 1 finds, valid for `reviewHoldBypassTtlMinutes`.
|
|
20
|
+
* Otherwise the approval records the decision only, exactly as it does for
|
|
21
|
+
* a hook-gate hold.
|
|
21
22
|
*
|
|
22
23
|
* "Identical" is the bypass key: the rule id, `mcp__<server>__<tool>`
|
|
23
24
|
* lower-cased, and a SHA-256 of the arguments serialised with sorted keys, so
|
|
@@ -59,7 +60,7 @@ export declare class ApprovalHolds {
|
|
|
59
60
|
/** Rides on the hold record so the reviewer sees who asked (identity.ts). */
|
|
60
61
|
identity?: CallerIdentity | undefined);
|
|
61
62
|
/** Lets the call through on an approved bypass, or records a hold and returns its id. Never throws. */
|
|
62
|
-
request(rule: SopRule, toolName: string, toolInput: unknown): Promise<HoldOutcome>;
|
|
63
|
+
request(rule: Pick<SopRule, 'id' | 'reason'>, toolName: string, toolInput: unknown): Promise<HoldOutcome>;
|
|
63
64
|
private findBypass;
|
|
64
65
|
}
|
|
65
66
|
//# sourceMappingURL=approvalHold.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"approvalHold.d.ts","sourceRoot":"","sources":["../src/approvalHold.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"approvalHold.d.ts","sourceRoot":"","sources":["../src/approvalHold.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAKH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAOnD,MAAM,MAAM,WAAW,GACnB;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,GACvD;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,OAAO,CAAA;CAAE,CAAA;AAEvD,sFAAsF;AACtF,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CASpD;AAED,wBAAgB,OAAO,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,GAAG;IAAE,kBAAkB,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAKpI;AAgBD,qBAAa,aAAa;IAEtB,OAAO,CAAC,QAAQ,CAAC,eAAe;IAChC,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,WAAW;IAC5B,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,6EAA6E;IAC7E,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBALR,eAAe,EAAE,MAAM,EACvB,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM;IACnC,6EAA6E;IAC5D,QAAQ,GAAE,cAAc,GAAG,SAAqB;IAGnE,uGAAuG;IACjG,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,GAAG,QAAQ,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,GAAG,OAAO,CAAC,WAAW,CAAC;YAoCjG,UAAU;CA4BzB"}
|
package/dist/approvalHold.js
CHANGED
|
@@ -12,12 +12,13 @@
|
|
|
12
12
|
* (`POST /api/v1/decisions`), which puts it in the review queue, notifies
|
|
13
13
|
* the workspace (`decision.pending`, Slack included), and gives the agent a
|
|
14
14
|
* hold id to quote.
|
|
15
|
-
* 3. An
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* `
|
|
19
|
-
*
|
|
20
|
-
*
|
|
15
|
+
* 3. An Owner, Admin or EM approves it (`intutic decision approve <holdId>`, the review
|
|
16
|
+
* API, or the Slack card — all one code path in the control plane). The
|
|
17
|
+
* approval lets the identical retry pass only while the workspace's
|
|
18
|
+
* review-hold bypass (`reviewHoldBypassEnabled`) is on: approving then
|
|
19
|
+
* writes the bypass step 1 finds, valid for `reviewHoldBypassTtlMinutes`.
|
|
20
|
+
* Otherwise the approval records the decision only, exactly as it does for
|
|
21
|
+
* a hook-gate hold.
|
|
21
22
|
*
|
|
22
23
|
* "Identical" is the bypass key: the rule id, `mcp__<server>__<tool>`
|
|
23
24
|
* lower-cased, and a SHA-256 of the arguments serialised with sorted keys, so
|
package/dist/approvalHold.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"approvalHold.js","source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AAM,CAAC,CAAC,CAAC,EAAE;gBACxD,SAAS,EAAE,OAAO,GAAG,CAAC,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE;aAClE,CAAA;QACH,CAAC;QACD,OAAO,IAAI,CAAA;IACb,CAAC;CACF"}
|
package/dist/budget.d.ts
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* budget.ts — MCP call budgets, enforced before a call leaves the machine.
|
|
3
|
+
*
|
|
4
|
+
* The workspace's `mcpBudgets` setting (shared-types `mcpBudgets.ts`) limits
|
|
5
|
+
* how many tool calls go to a server, a tool, or come from a member, per hour
|
|
6
|
+
* or per day. Every proxy pointed at the same Valkey counts against the same
|
|
7
|
+
* counters, so a member's daily allowance is one allowance however many
|
|
8
|
+
* harness sessions and servers they run; proxies on different Valkeys count
|
|
9
|
+
* separately.
|
|
10
|
+
*
|
|
11
|
+
* One round trip per call that any budget covers, none for a call no budget
|
|
12
|
+
* covers. A Lua script checks every counter the call draws on and, only if
|
|
13
|
+
* none is used up, increments them all — atomically, so two proxies racing
|
|
14
|
+
* for the last call cannot both get it, and a refused call never consumes
|
|
15
|
+
* allowance. The same script claims the once-per-period alert flags (SET NX
|
|
16
|
+
* with the counter's lifetime, the dedup the LLM budget alerts use), so the
|
|
17
|
+
* warning and the exceeded notification go out once per budget per period
|
|
18
|
+
* whichever proxy crosses the line.
|
|
19
|
+
*
|
|
20
|
+
* Periods are fixed UTC windows (`budgetWindow`); the window start is part of
|
|
21
|
+
* every key, so a new hour or day starts from zero and old counters expire on
|
|
22
|
+
* their own. Each proxy reads its own clock: proxies whose clocks disagree by
|
|
23
|
+
* a few seconds disagree about the window for those seconds.
|
|
24
|
+
*
|
|
25
|
+
* When Valkey cannot answer — no URL configured, not connected, slower than
|
|
26
|
+
* the guard's timeout, or an error — the check is `unavailable`, and the
|
|
27
|
+
* interceptor applies the proxy's fail setting: fail-open lets the call
|
|
28
|
+
* through uncounted, fail-closed refuses it.
|
|
29
|
+
*
|
|
30
|
+
* @module
|
|
31
|
+
*/
|
|
32
|
+
import { type McpBudget, type McpBudgetPolicy } from '@intutic/shared-types';
|
|
33
|
+
import type { GuardedValkey } from './guardedValkey.js';
|
|
34
|
+
/**
|
|
35
|
+
* Counter keys. The workspace id is a hash tag (`{…}`), so every key one call
|
|
36
|
+
* touches lives in the same slot and the script stays valid on a cluster.
|
|
37
|
+
*/
|
|
38
|
+
export declare function budgetCounterKey(workspaceId: string, budgetId: string, windowStartMs: number, subject: string): string;
|
|
39
|
+
export interface BudgetCounter {
|
|
40
|
+
key: string;
|
|
41
|
+
limit: number;
|
|
42
|
+
warnAt: number;
|
|
43
|
+
ttlSecs: number;
|
|
44
|
+
}
|
|
45
|
+
export type CountOutcome = {
|
|
46
|
+
allowed: true;
|
|
47
|
+
used: number[];
|
|
48
|
+
warnClaimed: boolean[];
|
|
49
|
+
} | {
|
|
50
|
+
allowed: false;
|
|
51
|
+
index: number;
|
|
52
|
+
used: number;
|
|
53
|
+
exhaustedClaimed: boolean;
|
|
54
|
+
};
|
|
55
|
+
export interface BudgetStore {
|
|
56
|
+
/** Checks and counts one call against every counter; `undefined` when Valkey cannot answer. */
|
|
57
|
+
count(counters: readonly BudgetCounter[]): Promise<CountOutcome | undefined>;
|
|
58
|
+
}
|
|
59
|
+
export declare class ValkeyBudgetStore implements BudgetStore {
|
|
60
|
+
private readonly valkey;
|
|
61
|
+
constructor(valkey: GuardedValkey);
|
|
62
|
+
count(counters: readonly BudgetCounter[]): Promise<CountOutcome | undefined>;
|
|
63
|
+
/**
|
|
64
|
+
* The current counts of the given counters, without counting anything:
|
|
65
|
+
* what the `intutic` MCP server reports as used. A counter never written
|
|
66
|
+
* this period reads 0. `undefined` when Valkey cannot answer.
|
|
67
|
+
*/
|
|
68
|
+
used(keys: readonly string[]): Promise<number[] | undefined>;
|
|
69
|
+
}
|
|
70
|
+
/** A budget at a moment in its period: which allowance, how much of it is used, and when it resets. */
|
|
71
|
+
export interface BudgetStanding {
|
|
72
|
+
budget: McpBudget;
|
|
73
|
+
/** The member (or fallback caller) a per-member budget counted; empty for any other budget. */
|
|
74
|
+
subject: string;
|
|
75
|
+
used: number;
|
|
76
|
+
resetAt: Date;
|
|
77
|
+
}
|
|
78
|
+
export type BudgetVerdict =
|
|
79
|
+
/** No budget covers this call. */
|
|
80
|
+
{
|
|
81
|
+
kind: 'unlimited';
|
|
82
|
+
}
|
|
83
|
+
/** Counted. `warnings`: budgets this call took to their warning threshold first this period. */
|
|
84
|
+
| {
|
|
85
|
+
kind: 'allowed';
|
|
86
|
+
warnings: BudgetStanding[];
|
|
87
|
+
}
|
|
88
|
+
/** Refused: a budget is used up. `notify` is true for the first refusal of the period. */
|
|
89
|
+
| {
|
|
90
|
+
kind: 'exceeded';
|
|
91
|
+
standing: BudgetStanding;
|
|
92
|
+
notify: boolean;
|
|
93
|
+
}
|
|
94
|
+
/** Budgets cover this call, but Valkey could not answer. */
|
|
95
|
+
| {
|
|
96
|
+
kind: 'unavailable';
|
|
97
|
+
budgets: McpBudget[];
|
|
98
|
+
};
|
|
99
|
+
export declare class McpBudgetEnforcer {
|
|
100
|
+
/** `undefined` when the proxy has no Valkey configured: every covered call is then `unavailable`. */
|
|
101
|
+
private readonly store;
|
|
102
|
+
private readonly workspaceId;
|
|
103
|
+
private readonly serverName;
|
|
104
|
+
/** Who a per-member budget counts when the control plane has not named a member (identity.ts). */
|
|
105
|
+
private readonly fallbackCaller;
|
|
106
|
+
private readonly now;
|
|
107
|
+
constructor(
|
|
108
|
+
/** `undefined` when the proxy has no Valkey configured: every covered call is then `unavailable`. */
|
|
109
|
+
store: BudgetStore | undefined, workspaceId: string, serverName: string,
|
|
110
|
+
/** Who a per-member budget counts when the control plane has not named a member (identity.ts). */
|
|
111
|
+
fallbackCaller: string, now?: () => number);
|
|
112
|
+
check(policy: McpBudgetPolicy, toolName: string, memberId: string | null): Promise<BudgetVerdict>;
|
|
113
|
+
}
|
|
114
|
+
/** The refusal an agent reads: which budget, how much of it is used, and when it resets. */
|
|
115
|
+
export declare function exceededReason(s: BudgetStanding, nowMs?: number): string;
|
|
116
|
+
export declare function warningReason(s: BudgetStanding, warnAtPct: number): string;
|
|
117
|
+
export declare function unavailableReason(budgets: readonly McpBudget[]): string;
|
|
118
|
+
/** What a budget event tells the control plane, for its notification and finding. */
|
|
119
|
+
export interface BudgetEventDetail {
|
|
120
|
+
budgetId: string;
|
|
121
|
+
scope: McpBudget['scope'];
|
|
122
|
+
server?: string;
|
|
123
|
+
tool?: string;
|
|
124
|
+
memberId?: string;
|
|
125
|
+
/** Whose allowance ran out, for a per-member budget: the member, or the fallback caller. */
|
|
126
|
+
subject?: string;
|
|
127
|
+
period: McpBudget['period'];
|
|
128
|
+
limit: number;
|
|
129
|
+
used: number;
|
|
130
|
+
resetAt: string;
|
|
131
|
+
}
|
|
132
|
+
export declare function budgetEventDetail(s: BudgetStanding): BudgetEventDetail;
|
|
133
|
+
//# sourceMappingURL=budget.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"budget.d.ts","sourceRoot":"","sources":["../src/budget.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,OAAO,EAKL,KAAK,SAAS,EACd,KAAK,eAAe,EACrB,MAAM,uBAAuB,CAAA;AAC9B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAEvD;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAEtH;AAkCD,MAAM,WAAW,aAAa;IAC5B,GAAG,EAAE,MAAM,CAAA;IACX,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,MAAM,CAAA;CAChB;AA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