@intutic/shared-types 2.1.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.
Files changed (188) hide show
  1. package/dist/anomaly.d.ts +6 -10
  2. package/dist/anomaly.d.ts.map +1 -1
  3. package/dist/anomaly.js +0 -2
  4. package/dist/anomaly.js.map +1 -1
  5. package/dist/api-contracts.d.ts +1 -1
  6. package/dist/api-contracts.js +1 -1
  7. package/dist/attenuation.d.ts +1 -1
  8. package/dist/attenuation.js +1 -1
  9. package/dist/auth.d.ts +10 -9
  10. package/dist/auth.d.ts.map +1 -1
  11. package/dist/auth.js +3 -4
  12. package/dist/auth.js.map +1 -1
  13. package/dist/billing.d.ts +1 -1
  14. package/dist/billing.js +1 -1
  15. package/dist/destructiveSql.d.ts +48 -0
  16. package/dist/destructiveSql.d.ts.map +1 -0
  17. package/dist/destructiveSql.js +43 -0
  18. package/dist/destructiveSql.js.map +1 -0
  19. package/dist/devInventory.d.ts +120 -0
  20. package/dist/devInventory.d.ts.map +1 -0
  21. package/dist/devInventory.js +80 -0
  22. package/dist/devInventory.js.map +1 -0
  23. package/dist/enums.d.ts +18 -21
  24. package/dist/enums.d.ts.map +1 -1
  25. package/dist/enums.js +24 -28
  26. package/dist/enums.js.map +1 -1
  27. package/dist/errors.js +3 -3
  28. package/dist/errors.js.map +1 -1
  29. package/dist/finops.d.ts +14 -2
  30. package/dist/finops.d.ts.map +1 -1
  31. package/dist/finops.js +15 -1
  32. package/dist/finops.js.map +1 -1
  33. package/dist/gateDecisions.d.ts +18 -0
  34. package/dist/gateDecisions.d.ts.map +1 -0
  35. package/dist/gateDecisions.js +20 -0
  36. package/dist/gateDecisions.js.map +1 -0
  37. package/dist/gateIdentity.d.ts +23 -0
  38. package/dist/gateIdentity.d.ts.map +1 -0
  39. package/dist/gateIdentity.js +32 -0
  40. package/dist/gateIdentity.js.map +1 -0
  41. package/dist/gateKind.d.ts +172 -0
  42. package/dist/gateKind.d.ts.map +1 -0
  43. package/dist/gateKind.js +160 -0
  44. package/dist/gateKind.js.map +1 -0
  45. package/dist/gateLimits.d.ts +170 -0
  46. package/dist/gateLimits.d.ts.map +1 -0
  47. package/dist/gateLimits.js +96 -0
  48. package/dist/gateLimits.js.map +1 -0
  49. package/dist/gitRemote.d.ts +17 -0
  50. package/dist/gitRemote.d.ts.map +1 -0
  51. package/dist/gitRemote.js +71 -0
  52. package/dist/gitRemote.js.map +1 -0
  53. package/dist/governanceCoverage.d.ts +3 -3
  54. package/dist/governanceCoverage.js +3 -3
  55. package/dist/guardrailIr.d.ts +3 -3
  56. package/dist/guardrailIr.d.ts.map +1 -1
  57. package/dist/guardrailIr.js +3 -3
  58. package/dist/guardrailIr.js.map +1 -1
  59. package/dist/guardrailRender.d.ts +1 -1
  60. package/dist/guardrailRender.js +1 -1
  61. package/dist/harnessRules.d.ts +74 -0
  62. package/dist/harnessRules.d.ts.map +1 -0
  63. package/dist/harnessRules.js +142 -0
  64. package/dist/harnessRules.js.map +1 -0
  65. package/dist/holdMessages.d.ts +25 -0
  66. package/dist/holdMessages.d.ts.map +1 -0
  67. package/dist/holdMessages.js +34 -0
  68. package/dist/holdMessages.js.map +1 -0
  69. package/dist/identity.d.ts +1 -1
  70. package/dist/identity.js +2 -2
  71. package/dist/identity.js.map +1 -1
  72. package/dist/index.d.ts +36 -6
  73. package/dist/index.d.ts.map +1 -1
  74. package/dist/index.js +141 -10
  75. package/dist/index.js.map +1 -1
  76. package/dist/intelligence.d.ts +1 -2
  77. package/dist/intelligence.d.ts.map +1 -1
  78. package/dist/intelligence.js.map +1 -1
  79. package/dist/mcpBudgets.d.ts +191 -0
  80. package/dist/mcpBudgets.d.ts.map +1 -0
  81. package/dist/mcpBudgets.js +144 -0
  82. package/dist/mcpBudgets.js.map +1 -0
  83. package/dist/mcpRegistryRecord.d.ts +143 -0
  84. package/dist/mcpRegistryRecord.d.ts.map +1 -0
  85. package/dist/mcpRegistryRecord.js +229 -0
  86. package/dist/mcpRegistryRecord.js.map +1 -0
  87. package/dist/mcpToolRisk.d.ts +82 -0
  88. package/dist/mcpToolRisk.d.ts.map +1 -0
  89. package/dist/mcpToolRisk.js +334 -0
  90. package/dist/mcpToolRisk.js.map +1 -0
  91. package/dist/modelCatalog.d.ts +2 -2
  92. package/dist/modelCatalog.generated.js +1 -1
  93. package/dist/modelCatalog.generated.js.map +1 -1
  94. package/dist/modelCatalog.js +2 -2
  95. package/dist/notifications.d.ts +20 -130
  96. package/dist/notifications.d.ts.map +1 -1
  97. package/dist/notifications.js +241 -1
  98. package/dist/notifications.js.map +1 -1
  99. package/dist/phrases.d.ts +87 -0
  100. package/dist/phrases.d.ts.map +1 -0
  101. package/dist/phrases.js +241 -0
  102. package/dist/phrases.js.map +1 -0
  103. package/dist/piiDetectors.d.ts +97 -0
  104. package/dist/piiDetectors.d.ts.map +1 -0
  105. package/dist/piiDetectors.js +96 -0
  106. package/dist/piiDetectors.js.map +1 -0
  107. package/dist/piiDetectors.json +71 -0
  108. package/dist/policy.d.ts +1 -1
  109. package/dist/policy.js +1 -1
  110. package/dist/policyGuardrails.d.ts +127 -10
  111. package/dist/policyGuardrails.d.ts.map +1 -1
  112. package/dist/policyGuardrails.js +59 -6
  113. package/dist/policyGuardrails.js.map +1 -1
  114. package/dist/posturePresets.js +1 -1
  115. package/dist/posturePresets.js.map +1 -1
  116. package/dist/providerVerification.d.ts +2 -2
  117. package/dist/providerVerification.js +2 -2
  118. package/dist/providers.d.ts +4 -4
  119. package/dist/providers.d.ts.map +1 -1
  120. package/dist/providers.js +11 -6
  121. package/dist/providers.js.map +1 -1
  122. package/dist/regoBuiltins.d.ts +42 -0
  123. package/dist/regoBuiltins.d.ts.map +1 -0
  124. package/dist/regoBuiltins.js +732 -0
  125. package/dist/regoBuiltins.js.map +1 -0
  126. package/dist/regoRules.d.ts +105 -0
  127. package/dist/regoRules.d.ts.map +1 -0
  128. package/dist/regoRules.js +407 -0
  129. package/dist/regoRules.js.map +1 -0
  130. package/dist/ruleLoadFailures.d.ts +15 -0
  131. package/dist/ruleLoadFailures.d.ts.map +1 -0
  132. package/dist/ruleLoadFailures.js +26 -0
  133. package/dist/ruleLoadFailures.js.map +1 -0
  134. package/dist/scriptScan.d.ts +5 -5
  135. package/dist/scriptScan.js +3 -3
  136. package/dist/sequence.d.ts +52 -0
  137. package/dist/sequence.d.ts.map +1 -0
  138. package/dist/sequence.js +127 -0
  139. package/dist/sequence.js.map +1 -0
  140. package/dist/session.d.ts +1 -1
  141. package/dist/session.js +1 -1
  142. package/dist/skillScan.d.ts +3 -3
  143. package/dist/skillScan.d.ts.map +1 -1
  144. package/dist/skillScan.js +26 -4
  145. package/dist/skillScan.js.map +1 -1
  146. package/dist/sop.d.ts +24 -11
  147. package/dist/sop.d.ts.map +1 -1
  148. package/dist/sop.js +10 -9
  149. package/dist/sop.js.map +1 -1
  150. package/dist/sourceProviders.d.ts +1 -8
  151. package/dist/sourceProviders.d.ts.map +1 -1
  152. package/dist/sourceProviders.js +2 -9
  153. package/dist/sourceProviders.js.map +1 -1
  154. package/dist/ssoGroupClearance.d.ts +119 -0
  155. package/dist/ssoGroupClearance.d.ts.map +1 -0
  156. package/dist/ssoGroupClearance.js +196 -0
  157. package/dist/ssoGroupClearance.js.map +1 -0
  158. package/dist/sync.d.ts +42 -14
  159. package/dist/sync.d.ts.map +1 -1
  160. package/dist/sync.js +3 -3
  161. package/dist/sync.js.map +1 -1
  162. package/dist/taskManagement.d.ts +0 -2
  163. package/dist/taskManagement.d.ts.map +1 -1
  164. package/dist/taskManagement.js +0 -2
  165. package/dist/taskManagement.js.map +1 -1
  166. package/dist/toolPoison.d.ts +33 -0
  167. package/dist/toolPoison.d.ts.map +1 -0
  168. package/dist/toolPoison.js +85 -0
  169. package/dist/toolPoison.js.map +1 -0
  170. package/dist/usage.d.ts +186 -0
  171. package/dist/usage.d.ts.map +1 -1
  172. package/dist/wasmBinary.d.ts +25 -0
  173. package/dist/wasmBinary.d.ts.map +1 -0
  174. package/dist/wasmBinary.js +111 -0
  175. package/dist/wasmBinary.js.map +1 -0
  176. package/dist/wasmFuel.d.ts +52 -0
  177. package/dist/wasmFuel.d.ts.map +1 -0
  178. package/dist/wasmFuel.js +320 -0
  179. package/dist/wasmFuel.js.map +1 -0
  180. package/dist/wasmMemoryCap.d.ts +21 -0
  181. package/dist/wasmMemoryCap.d.ts.map +1 -0
  182. package/dist/wasmMemoryCap.js +58 -0
  183. package/dist/wasmMemoryCap.js.map +1 -0
  184. package/dist/workspaceSettings.d.ts +126 -17
  185. package/dist/workspaceSettings.d.ts.map +1 -1
  186. package/dist/workspaceSettings.js +21 -2
  187. package/dist/workspaceSettings.js.map +1 -1
  188. package/package.json +2 -2
@@ -0,0 +1,191 @@
1
+ /**
2
+ * MCP call budgets — how many MCP tool calls a workspace allows per hour or
3
+ * per day, per server, per member, per tool, or per member on one server.
4
+ *
5
+ * An MCP tool call has no price of its own: the protocol's `tools/call` result
6
+ * carries content, structured content, an error flag and `_meta`, and nothing
7
+ * that reports cost (the only cost-shaped field in the specification,
8
+ * `costPriority`, is a client's model preference for sampling). So a budget
9
+ * counts calls.
10
+ *
11
+ * The workspace setting `mcpBudgets` holds the budgets. The control plane
12
+ * validates it with {@link McpBudgetSettingsSchema} when an owner or admin
13
+ * writes it, delivers it to every MCP proxy with the rest of the MCP policy,
14
+ * and the proxy reads it with {@link parseMcpBudgetPolicy} and enforces it
15
+ * against counters in Valkey before each call
16
+ * (`packages/mcp-proxy/src/budget.ts`).
17
+ *
18
+ * @module
19
+ */
20
+ import { z } from 'zod';
21
+ /**
22
+ * What a budget counts:
23
+ * - `server` every call to one server;
24
+ * - `tool` every call to one tool on one server;
25
+ * - `member` each member's calls across every server;
26
+ * - `member_server` each member's calls to one server.
27
+ *
28
+ * A `member` or `member_server` budget names one member, or none to give
29
+ * every member their own allowance of the same size.
30
+ */
31
+ export type McpBudgetScope = 'server' | 'tool' | 'member' | 'member_server';
32
+ /** A budget's period. Periods are fixed UTC windows: an hour starts on the hour, a day at 00:00 UTC. */
33
+ export type McpBudgetPeriod = 'hour' | 'day';
34
+ export interface McpBudget {
35
+ /** Stable id, so a counter survives an edit to the limit. Named in refusals and alerts. */
36
+ id: string;
37
+ scope: McpBudgetScope;
38
+ /** The server, for `server`, `tool` and `member_server`. */
39
+ server?: string;
40
+ /** The tool, for `tool`. */
41
+ tool?: string;
42
+ /** One member, for `member` and `member_server`; absent means each member separately. */
43
+ memberId?: string;
44
+ period: McpBudgetPeriod;
45
+ /** Calls allowed per period. */
46
+ limit: number;
47
+ }
48
+ export interface McpBudgetPolicy {
49
+ budgets: McpBudget[];
50
+ /** A budget warns once per period when its calls reach this percentage of the limit. */
51
+ warnAtPct: number;
52
+ }
53
+ /** The LLM budget alert's default threshold, used here too so both kinds of budget warn alike. */
54
+ export declare const MCP_BUDGET_DEFAULT_WARN_PCT = 80;
55
+ export declare const MAX_MCP_BUDGETS = 200;
56
+ export declare const MAX_MCP_BUDGET_LIMIT = 1000000;
57
+ export declare const MCP_BUDGET_SCOPES: readonly McpBudgetScope[];
58
+ export declare const MCP_BUDGET_PERIODS: readonly McpBudgetPeriod[];
59
+ /**
60
+ * The `mcpBudgets` workspace setting as an owner or admin writes it. Budget
61
+ * ids are unique within a workspace: the id is part of the counter's key.
62
+ */
63
+ export declare const McpBudgetSettingsSchema: z.ZodEffects<z.ZodObject<{
64
+ budgets: z.ZodArray<z.ZodEffects<z.ZodObject<{
65
+ id: z.ZodString;
66
+ scope: z.ZodEnum<["server", "tool", "member", "member_server"]>;
67
+ server: z.ZodOptional<z.ZodString>;
68
+ tool: z.ZodOptional<z.ZodString>;
69
+ memberId: z.ZodOptional<z.ZodString>;
70
+ period: z.ZodEnum<["hour", "day"]>;
71
+ limit: z.ZodNumber;
72
+ }, "strict", z.ZodTypeAny, {
73
+ limit: number;
74
+ scope: "server" | "tool" | "member" | "member_server";
75
+ id: string;
76
+ period: "hour" | "day";
77
+ server?: string | undefined;
78
+ tool?: string | undefined;
79
+ memberId?: string | undefined;
80
+ }, {
81
+ limit: number;
82
+ scope: "server" | "tool" | "member" | "member_server";
83
+ id: string;
84
+ period: "hour" | "day";
85
+ server?: string | undefined;
86
+ tool?: string | undefined;
87
+ memberId?: string | undefined;
88
+ }>, {
89
+ limit: number;
90
+ scope: "server" | "tool" | "member" | "member_server";
91
+ id: string;
92
+ period: "hour" | "day";
93
+ server?: string | undefined;
94
+ tool?: string | undefined;
95
+ memberId?: string | undefined;
96
+ }, {
97
+ limit: number;
98
+ scope: "server" | "tool" | "member" | "member_server";
99
+ id: string;
100
+ period: "hour" | "day";
101
+ server?: string | undefined;
102
+ tool?: string | undefined;
103
+ memberId?: string | undefined;
104
+ }>, "many">;
105
+ warnAtPct: z.ZodOptional<z.ZodNumber>;
106
+ }, "strict", z.ZodTypeAny, {
107
+ budgets: {
108
+ limit: number;
109
+ scope: "server" | "tool" | "member" | "member_server";
110
+ id: string;
111
+ period: "hour" | "day";
112
+ server?: string | undefined;
113
+ tool?: string | undefined;
114
+ memberId?: string | undefined;
115
+ }[];
116
+ warnAtPct?: number | undefined;
117
+ }, {
118
+ budgets: {
119
+ limit: number;
120
+ scope: "server" | "tool" | "member" | "member_server";
121
+ id: string;
122
+ period: "hour" | "day";
123
+ server?: string | undefined;
124
+ tool?: string | undefined;
125
+ memberId?: string | undefined;
126
+ }[];
127
+ warnAtPct?: number | undefined;
128
+ }>, {
129
+ budgets: {
130
+ limit: number;
131
+ scope: "server" | "tool" | "member" | "member_server";
132
+ id: string;
133
+ period: "hour" | "day";
134
+ server?: string | undefined;
135
+ tool?: string | undefined;
136
+ memberId?: string | undefined;
137
+ }[];
138
+ warnAtPct?: number | undefined;
139
+ }, {
140
+ budgets: {
141
+ limit: number;
142
+ scope: "server" | "tool" | "member" | "member_server";
143
+ id: string;
144
+ period: "hour" | "day";
145
+ server?: string | undefined;
146
+ tool?: string | undefined;
147
+ memberId?: string | undefined;
148
+ }[];
149
+ warnAtPct?: number | undefined;
150
+ }>;
151
+ export type McpBudgetSettings = z.infer<typeof McpBudgetSettingsSchema>;
152
+ /**
153
+ * Reads `mcpBudgets` as the control plane delivered it. Every budget is
154
+ * checked on its own and a malformed one is dropped, so one bad entry never
155
+ * lifts the others; anything that is not a settings object reads as no
156
+ * budgets at all.
157
+ */
158
+ export declare function parseMcpBudgetPolicy(value: unknown): McpBudgetPolicy;
159
+ /** One tool call, as far as budgets are concerned. */
160
+ export interface McpBudgetCall {
161
+ server: string;
162
+ tool: string;
163
+ /** The member the proxy's API key resolves to, when the control plane said. */
164
+ memberId: string | null;
165
+ /**
166
+ * Who to count a per-member budget against when no member is known — the
167
+ * API key's prefix, say. Callers nobody can identify share one allowance.
168
+ */
169
+ fallbackCaller: string;
170
+ }
171
+ /** A budget that applies to a call, and whose allowance the call draws on. */
172
+ export interface McpBudgetCharge {
173
+ budget: McpBudget;
174
+ /** Distinguishes allowances within one budget: the member, for an each-member budget. */
175
+ subject: string;
176
+ }
177
+ /**
178
+ * The budgets a call counts against, in the order they were configured. A
179
+ * call draws on every one of them, and is refused when any is used up.
180
+ */
181
+ export declare function budgetsForCall(policy: McpBudgetPolicy, call: McpBudgetCall): McpBudgetCharge[];
182
+ /** The fixed window a moment falls in: when it began and when it resets. */
183
+ export declare function budgetWindow(period: McpBudgetPeriod, nowMs: number): {
184
+ startMs: number;
185
+ resetAtMs: number;
186
+ };
187
+ /** The call count at which a budget warns: `warnAtPct` of the limit, rounded up, at least one call. */
188
+ export declare function budgetWarnAt(limit: number, warnAtPct: number): number;
189
+ /** A budget in words, for refusals, alerts and the dashboard: what it counts, and how many per period. */
190
+ export declare function describeMcpBudget(budget: McpBudget, memberLabel?: string): string;
191
+ //# sourceMappingURL=mcpBudgets.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcpBudgets.d.ts","sourceRoot":"","sources":["../src/mcpBudgets.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,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IAC5B,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,MAAM,CAAA;IACZ,+EAA+E;IAC/E,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;IACvB;;;OAGG;IACH,cAAc,EAAE,MAAM,CAAA;CACvB;AAED,8EAA8E;AAC9E,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,SAAS,CAAA;IACjB,yFAAyF;IACzF,OAAO,EAAE,MAAM,CAAA;CAChB;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,eAAe,EAAE,IAAI,EAAE,aAAa,GAAG,eAAe,EAAE,CAW9F;AAED,4EAA4E;AAC5E,wBAAgB,YAAY,CAAC,MAAM,EAAE,eAAe,EAAE,KAAK,EAAE,MAAM,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAI3G;AAED,uGAAuG;AACvG,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAErE;AAED,0GAA0G;AAC1G,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,SAAS,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,CAWjF"}
@@ -0,0 +1,144 @@
1
+ "use strict";
2
+ /**
3
+ * MCP call budgets — how many MCP tool calls a workspace allows per hour or
4
+ * per day, per server, per member, per tool, or per member on one server.
5
+ *
6
+ * An MCP tool call has no price of its own: the protocol's `tools/call` result
7
+ * carries content, structured content, an error flag and `_meta`, and nothing
8
+ * that reports cost (the only cost-shaped field in the specification,
9
+ * `costPriority`, is a client's model preference for sampling). So a budget
10
+ * counts calls.
11
+ *
12
+ * The workspace setting `mcpBudgets` holds the budgets. The control plane
13
+ * validates it with {@link McpBudgetSettingsSchema} when an owner or admin
14
+ * writes it, delivers it to every MCP proxy with the rest of the MCP policy,
15
+ * and the proxy reads it with {@link parseMcpBudgetPolicy} and enforces it
16
+ * against counters in Valkey before each call
17
+ * (`packages/mcp-proxy/src/budget.ts`).
18
+ *
19
+ * @module
20
+ */
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.McpBudgetSettingsSchema = exports.MCP_BUDGET_PERIODS = exports.MCP_BUDGET_SCOPES = exports.MAX_MCP_BUDGET_LIMIT = exports.MAX_MCP_BUDGETS = exports.MCP_BUDGET_DEFAULT_WARN_PCT = void 0;
23
+ exports.parseMcpBudgetPolicy = parseMcpBudgetPolicy;
24
+ exports.budgetsForCall = budgetsForCall;
25
+ exports.budgetWindow = budgetWindow;
26
+ exports.budgetWarnAt = budgetWarnAt;
27
+ exports.describeMcpBudget = describeMcpBudget;
28
+ const zod_1 = require("zod");
29
+ /** The LLM budget alert's default threshold, used here too so both kinds of budget warn alike. */
30
+ exports.MCP_BUDGET_DEFAULT_WARN_PCT = 80;
31
+ exports.MAX_MCP_BUDGETS = 200;
32
+ exports.MAX_MCP_BUDGET_LIMIT = 1_000_000;
33
+ exports.MCP_BUDGET_SCOPES = ['server', 'tool', 'member', 'member_server'];
34
+ exports.MCP_BUDGET_PERIODS = ['hour', 'day'];
35
+ const PERIOD_MS = { hour: 3_600_000, day: 86_400_000 };
36
+ const BudgetSchema = zod_1.z
37
+ .object({
38
+ id: zod_1.z.string().regex(/^[A-Za-z0-9_-]{1,40}$/, 'letters, digits, - and _, at most 40'),
39
+ scope: zod_1.z.enum(['server', 'tool', 'member', 'member_server']),
40
+ server: zod_1.z.string().min(1).max(256).optional(),
41
+ tool: zod_1.z.string().min(1).max(256).optional(),
42
+ memberId: zod_1.z.string().min(1).max(64).optional(),
43
+ period: zod_1.z.enum(['hour', 'day']),
44
+ limit: zod_1.z.number().int().min(1).max(exports.MAX_MCP_BUDGET_LIMIT),
45
+ })
46
+ .strict()
47
+ .superRefine((b, ctx) => {
48
+ const needsServer = b.scope !== 'member';
49
+ if (needsServer && !b.server)
50
+ ctx.addIssue({ code: 'custom', path: ['server'], message: `a ${b.scope} budget names a server` });
51
+ if (!needsServer && b.server)
52
+ ctx.addIssue({ code: 'custom', path: ['server'], message: 'a member budget covers every server' });
53
+ if (b.scope === 'tool' && !b.tool)
54
+ ctx.addIssue({ code: 'custom', path: ['tool'], message: 'a tool budget names a tool' });
55
+ if (b.scope !== 'tool' && b.tool)
56
+ ctx.addIssue({ code: 'custom', path: ['tool'], message: 'only a tool budget names a tool' });
57
+ const perMember = b.scope === 'member' || b.scope === 'member_server';
58
+ if (!perMember && b.memberId)
59
+ ctx.addIssue({ code: 'custom', path: ['memberId'], message: 'only a member budget names a member' });
60
+ });
61
+ /**
62
+ * The `mcpBudgets` workspace setting as an owner or admin writes it. Budget
63
+ * ids are unique within a workspace: the id is part of the counter's key.
64
+ */
65
+ exports.McpBudgetSettingsSchema = zod_1.z
66
+ .object({
67
+ budgets: zod_1.z.array(BudgetSchema).max(exports.MAX_MCP_BUDGETS),
68
+ warnAtPct: zod_1.z.number().int().min(1).max(99).optional(),
69
+ })
70
+ .strict()
71
+ .superRefine((s, ctx) => {
72
+ const seen = new Set();
73
+ s.budgets.forEach((b, i) => {
74
+ if (seen.has(b.id))
75
+ ctx.addIssue({ code: 'custom', path: ['budgets', i, 'id'], message: `duplicate budget id "${b.id}"` });
76
+ seen.add(b.id);
77
+ });
78
+ });
79
+ /**
80
+ * Reads `mcpBudgets` as the control plane delivered it. Every budget is
81
+ * checked on its own and a malformed one is dropped, so one bad entry never
82
+ * lifts the others; anything that is not a settings object reads as no
83
+ * budgets at all.
84
+ */
85
+ function parseMcpBudgetPolicy(value) {
86
+ const empty = { budgets: [], warnAtPct: exports.MCP_BUDGET_DEFAULT_WARN_PCT };
87
+ if (typeof value !== 'object' || value === null || Array.isArray(value))
88
+ return empty;
89
+ const raw = value;
90
+ const budgets = [];
91
+ const seen = new Set();
92
+ for (const entry of Array.isArray(raw['budgets']) ? raw['budgets'] : []) {
93
+ const parsed = BudgetSchema.safeParse(entry);
94
+ if (!parsed.success || seen.has(parsed.data.id))
95
+ continue;
96
+ seen.add(parsed.data.id);
97
+ budgets.push(parsed.data);
98
+ }
99
+ const pct = raw['warnAtPct'];
100
+ const warnAtPct = typeof pct === 'number' && Number.isInteger(pct) && pct >= 1 && pct <= 99 ? pct : exports.MCP_BUDGET_DEFAULT_WARN_PCT;
101
+ return { budgets, warnAtPct };
102
+ }
103
+ /**
104
+ * The budgets a call counts against, in the order they were configured. A
105
+ * call draws on every one of them, and is refused when any is used up.
106
+ */
107
+ function budgetsForCall(policy, call) {
108
+ const caller = call.memberId ?? call.fallbackCaller;
109
+ const charges = [];
110
+ for (const budget of policy.budgets) {
111
+ if (budget.server !== undefined && budget.server !== call.server)
112
+ continue;
113
+ if (budget.tool !== undefined && budget.tool !== call.tool)
114
+ continue;
115
+ if (budget.memberId !== undefined && budget.memberId !== call.memberId)
116
+ continue;
117
+ const perMember = budget.scope === 'member' || budget.scope === 'member_server';
118
+ charges.push({ budget, subject: perMember ? caller : '' });
119
+ }
120
+ return charges;
121
+ }
122
+ /** The fixed window a moment falls in: when it began and when it resets. */
123
+ function budgetWindow(period, nowMs) {
124
+ const size = PERIOD_MS[period];
125
+ const startMs = Math.floor(nowMs / size) * size;
126
+ return { startMs, resetAtMs: startMs + size };
127
+ }
128
+ /** The call count at which a budget warns: `warnAtPct` of the limit, rounded up, at least one call. */
129
+ function budgetWarnAt(limit, warnAtPct) {
130
+ return Math.max(1, Math.ceil((limit * warnAtPct) / 100));
131
+ }
132
+ /** A budget in words, for refusals, alerts and the dashboard: what it counts, and how many per period. */
133
+ function describeMcpBudget(budget, memberLabel) {
134
+ const who = budget.memberId ? (memberLabel ?? `member ${budget.memberId}`) : 'each member';
135
+ const what = budget.scope === 'server'
136
+ ? `calls to ${budget.server}`
137
+ : budget.scope === 'tool'
138
+ ? `calls to ${budget.server} › ${budget.tool}`
139
+ : budget.scope === 'member'
140
+ ? `MCP calls by ${who}`
141
+ : `calls to ${budget.server} by ${who}`;
142
+ return `${what}: ${budget.limit} per ${budget.period}`;
143
+ }
144
+ //# sourceMappingUR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AC,CAAC,CAAC,CAAC,WAAW,IAAI,UAAU,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,CAAC,aAAa,CAAA;IAC1F,MAAM,IAAI,GACR,MAAM,CAAC,KAAK,KAAK,QAAQ;QACvB,CAAC,CAAC,YAAY,MAAM,CAAC,MAAM,EAAE;QAC7B,CAAC,CAAC,MAAM,CAAC,KAAK,KAAK,MAAM;YACvB,CAAC,CAAC,YAAY,MAAM,CAAC,MAAM,MAAM,MAAM,CAAC,IAAI,EAAE;YAC9C,CAAC,CAAC,MAAM,CAAC,KAAK,KAAK,QAAQ;gBACzB,CAAC,CAAC,gBAAgB,GAAG,EAAE;gBACvB,CAAC,CAAC,YAAY,MAAM,CAAC,MAAM,OAAO,GAAG,EAAE,CAAA;IAC/C,OAAO,GAAG,IAAI,KAAK,MAAM,CAAC,KAAK,QAAQ,MAAM,CAAC,MAAM,EAAE,CAAA;AACxD,CAAC"}
@@ -0,0 +1,143 @@
1
+ /**
2
+ * The workspace's MCP server registry decisions, as the gates apply them.
3
+ *
4
+ * An owner or admin approves or blocks each MCP server on the MCP Servers
5
+ * page, disables tools within one, and sets what happens to a server nobody
6
+ * has decided on (`mcpDefaultPolicy`); a high-risk tool-set change can send a
7
+ * server back to the queue. The control plane serves those decisions as
8
+ * `mcpRegistry` on `GET /api/v1/policy/resolve`. The MCP proxy applies them to
9
+ * the servers it fronts; the sync daemon writes them into the policy snapshot
10
+ * as an `@mcp_registry` record so the harness hook gates apply them to every
11
+ * `mcp__<server>__<tool>` call, the servers no proxy fronts included.
12
+ *
13
+ * {@link evaluateMcpRegistry} is the one decision. The MCP proxy and the
14
+ * control plane's hook gate call it, the JavaScript hook gates embed its
15
+ * source ({@link MCP_REGISTRY_JS_SOURCE}), `@intutic/gate` carries a
16
+ * byte-identical copy of this file, and the bash gates and `intutic-clawde`
17
+ * run its Python transliteration (`intutic_clawde/gate/mcp_registry.py`);
18
+ * `fixtures/mcp-registry-vectors.json` holds all of them to the same codes,
19
+ * rule ids and reasons.
20
+ *
21
+ * The workspace's `mcpAllowedServers` list rides beside it as an
22
+ * `@mcp_allowlist` record ({@link evaluateMcpAllowlist}). Both records sit
23
+ * inside the snapshot's digest, and a gate that finds the snapshot unverified
24
+ * (its digest broken or missing, or another workspace's) trusts neither: it
25
+ * refuses every MCP call with {@link mcpSnapshotUnverifiedRefusal}, at `block`
26
+ * even in an observe-only workspace. An edit that widens either record, or
27
+ * deletes one, therefore admits nothing. A policy activates only when it
28
+ * verifies; the sync daemon restores the last snapshot it verified.
29
+ *
30
+ * Self-contained (no imports) so `@intutic/gate`, which has no workspace
31
+ * dependencies, can carry the copy.
32
+ *
33
+ * @module
34
+ */
35
+ /** What the registry decides, per workspace. The MCP proxy's `McpRegistryPolicy` has the same shape. */
36
+ export interface McpRegistryRecord {
37
+ defaultPolicy: 'allow' | 'deny';
38
+ approvedServers: string[];
39
+ blockedServers: string[];
40
+ /** Servers a high-risk tool change returned to the approval queue; refused under either default. */
41
+ heldServers: string[];
42
+ /** Server name → tool names disabled within it. */
43
+ disabledTools: Record<string, string[]>;
44
+ }
45
+ /** A registry refusal: the code every MCP surface uses, the deciding rule, and why. */
46
+ export interface McpRegistryRefusal {
47
+ code: 'SERVER_BLOCKED' | 'SERVER_HELD' | 'SERVER_NOT_APPROVED' | 'TOOL_DISABLED';
48
+ ruleId: string;
49
+ reason: string;
50
+ }
51
+ /**
52
+ * Decides one MCP tool call against the registry: a blocked server, then a
53
+ * held one, then — under `deny` — one not approved, then a disabled tool.
54
+ * Null lets the call continue.
55
+ *
56
+ * Self-contained (no imports, no module state) because the JavaScript hook
57
+ * gates run it as emitted source.
58
+ */
59
+ export declare function evaluateMcpRegistry(registry: McpRegistryRecord, serverName: string, toolName: string): McpRegistryRefusal | null;
60
+ /** {@link evaluateMcpRegistry} as source, for the JavaScript hook gates. */
61
+ export declare const MCP_REGISTRY_JS_SOURCE: string;
62
+ /**
63
+ * Reads `mcpRegistry` as the control plane sends it. Null for anything that is
64
+ * not a registry object; wrong-typed lists read as empty, and any default but
65
+ * `deny` reads as `allow`, the control plane's own reading of the setting.
66
+ */
67
+ export declare function parseMcpRegistryRecord(value: unknown): McpRegistryRecord | null;
68
+ /** Whether a registry refuses nothing: no snapshot record is written for one. */
69
+ export declare function isUnrestrictedMcpRegistry(registry: McpRegistryRecord): boolean;
70
+ /**
71
+ * First column of the record's line in `policy-snapshot.rules`. A data line,
72
+ * like `@sso_groups`, so the digest every gate recomputes covers it; two
73
+ * columns, so every rule parser (which needs six) skips it.
74
+ */
75
+ export declare const MCP_REGISTRY_RECORD_TAG = "@mcp_registry";
76
+ /** The record as one `.rules` line: the tag, a tab, base64 of its JSON. */
77
+ export declare function encodeMcpRegistryRecord(registry: McpRegistryRecord): string;
78
+ /** Reads a record line back; null for any other line or a damaged one. */
79
+ export declare function decodeMcpRegistryRecord(line: string): McpRegistryRecord | null;
80
+ /**
81
+ * The workspace's `mcpAllowedServers` list as the gates apply it: only the
82
+ * listed servers may be called, and under `shadow` (an observe-only
83
+ * workspace) a call to another is recorded instead of refused. A workspace
84
+ * with no list has no record.
85
+ */
86
+ export interface McpAllowlistRecord {
87
+ severity: 'block' | 'shadow';
88
+ servers: string[];
89
+ }
90
+ /** An allowlist refusal, shaped like {@link McpRegistryRefusal}. */
91
+ export interface McpAllowlistRefusal {
92
+ code: 'SERVER_NOT_ALLOWED';
93
+ ruleId: 'mcp_allowlist';
94
+ reason: string;
95
+ }
96
+ /**
97
+ * Decides one MCP call's server against the allowlist. Null lets the call
98
+ * continue; a refusal under `shadow` is recorded, not enforced, by the caller.
99
+ *
100
+ * Self-contained, like {@link evaluateMcpRegistry}, because the JavaScript
101
+ * hook gates run it as emitted source.
102
+ */
103
+ export declare function evaluateMcpAllowlist(allowlist: McpAllowlistRecord, serverName: string): McpAllowlistRefusal | null;
104
+ /** {@link evaluateMcpAllowlist} as source, for the JavaScript hook gates. */
105
+ export declare const MCP_ALLOWLIST_JS_SOURCE: string;
106
+ /** The refusal of an MCP call on a snapshot that failed its integrity check. */
107
+ export interface McpSnapshotUnverifiedRefusal {
108
+ code: 'POLICY_SNAPSHOT_UNVERIFIED';
109
+ ruleId: 'policy_snapshot';
110
+ reason: string;
111
+ }
112
+ /**
113
+ * Refuses one MCP call because the policy snapshot failed its digest or
114
+ * workspace check. Neither the registry's approvals nor the allowlist's
115
+ * servers can be vouched for then, and a deleted record is indistinguishable
116
+ * from one the workspace never set, so the snapshot admits no MCP server at
117
+ * all. Every gate that reads the snapshot refuses with this, at `block`.
118
+ *
119
+ * Self-contained, like {@link evaluateMcpRegistry}, because the JavaScript
120
+ * hook gates run it as emitted source.
121
+ */
122
+ export declare function mcpSnapshotUnverifiedRefusal(serverName: string): McpSnapshotUnverifiedRefusal;
123
+ /** {@link mcpSnapshotUnverifiedRefusal} as source, for the JavaScript hook gates. */
124
+ export declare const MCP_SNAPSHOT_UNVERIFIED_JS_SOURCE: string;
125
+ /**
126
+ * First column of the allowlist's line in `policy-snapshot.rules`. A data
127
+ * line, so the digest covers it and a server added to the list by hand fails
128
+ * the check; three columns, so every rule parser skips it.
129
+ */
130
+ export declare const MCP_ALLOWLIST_RECORD_TAG = "@mcp_allowlist";
131
+ /**
132
+ * The allowlist as one `.rules` line: the tag, the severity and the server
133
+ * names joined by commas, tab-separated. Plain text, so the bash gates read
134
+ * it with parameter expansion; the snapshot writer drops a name holding
135
+ * whitespace or a comma.
136
+ */
137
+ export declare function encodeMcpAllowlistRecord(allowlist: McpAllowlistRecord): string;
138
+ /**
139
+ * Reads an allowlist line back; null for any other line. A severity other
140
+ * than `shadow` reads as `block`, so a damaged one refuses.
141
+ */
142
+ export declare function decodeMcpAllowlistRecord(line: string): McpAllowlistRecord | null;
143
+ //# sourceMappingURL=mcpRegistryRecord.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcpRegistryRecord.d.ts","sourceRoot":"","sources":["../src/mcpRegistryRecord.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;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