mcp-usage-control-mcp 1.0.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/dist/index.js ADDED
@@ -0,0 +1,525 @@
1
+ import { UsageDeniedError, UsageStateError, } from 'mcp-usage-control';
2
+ import { normalizeSettlementOutcome } from 'mcp-usage-control/settlement-outcomes';
3
+ /**
4
+ * Process-local flow store for tests and single-process servers.
5
+ *
6
+ * Instantiate it outside a `createMcpHandler` per-request factory. Distributed
7
+ * or horizontally scaled servers should provide a durable store with atomic
8
+ * compare-and-consume semantics instead.
9
+ */
10
+ export class MemoryMcpUsageFlowStore {
11
+ flows = new Map();
12
+ suspend(record) {
13
+ this.pruneExpired(Date.now());
14
+ validateFlowRecord(record);
15
+ if (this.flows.has(record.flowId)) {
16
+ throw new UsageStateError('MCP usage flow ID already exists');
17
+ }
18
+ this.flows.set(record.flowId, cloneFlowRecord(record));
19
+ }
20
+ consume(flowId, binding) {
21
+ const now = Date.now();
22
+ this.pruneExpired(now);
23
+ const record = this.flows.get(flowId);
24
+ if (!record || record.expiresAt <= now)
25
+ return undefined;
26
+ if (!sameBinding(record.binding, binding))
27
+ return undefined;
28
+ this.flows.delete(flowId);
29
+ return cloneFlowRecord(record);
30
+ }
31
+ pruneExpired(now) {
32
+ for (const [flowId, record] of this.flows) {
33
+ if (record.expiresAt <= now)
34
+ this.flows.delete(flowId);
35
+ }
36
+ }
37
+ }
38
+ export class UsageSettlementError extends Error {
39
+ settlementError;
40
+ executionError;
41
+ constructor(message, settlementError, executionError) {
42
+ super(message);
43
+ this.settlementError = settlementError;
44
+ this.executionError = executionError;
45
+ this.name = 'UsageSettlementError';
46
+ }
47
+ }
48
+ export class UsageClassificationError extends Error {
49
+ classificationError;
50
+ executionError;
51
+ constructor(message, classificationError, executionError) {
52
+ super(message);
53
+ this.classificationError = classificationError;
54
+ this.executionError = executionError;
55
+ this.name = 'UsageClassificationError';
56
+ }
57
+ }
58
+ export class UnsupportedMcpUsageFlowError extends Error {
59
+ constructor(message) {
60
+ super(message);
61
+ this.name = 'UnsupportedMcpUsageFlowError';
62
+ }
63
+ }
64
+ export class McpUsageResumeError extends Error {
65
+ constructor(message) {
66
+ super(message);
67
+ this.name = 'McpUsageResumeError';
68
+ }
69
+ }
70
+ export class McpUsageRoundsExceededError extends Error {
71
+ constructor(message) {
72
+ super(message);
73
+ this.name = 'McpUsageRoundsExceededError';
74
+ }
75
+ }
76
+ /**
77
+ * Wrap an MCP v2 single-round tool handler with usage admission and settlement.
78
+ *
79
+ * The lease is marked cost-liable immediately before the application handler is
80
+ * entered. If the process disappears after that point, expiry conservatively
81
+ * charges the full reservation instead of turning a crash into a refund.
82
+ *
83
+ * Error settlement is conservative by default: the full reservation is charged.
84
+ * Applications may return a lower amount only when they can prove the metered
85
+ * cost was not incurred. If a cost-classification hook throws or returns an
86
+ * invalid amount, the wrapper charges the full reservation before surfacing a
87
+ * UsageClassificationError.
88
+ *
89
+ * MCP `isError: true` results are classified as tool errors rather than success.
90
+ * MCP v2 `input_required` results remain rejected by this single-round wrapper;
91
+ * use `protectMultiRoundTool()` when suspend/resume is required.
92
+ */
93
+ export function protectTool(options, handler) {
94
+ const protectedHandler = async (argsOrCtx, maybeCtx) => {
95
+ const { args, ctx } = resolveInvocation(options.noInput === true, argsOrCtx, maybeCtx, 'protectTool');
96
+ const principal = await options.principal(ctx);
97
+ const operationId = await options.operationId(args, ctx);
98
+ const admission = await options.control.reserve({
99
+ operationId,
100
+ principal,
101
+ tool: options.tool,
102
+ args,
103
+ });
104
+ if (!admission.allowed) {
105
+ throw new UsageDeniedError(admission.reason);
106
+ }
107
+ const { lease } = admission;
108
+ await lease.markLiable();
109
+ const heartbeat = options.leaseHeartbeat === false ? noHeartbeat() : startLeaseHeartbeat(lease, options.onLeaseRenewalState);
110
+ let result;
111
+ try {
112
+ result = await handler(args, ctx);
113
+ }
114
+ catch (executionError) {
115
+ await heartbeat.stop();
116
+ const classified = await classifyUnits(options.errorUnits
117
+ ? () => options.errorUnits({ error: executionError, args, ctx, lease })
118
+ : undefined, lease.reservedUnits, lease);
119
+ await settleOnce(lease, classified.units, 'error', executionError);
120
+ if (classified.error !== undefined) {
121
+ throw new UsageClassificationError('Usage error-cost classification failed; full reservation was charged', classified.error, executionError);
122
+ }
123
+ throw executionError;
124
+ }
125
+ await heartbeat.stop();
126
+ if (isInputRequiredResult(result)) {
127
+ await settleOnce(lease, lease.reservedUnits, 'unsupported_input_required');
128
+ throw new UnsupportedMcpUsageFlowError('MCP input_required requires protectMultiRoundTool(); protectTool() is single-round only');
129
+ }
130
+ return settleCompletedResult(options, result, args, ctx, lease);
131
+ };
132
+ return protectedHandler;
133
+ }
134
+ /**
135
+ * Protect an MCP v2 `input_required` flow without reserving again on retries.
136
+ *
137
+ * The wrapper owns the wire `requestState`. The application handler may still
138
+ * return its own `requestState`; that string is kept only in trusted server-side
139
+ * flow storage and is exposed on the next entry as `flow.applicationRequestState`.
140
+ *
141
+ * On resume, `ctx.mcpReq.requestState<T>()` MUST already contain a decoded object
142
+ * produced by the MCP server's configured verification hook. If the server has
143
+ * no verifier, the SDK returns the raw string and this wrapper fails closed.
144
+ *
145
+ * A flow token is one-time: `flowStore.consume()` must atomically compare the
146
+ * principal/tool/args binding and consume it. Concurrent or replayed resume
147
+ * attempts therefore cannot execute the application handler twice. If a claimed
148
+ * process disappears before producing a next state or settlement, the liable
149
+ * usage lease eventually expires conservatively at its full reserved charge.
150
+ */
151
+ export function protectMultiRoundTool(options, handler) {
152
+ assertPositiveInteger(options.suspendTtlMs, 'suspendTtlMs');
153
+ const maxRounds = options.maxRounds ?? 8;
154
+ assertPositiveInteger(maxRounds, 'maxRounds');
155
+ const protectedHandler = async (argsOrCtx, maybeCtx) => {
156
+ const { args, ctx } = resolveInvocation(options.noInput === true, argsOrCtx, maybeCtx, 'protectMultiRoundTool');
157
+ const principal = await options.principal(ctx);
158
+ const argsHash = await hashArgs(args);
159
+ const binding = {
160
+ principalId: principal.id,
161
+ ...(principal.tenantId === undefined ? {} : { tenantId: principal.tenantId }),
162
+ tool: options.tool,
163
+ argsHash,
164
+ };
165
+ const decodedState = ctx.mcpReq.requestState();
166
+ let lease;
167
+ let round;
168
+ let operationId;
169
+ let applicationRequestState;
170
+ if (decodedState === undefined) {
171
+ operationId = await options.operationId(args, ctx);
172
+ const admission = await options.control.reserve({
173
+ operationId,
174
+ principal,
175
+ tool: options.tool,
176
+ args,
177
+ });
178
+ if (!admission.allowed)
179
+ throw new UsageDeniedError(admission.reason);
180
+ lease = admission.lease;
181
+ await lease.markLiable();
182
+ round = 0;
183
+ }
184
+ else {
185
+ if (!isMcpUsageRequestStatePayload(decodedState)) {
186
+ throw new McpUsageResumeError('MCP usage requestState was not a verified decoded resume payload');
187
+ }
188
+ const suspended = await options.flowStore.consume(decodedState.flowId, binding);
189
+ if (!suspended) {
190
+ throw new McpUsageResumeError('MCP usage resume state was missing, expired, replayed, or mismatched');
191
+ }
192
+ if (!sameBinding(suspended.binding, binding)) {
193
+ throw new McpUsageResumeError('MCP usage resume state failed its server-side binding check');
194
+ }
195
+ lease = options.control.resumeLease(suspended.lease);
196
+ operationId = lease.reservation.operationId;
197
+ round = suspended.round;
198
+ applicationRequestState = suspended.applicationRequestState;
199
+ // The UsageStore is authoritative. This renew proves the reservation still
200
+ // exists and extends it before application work resumes.
201
+ await lease.renew(options.suspendTtlMs);
202
+ }
203
+ const flowContext = {
204
+ round,
205
+ operationId,
206
+ ...(applicationRequestState === undefined ? {} : { applicationRequestState }),
207
+ };
208
+ const heartbeat = options.leaseHeartbeat === false ? noHeartbeat() : startLeaseHeartbeat(lease, options.onLeaseRenewalState);
209
+ let result;
210
+ try {
211
+ result = await handler(args, ctx, flowContext);
212
+ }
213
+ catch (executionError) {
214
+ await heartbeat.stop();
215
+ const classified = await classifyUnits(options.errorUnits
216
+ ? () => options.errorUnits({ error: executionError, args, ctx, lease })
217
+ : undefined, lease.reservedUnits, lease);
218
+ await settleOnce(lease, classified.units, 'error', executionError);
219
+ if (classified.error !== undefined) {
220
+ throw new UsageClassificationError('Usage error-cost classification failed; full reservation was charged', classified.error, executionError);
221
+ }
222
+ throw executionError;
223
+ }
224
+ await heartbeat.stop();
225
+ if (!isInputRequiredResult(result)) {
226
+ return settleCompletedResult(options, result, args, ctx, lease);
227
+ }
228
+ const nextRound = round + 1;
229
+ if (nextRound > maxRounds) {
230
+ await settleOnce(lease, lease.reservedUnits, 'input_required_round_limit');
231
+ throw new McpUsageRoundsExceededError('MCP usage multi-round flow exceeded maxRounds');
232
+ }
233
+ const resultRecord = result;
234
+ const innerState = resultRecord.requestState;
235
+ if (innerState !== undefined && typeof innerState !== 'string') {
236
+ await settleOnce(lease, lease.reservedUnits, 'invalid_input_required_state');
237
+ throw new McpUsageResumeError('MCP input_required requestState must be a string when present');
238
+ }
239
+ let wrappedResult;
240
+ try {
241
+ const flowId = await createFlowId(options.flowId);
242
+ const requestState = await options.requestState.mint({ mcpUsageControl: 1, flowId }, ctx);
243
+ validateWireRequestState(requestState);
244
+ const renewed = await lease.renew(options.suspendTtlMs);
245
+ const record = {
246
+ flowId,
247
+ binding,
248
+ lease: lease.toResumeState(),
249
+ round: nextRound,
250
+ expiresAt: renewed.expiresAt,
251
+ ...(innerState === undefined ? {} : { applicationRequestState: innerState }),
252
+ };
253
+ await options.flowStore.suspend(record);
254
+ wrappedResult = { ...resultRecord, requestState };
255
+ }
256
+ catch (suspendError) {
257
+ await settleOnce(lease, lease.reservedUnits, 'input_required_suspend_failed', suspendError);
258
+ throw suspendError;
259
+ }
260
+ return wrappedResult;
261
+ };
262
+ return protectedHandler;
263
+ }
264
+ async function settleCompletedResult(options, result, args, ctx, lease) {
265
+ if (isToolErrorResult(result)) {
266
+ const classified = await classifyUnits(options.toolErrorUnits
267
+ ? () => options.toolErrorUnits({ result, args, ctx, lease })
268
+ : undefined, lease.reservedUnits, lease);
269
+ await settleOnce(lease, classified.units, 'tool_error');
270
+ if (classified.error !== undefined) {
271
+ throw new UsageClassificationError('Usage tool-error classification failed; full reservation was charged', classified.error);
272
+ }
273
+ return result;
274
+ }
275
+ const classified = await classifyUnits(options.successUnits
276
+ ? () => options.successUnits({ result, args, ctx, lease })
277
+ : undefined, lease.reservedUnits, lease);
278
+ await settleOnce(lease, classified.units, 'success');
279
+ if (classified.error !== undefined) {
280
+ throw new UsageClassificationError('Usage success-cost classification failed; full reservation was charged', classified.error);
281
+ }
282
+ return result;
283
+ }
284
+ function resolveInvocation(noInput, argsOrCtx, maybeCtx, wrapperName) {
285
+ if (noInput) {
286
+ return {
287
+ args: undefined,
288
+ ctx: (maybeCtx ?? argsOrCtx),
289
+ };
290
+ }
291
+ if (maybeCtx === undefined) {
292
+ throw new TypeError(`${wrapperName} expected an (args, ctx) invocation; set noInput: true for a tool without an input schema`);
293
+ }
294
+ return { args: argsOrCtx, ctx: maybeCtx };
295
+ }
296
+ const MAX_PORTABLE_TIMER_DELAY_MS = 2_147_483_647;
297
+ function noHeartbeat() {
298
+ return { stop: async () => undefined };
299
+ }
300
+ function startLeaseHeartbeat(lease, onState) {
301
+ const intervalMs = Math.max(1, Math.floor(lease.ttlMs / 3));
302
+ let remainingMs = intervalMs;
303
+ let stopped = false;
304
+ let timer;
305
+ let inFlight;
306
+ let uncertain = false;
307
+ const notify = (event) => {
308
+ if (!onState)
309
+ return;
310
+ Promise.resolve()
311
+ .then(() => onState(event))
312
+ .catch(() => undefined);
313
+ };
314
+ const schedule = () => {
315
+ if (stopped)
316
+ return;
317
+ const delayMs = Math.min(remainingMs, MAX_PORTABLE_TIMER_DELAY_MS);
318
+ timer = setTimeout(() => {
319
+ if (stopped)
320
+ return;
321
+ remainingMs -= delayMs;
322
+ if (remainingMs > 0) {
323
+ schedule();
324
+ return;
325
+ }
326
+ inFlight = lease
327
+ .renew()
328
+ .then(() => {
329
+ if (uncertain) {
330
+ uncertain = false;
331
+ notify({ status: 'confirmed', lease });
332
+ }
333
+ })
334
+ .catch(error => {
335
+ if (!uncertain) {
336
+ uncertain = true;
337
+ notify({ status: 'uncertain', lease, error });
338
+ }
339
+ })
340
+ .finally(() => {
341
+ inFlight = undefined;
342
+ remainingMs = intervalMs;
343
+ schedule();
344
+ });
345
+ }, delayMs);
346
+ };
347
+ schedule();
348
+ return {
349
+ async stop() {
350
+ stopped = true;
351
+ if (timer !== undefined)
352
+ clearTimeout(timer);
353
+ if (inFlight !== undefined)
354
+ await inFlight;
355
+ },
356
+ };
357
+ }
358
+ async function classifyUnits(resolver, fallbackUnits, lease) {
359
+ if (!resolver)
360
+ return { units: fallbackUnits };
361
+ try {
362
+ const units = await resolver();
363
+ if (!Number.isSafeInteger(units) || units < 0 || units > lease.reservedUnits) {
364
+ throw new RangeError('classified units must be a non-negative safe integer within the reservation');
365
+ }
366
+ return { units };
367
+ }
368
+ catch (error) {
369
+ return { units: fallbackUnits, error };
370
+ }
371
+ }
372
+ function isToolErrorResult(value) {
373
+ return isRecord(value) && value.isError === true;
374
+ }
375
+ function isInputRequiredResult(value) {
376
+ return isRecord(value) && value.resultType === 'input_required';
377
+ }
378
+ function isMcpUsageRequestStatePayload(value) {
379
+ return (isRecord(value) &&
380
+ value.mcpUsageControl === 1 &&
381
+ typeof value.flowId === 'string' &&
382
+ isValidFlowId(value.flowId));
383
+ }
384
+ function isRecord(value) {
385
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
386
+ }
387
+ async function settleOnce(lease, actualUnits, outcome, executionError) {
388
+ try {
389
+ const canonicalOutcome = normalizeSettlementOutcome(outcome);
390
+ await lease.settle(actualUnits, canonicalOutcome);
391
+ }
392
+ catch (settlementError) {
393
+ throw new UsageSettlementError('Usage settlement failed; settlement state may be ambiguous', settlementError, executionError);
394
+ }
395
+ }
396
+ async function createFlowId(generator) {
397
+ const flowId = generator ? await generator() : randomFlowId();
398
+ if (!isValidFlowId(flowId)) {
399
+ throw new RangeError('flowId must be 16-128 URL-safe characters');
400
+ }
401
+ return flowId;
402
+ }
403
+ function randomFlowId() {
404
+ if (typeof globalThis.crypto.randomUUID === 'function')
405
+ return globalThis.crypto.randomUUID();
406
+ const bytes = new Uint8Array(24);
407
+ globalThis.crypto.getRandomValues(bytes);
408
+ return Array.from(bytes, value => value.toString(16).padStart(2, '0')).join('');
409
+ }
410
+ function isValidFlowId(value) {
411
+ return /^[A-Za-z0-9._~-]{16,128}$/.test(value);
412
+ }
413
+ function validateWireRequestState(value) {
414
+ if (typeof value !== 'string' || value.length === 0 || value.length > 16_384) {
415
+ throw new RangeError('minted MCP requestState must be a non-empty string up to 16384 characters');
416
+ }
417
+ }
418
+ async function hashArgs(value) {
419
+ const encoded = new TextEncoder().encode(stableJson(value));
420
+ const digest = await globalThis.crypto.subtle.digest('SHA-256', encoded);
421
+ return Array.from(new Uint8Array(digest), byte => byte.toString(16).padStart(2, '0')).join('');
422
+ }
423
+ function stableJson(value, seen = new Set()) {
424
+ if (value === undefined)
425
+ return '["undefined"]';
426
+ if (value === null)
427
+ return '["null"]';
428
+ switch (typeof value) {
429
+ case 'string':
430
+ return `["string",${JSON.stringify(value)}]`;
431
+ case 'boolean':
432
+ return `["boolean",${value ? 'true' : 'false'}]`;
433
+ case 'number':
434
+ if (!Number.isFinite(value))
435
+ throw new TypeError('MCP tool args must contain only finite JSON numbers');
436
+ return `["number",${JSON.stringify(value)}]`;
437
+ case 'object': {
438
+ const object = value;
439
+ if (seen.has(object))
440
+ throw new TypeError('MCP tool args must not contain cycles');
441
+ seen.add(object);
442
+ try {
443
+ if (Array.isArray(value)) {
444
+ return `["array",${value.map(item => stableJson(item, seen)).join(',')}]`;
445
+ }
446
+ const prototype = Object.getPrototypeOf(value);
447
+ if (prototype !== Object.prototype && prototype !== null) {
448
+ throw new TypeError('MCP tool args must be plain JSON objects');
449
+ }
450
+ const entries = Object.keys(value)
451
+ .sort()
452
+ .map(key => `[${JSON.stringify(key)},${stableJson(value[key], seen)}]`);
453
+ return `["object",${entries.join(',')}]`;
454
+ }
455
+ finally {
456
+ seen.delete(object);
457
+ }
458
+ }
459
+ default:
460
+ throw new TypeError('MCP tool args must be JSON-serializable');
461
+ }
462
+ }
463
+ function sameBinding(left, right) {
464
+ return (left.principalId === right.principalId &&
465
+ left.tenantId === right.tenantId &&
466
+ left.tool === right.tool &&
467
+ left.argsHash === right.argsHash);
468
+ }
469
+ function validateFlowRecord(record) {
470
+ if (!isValidFlowId(record.flowId))
471
+ throw new UsageStateError('Invalid MCP usage flow ID');
472
+ if (!Number.isSafeInteger(record.round) || record.round <= 0) {
473
+ throw new UsageStateError('MCP usage flow round must be a positive safe integer');
474
+ }
475
+ if (!Number.isSafeInteger(record.expiresAt) || record.expiresAt <= Date.now()) {
476
+ throw new UsageStateError('MCP usage flow expiry must be in the future');
477
+ }
478
+ if (record.lease.reservation.expiresAt !== record.expiresAt) {
479
+ throw new UsageStateError('MCP usage flow and lease expiry must match');
480
+ }
481
+ if (record.binding.principalId.length === 0 || record.binding.tool.length === 0) {
482
+ throw new UsageStateError('MCP usage flow binding identity must be non-empty');
483
+ }
484
+ if (!/^[a-f0-9]{64}$/.test(record.binding.argsHash)) {
485
+ throw new UsageStateError('MCP usage flow args hash must be SHA-256 hex');
486
+ }
487
+ if (record.applicationRequestState !== undefined &&
488
+ (record.applicationRequestState.length === 0 || record.applicationRequestState.length > 16_384)) {
489
+ throw new UsageStateError('Application requestState must be a non-empty bounded string');
490
+ }
491
+ }
492
+ function cloneFlowRecord(record) {
493
+ return {
494
+ flowId: record.flowId,
495
+ binding: { ...record.binding },
496
+ lease: {
497
+ reservation: {
498
+ ...record.lease.reservation,
499
+ budgetKeys: [...record.lease.reservation.budgetKeys],
500
+ },
501
+ ttlMs: record.lease.ttlMs,
502
+ ...(record.lease.metadata === undefined ? {} : { metadata: { ...record.lease.metadata } }),
503
+ ...(record.lease.unresolvedGrowth === undefined
504
+ ? {}
505
+ : {
506
+ unresolvedGrowth: {
507
+ incrementId: record.lease.unresolvedGrowth.incrementId,
508
+ additionalUnits: record.lease.unresolvedGrowth.additionalUnits,
509
+ budgets: record.lease.unresolvedGrowth.budgets.map(budget => ({ ...budget })),
510
+ },
511
+ }),
512
+ },
513
+ round: record.round,
514
+ expiresAt: record.expiresAt,
515
+ ...(record.applicationRequestState === undefined
516
+ ? {}
517
+ : { applicationRequestState: record.applicationRequestState }),
518
+ };
519
+ }
520
+ function assertPositiveInteger(value, name) {
521
+ if (!Number.isSafeInteger(value) || value <= 0) {
522
+ throw new RangeError(`${name} must be a positive safe integer`);
523
+ }
524
+ }
525
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,gBAAgB,EAChB,eAAe,GAKhB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,0BAA0B,EAAE,MAAM,uCAAuC,CAAC;AA8GnF;;;;;;GAMG;AACH,MAAM,OAAO,uBAAuB;IACjB,KAAK,GAAG,IAAI,GAAG,EAA8B,CAAC;IAE/D,OAAO,CAAC,MAA0B;QAChC,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;QAC9B,kBAAkB,CAAC,MAAM,CAAC,CAAC;QAC3B,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;YAClC,MAAM,IAAI,eAAe,CAAC,kCAAkC,CAAC,CAAC;QAChE,CAAC;QACD,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,MAAM,CAAC,CAAC,CAAC;IACzD,CAAC;IAED,OAAO,CAAC,MAAc,EAAE,OAA4B;QAClD,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACvB,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC;QACvB,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACtC,IAAI,CAAC,MAAM,IAA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C;qBAC9E;iBACF,CAAC;SACP;QACD,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,SAAS,EAAE,MAAM,CAAC,SAAS;QAC3B,GAAG,CAAC,MAAM,CAAC,uBAAuB,KAAK,SAAS;YAC9C,CAAC,CAAC,EAAE;YACJ,CAAC,CAAC,EAAE,uBAAuB,EAAE,MAAM,CAAC,uBAAuB,EAAE,CAAC;KACjE,CAAC;AACJ,CAAC;AAED,SAAS,qBAAqB,CAAC,KAAa,EAAE,IAAY;IACxD,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,EAAE,CAAC;QAC/C,MAAM,IAAI,UAAU,CAAC,GAAG,IAAI,kCAAkC,CAAC,CAAC;IAClE,CAAC;AACH,CAAC"}
package/package.json ADDED
@@ -0,0 +1,71 @@
1
+ {
2
+ "name": "mcp-usage-control-mcp",
3
+ "version": "1.0.0",
4
+ "description": "MCP TypeScript SDK v2 adapter for mcp-usage-control.",
5
+ "type": "module",
6
+ "license": "Apache-2.0",
7
+ "sideEffects": false,
8
+ "main": "./dist/index.js",
9
+ "types": "./dist/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "import": "./dist/index.js",
14
+ "default": "./dist/index.js"
15
+ },
16
+ "./conformance": {
17
+ "types": "./dist/flow-store-conformance.d.ts",
18
+ "import": "./dist/flow-store-conformance.js",
19
+ "default": "./dist/flow-store-conformance.js"
20
+ }
21
+ },
22
+ "files": [
23
+ "dist/index.js",
24
+ "dist/index.js.map",
25
+ "dist/index.d.ts",
26
+ "dist/index.d.ts.map",
27
+ "dist/flow-store-conformance.js",
28
+ "dist/flow-store-conformance.js.map",
29
+ "dist/flow-store-conformance.d.ts",
30
+ "dist/flow-store-conformance.d.ts.map",
31
+ "README.md",
32
+ "LICENSE"
33
+ ],
34
+ "engines": {
35
+ "node": ">=22"
36
+ },
37
+ "repository": {
38
+ "type": "git",
39
+ "url": "git+https://github.com/git-ksk/mcp-usage-control.git",
40
+ "directory": "packages/mcp"
41
+ },
42
+ "homepage": "https://github.com/git-ksk/mcp-usage-control#readme",
43
+ "bugs": {
44
+ "url": "https://github.com/git-ksk/mcp-usage-control/issues"
45
+ },
46
+ "keywords": [
47
+ "mcp",
48
+ "model-context-protocol",
49
+ "usage",
50
+ "quota",
51
+ "middleware"
52
+ ],
53
+ "publishConfig": {
54
+ "access": "public"
55
+ },
56
+ "scripts": {
57
+ "build": "tsc -p tsconfig.json",
58
+ "test": "vitest run"
59
+ },
60
+ "dependencies": {
61
+ "mcp-usage-control": "^1.0.0"
62
+ },
63
+ "peerDependencies": {
64
+ "@modelcontextprotocol/server": "^2.0.0"
65
+ },
66
+ "devDependencies": {
67
+ "@modelcontextprotocol/client": "^2.0.0",
68
+ "@modelcontextprotocol/server": "^2.0.0",
69
+ "zod": "^4.0.0"
70
+ }
71
+ }