@nest-mcp/manager 0.0.0-stage → 2.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/CHANGELOG.md +90 -0
- package/LICENSE +28 -0
- package/README.md +255 -2
- package/dist/index.d.mts +350 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +1697 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +68 -3
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
import { CallToolResult, GetPromptResult, McpClientConnectionSnapshot, McpClientRuntime, McpClientRuntimeOptions, McpClientTransportDefinition, ReadResourceResult } from "@nest-mcp/client";
|
|
2
|
+
import { Prompt, Resource, ResourceTemplateType, StandardSchemaV1Sync, Tool } from "@modelcontextprotocol/client";
|
|
3
|
+
import { MaybePromise, McpLifecycleObserver } from "@nest-mcp/core";
|
|
4
|
+
//#region src/errors.d.ts
|
|
5
|
+
declare const MCP_RUNTIME_QUEUE_FULL: "MCP_QUEUE_FULL";
|
|
6
|
+
declare const MCP_RUNTIME_ADMISSION_TIMEOUT: "MCP_ADMISSION_TIMEOUT";
|
|
7
|
+
declare const MCP_RUNTIME_CAPACITY_EXCEEDED: "MCP_CAPACITY_EXCEEDED";
|
|
8
|
+
declare const MCP_RUNTIME_DISCOVERY_LIMIT_EXCEEDED: "MCP_DISCOVERY_LIMIT_EXCEEDED";
|
|
9
|
+
declare const MCP_RUNTIME_GENERATION_RETIRED: "MCP_GENERATION_RETIRED";
|
|
10
|
+
declare const MCP_RUNTIME_LEASE_MODE_CONFLICT: "MCP_LEASE_MODE_CONFLICT";
|
|
11
|
+
declare const MCP_RUNTIME_NOT_READY: "MCP_NOT_READY";
|
|
12
|
+
declare const MCP_RUNTIME_QUARANTINED: "MCP_QUARANTINED";
|
|
13
|
+
declare const MCP_RUNTIME_MANAGER_CLOSED: "MCP_RUNTIME_CLOSED";
|
|
14
|
+
declare const MCP_RUNTIME_UPSTREAM_FAILED: "MCP_UPSTREAM_FAILED";
|
|
15
|
+
declare const MCP_RUNTIME_CLEANUP_FAILED: "MCP_CLEANUP_FAILED";
|
|
16
|
+
declare const MCP_RUNTIME_CONNECTION_LOST: "MCP_CONNECTION_LOST";
|
|
17
|
+
type McpRuntimeManagerErrorCode = typeof MCP_RUNTIME_CAPACITY_EXCEEDED | typeof MCP_RUNTIME_QUEUE_FULL | typeof MCP_RUNTIME_ADMISSION_TIMEOUT | typeof MCP_RUNTIME_DISCOVERY_LIMIT_EXCEEDED | typeof MCP_RUNTIME_GENERATION_RETIRED | typeof MCP_RUNTIME_LEASE_MODE_CONFLICT | typeof MCP_RUNTIME_NOT_READY | typeof MCP_RUNTIME_QUARANTINED | typeof MCP_RUNTIME_MANAGER_CLOSED | typeof MCP_RUNTIME_UPSTREAM_FAILED;
|
|
18
|
+
type McpRuntimeStateErrorCode = McpRuntimeManagerErrorCode | typeof MCP_RUNTIME_CLEANUP_FAILED | typeof MCP_RUNTIME_CONNECTION_LOST | "UNKNOWN";
|
|
19
|
+
/** Framework-neutral, key-free failure raised by the managed runtime lifecycle. */
|
|
20
|
+
declare class McpRuntimeManagerError extends Error {
|
|
21
|
+
readonly code: McpRuntimeManagerErrorCode;
|
|
22
|
+
constructor(code: McpRuntimeManagerErrorCode, message: string, options?: ErrorOptions);
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
//#region src/types.d.ts
|
|
26
|
+
type McpRuntimePhase = "offline" | "queued" | "connecting" | "online" | "degraded" | "draining" | "failed" | "quarantined";
|
|
27
|
+
/** Protocol era negotiated by a connected managed runtime generation. */
|
|
28
|
+
type McpRuntimeProtocolEra = NonNullable<McpClientConnectionSnapshot["protocolEra"]>;
|
|
29
|
+
interface McpRuntimeCapabilitiesSnapshot {
|
|
30
|
+
readonly tools: boolean;
|
|
31
|
+
readonly resources: boolean;
|
|
32
|
+
readonly prompts: boolean;
|
|
33
|
+
readonly completion: boolean;
|
|
34
|
+
readonly subscriptions: boolean;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Normalized immutable projection of one managed runtime's lifecycle state.
|
|
38
|
+
*
|
|
39
|
+
* Optional properties are absent rather than present with an `undefined` value.
|
|
40
|
+
* The snapshot and its nested capability projection are frozen.
|
|
41
|
+
*/
|
|
42
|
+
interface McpRuntimeStateSnapshot {
|
|
43
|
+
readonly phase: McpRuntimePhase;
|
|
44
|
+
readonly lastTransitionAt: string;
|
|
45
|
+
readonly protocolVersion?: string;
|
|
46
|
+
readonly protocolEra?: McpRuntimeProtocolEra;
|
|
47
|
+
readonly connectedAt?: string;
|
|
48
|
+
readonly errorCode?: McpRuntimeStateErrorCode;
|
|
49
|
+
readonly capabilities?: McpRuntimeCapabilitiesSnapshot;
|
|
50
|
+
}
|
|
51
|
+
/** Aggregate diagnostics deliberately omit opaque generation keys and runtime names. */
|
|
52
|
+
interface McpRuntimeManagerSnapshot {
|
|
53
|
+
readonly closed: boolean;
|
|
54
|
+
readonly maxConnections: number;
|
|
55
|
+
readonly maxQueuedOperations: number;
|
|
56
|
+
readonly queuedOperationCount: number;
|
|
57
|
+
readonly connectionCount: number;
|
|
58
|
+
readonly pendingConnectionCount: number;
|
|
59
|
+
readonly activeConnectionCount: number;
|
|
60
|
+
readonly closingConnectionCount: number;
|
|
61
|
+
readonly quarantinedConnectionCount: number;
|
|
62
|
+
readonly operationReferenceCount: number;
|
|
63
|
+
readonly onlineKeeperCount: number;
|
|
64
|
+
}
|
|
65
|
+
interface McpRuntimeCatalogSnapshot {
|
|
66
|
+
readonly discoveredAt: string;
|
|
67
|
+
readonly tools: readonly Tool[];
|
|
68
|
+
readonly resources: readonly Resource[];
|
|
69
|
+
readonly resourceTemplates: readonly ResourceTemplateType[];
|
|
70
|
+
readonly prompts: readonly Prompt[];
|
|
71
|
+
}
|
|
72
|
+
interface McpRuntimeProbeSnapshot {
|
|
73
|
+
readonly reachable: true;
|
|
74
|
+
readonly observedAt: string;
|
|
75
|
+
readonly protocolVersion?: string;
|
|
76
|
+
readonly protocolEra?: McpRuntimeProtocolEra;
|
|
77
|
+
readonly capabilities?: McpRuntimeCapabilitiesSnapshot;
|
|
78
|
+
readonly runtime: McpRuntimeStateSnapshot;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Selects whether an operation may reuse the generation-keyed runtime.
|
|
82
|
+
*
|
|
83
|
+
* `"concurrent"` admits an isolated transport per operation. `concurrentContention: "queue"`
|
|
84
|
+
* opts into bounded waiting for connector and process capacity; the default rejects contention.
|
|
85
|
+
* `"shared"` preserves the manager's ordinary retained-generation behavior. `"exclusive"`
|
|
86
|
+
* creates one unshared runtime for the operation and closes it before settlement. Exclusive
|
|
87
|
+
* work is fail-fast unless `exclusiveContention: "queue"` opts into bounded waiting behind
|
|
88
|
+
* another exclusive operation. Shared work and retained keepers still conflict. A custom
|
|
89
|
+
* `withClientRuntime` callback remains responsible for not starting parallel protocol requests.
|
|
90
|
+
*/
|
|
91
|
+
type McpRuntimeOperationLeaseMode = "shared" | "exclusive" | "concurrent";
|
|
92
|
+
interface McpRuntimeAdmissionEvent {
|
|
93
|
+
readonly outcome: "admitted" | "queue-full" | "timeout" | "cancelled" | "refused";
|
|
94
|
+
readonly durationMs: number;
|
|
95
|
+
readonly queuedOperationCount: number;
|
|
96
|
+
readonly activeConnectionCount: number;
|
|
97
|
+
}
|
|
98
|
+
interface McpRuntimeOperationOptions {
|
|
99
|
+
readonly signal?: AbortSignal;
|
|
100
|
+
/** Defaults to `"shared"`; use `"exclusive"` for a non-pooled close-before-settlement runtime. */
|
|
101
|
+
readonly leaseMode?: McpRuntimeOperationLeaseMode;
|
|
102
|
+
/** Stable opaque connector identity across generations. Required for concurrent calls;
|
|
103
|
+
* supply the same identity to exclusive calls for mutual exclusion. Never logged. */
|
|
104
|
+
readonly admissionKey?: string;
|
|
105
|
+
/** Defaults to `"reject"`. `"queue"` waits FIFO behind exclusive work within the request deadline. */
|
|
106
|
+
readonly exclusiveContention?: "reject" | "queue";
|
|
107
|
+
/** Opt into bounded waiting for isolated concurrent calls, including process capacity. */
|
|
108
|
+
readonly concurrentContention?: "reject" | "queue";
|
|
109
|
+
/** Host-owned connector limit; null removes the per-key ceiling, undefined uses the manager default. */
|
|
110
|
+
readonly maxConcurrentOperations?: number | null;
|
|
111
|
+
/** Bounded, key-free admission timing. Observer failures never alter execution. */
|
|
112
|
+
readonly onAdmission?: (event: McpRuntimeAdmissionEvent) => void;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Narrow client-runtime surface available while the manager owns a generation lease.
|
|
116
|
+
* Registry mutation, transport admission, shutdown, and credential material stay private.
|
|
117
|
+
*/
|
|
118
|
+
type McpManagedClientRuntime = Pick<McpClientRuntime, "callTool" | "complete" | "getPrompt" | "listPrompts" | "listResources" | "listResourceTemplates" | "listTools" | "readResource" | "request" | "requestWithInputRequired" | "snapshot">;
|
|
119
|
+
interface McpManagedClientRuntimeContext {
|
|
120
|
+
readonly runtime: McpManagedClientRuntime;
|
|
121
|
+
readonly serverName: string;
|
|
122
|
+
readonly signal: AbortSignal;
|
|
123
|
+
}
|
|
124
|
+
type McpManagedClientRuntimeOperation<Result> = (context: McpManagedClientRuntimeContext) => Promise<Result>;
|
|
125
|
+
/**
|
|
126
|
+
* Host-authorized transport material for one opaque runtime generation.
|
|
127
|
+
*
|
|
128
|
+
* The close callback is wrapped by the manager, but hosts should still make it
|
|
129
|
+
* idempotent because process-level cleanup can be retried after failures.
|
|
130
|
+
*/
|
|
131
|
+
interface McpAdmittedRuntimeGeneration {
|
|
132
|
+
readonly transport: McpClientTransportDefinition;
|
|
133
|
+
/**
|
|
134
|
+
* Called once after successful negotiation, before the runtime is handed to an operation.
|
|
135
|
+
* The host may retain this immutable observation independently of transient runtime state.
|
|
136
|
+
* Awaited as part of acquisition; rejection fails acquisition and closes admitted material.
|
|
137
|
+
* Hosts that need best-effort persistence must handle their own persistence errors.
|
|
138
|
+
*/
|
|
139
|
+
onConnected?(snapshot: McpRuntimeStateSnapshot, signal: AbortSignal): MaybePromise<void>;
|
|
140
|
+
close(): Promise<void>;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Resolves an opaque, non-secret generation key into already-admitted runtime
|
|
144
|
+
* material. Product records, credentials, endpoint policy, and tenancy remain
|
|
145
|
+
* behind this interface.
|
|
146
|
+
*/
|
|
147
|
+
interface McpRuntimeGenerationResolver<GenerationKey = string> {
|
|
148
|
+
resolve(generationKey: GenerationKey, signal: AbortSignal): Promise<McpAdmittedRuntimeGeneration>;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* A key-free, bounded state transition suitable for metrics and diagnostics.
|
|
152
|
+
* It intentionally omits endpoints, server names, generation keys, payloads,
|
|
153
|
+
* error messages, and credentials.
|
|
154
|
+
*/
|
|
155
|
+
interface McpRuntimeStateTransitionEvent {
|
|
156
|
+
readonly type: "runtime.state.changed";
|
|
157
|
+
readonly timestamp: number;
|
|
158
|
+
readonly phase: McpRuntimePhase;
|
|
159
|
+
readonly previousPhase?: McpRuntimePhase;
|
|
160
|
+
readonly errorCode?: McpRuntimeStateErrorCode;
|
|
161
|
+
readonly protocolEra?: McpRuntimeProtocolEra;
|
|
162
|
+
readonly capabilities?: McpRuntimeCapabilitiesSnapshot;
|
|
163
|
+
}
|
|
164
|
+
type McpRuntimeStateListener = (event: McpRuntimeStateTransitionEvent) => MaybePromise<void>;
|
|
165
|
+
interface McpRuntimeManagerOptions<GenerationKey = string> {
|
|
166
|
+
readonly generationResolver: McpRuntimeGenerationResolver<GenerationKey>;
|
|
167
|
+
readonly maxConnections?: number;
|
|
168
|
+
/** Global bound on operations waiting behind exclusive work; defaults to 100. */
|
|
169
|
+
readonly maxQueuedOperations?: number;
|
|
170
|
+
/** Concurrent isolated operations per admissionKey, including cleanup. Defaults to four. */
|
|
171
|
+
readonly maxConcurrentOperationsPerAdmissionKey?: number | null;
|
|
172
|
+
/** Maximum retained generation state projections; must be at least maxConnections. */
|
|
173
|
+
readonly maxStateEntries?: number;
|
|
174
|
+
readonly requestTimeoutMs?: number;
|
|
175
|
+
readonly shutdownTimeoutMs?: number;
|
|
176
|
+
readonly maxDiscoveryPages?: number;
|
|
177
|
+
readonly maxDiscoveryItems?: number;
|
|
178
|
+
/** Identity advertised by every short-lived managed MCP client runtime. */
|
|
179
|
+
readonly clientInfo?: NonNullable<McpClientRuntimeOptions["clientInfo"]>;
|
|
180
|
+
/** Receives operation lifecycle events from every managed client runtime. */
|
|
181
|
+
readonly observer?: McpLifecycleObserver;
|
|
182
|
+
/** Unix epoch milliseconds, injectable for deterministic state and runtime snapshots. */
|
|
183
|
+
readonly now?: () => number;
|
|
184
|
+
/** Listener failures never alter runtime lifecycle; this hook receives them best-effort. */
|
|
185
|
+
readonly onListenerError?: (error: unknown, event: McpRuntimeStateTransitionEvent) => MaybePromise<void>;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Per-call controls for the manager's convenience tool invocation.
|
|
189
|
+
*
|
|
190
|
+
* Pinning `toolDefinition` keeps the managed client runtime's structured output
|
|
191
|
+
* validation bound to that exact definition instead of a cached `tools/list`
|
|
192
|
+
* view, so a host that already holds an approved definition never validates a
|
|
193
|
+
* result against a drifted schema.
|
|
194
|
+
*/
|
|
195
|
+
interface McpRuntimeToolCallOptions {
|
|
196
|
+
readonly signal?: AbortSignal;
|
|
197
|
+
/** Defaults to `"shared"`; exclusive calls do not require an online keeper. */
|
|
198
|
+
readonly leaseMode?: McpRuntimeOperationLeaseMode;
|
|
199
|
+
/** Stable opaque connector identity across generations. Required for concurrent calls;
|
|
200
|
+
* supply the same identity to exclusive calls for mutual exclusion. Never logged. */
|
|
201
|
+
readonly admissionKey?: string;
|
|
202
|
+
/** Defaults to `"reject"`; requires `leaseMode: "exclusive"` when set to `"queue"`. */
|
|
203
|
+
readonly exclusiveContention?: "reject" | "queue";
|
|
204
|
+
/** Opt into bounded waiting for isolated concurrent calls, including process capacity. */
|
|
205
|
+
readonly concurrentContention?: "reject" | "queue";
|
|
206
|
+
/** Host-owned connector limit; null removes the per-key ceiling, undefined uses the manager default. */
|
|
207
|
+
readonly maxConcurrentOperations?: number | null;
|
|
208
|
+
/** Bounded, key-free admission timing. Observer failures never alter execution. */
|
|
209
|
+
readonly onAdmission?: (event: McpRuntimeAdmissionEvent) => void;
|
|
210
|
+
readonly toolDefinition?: Tool;
|
|
211
|
+
}
|
|
212
|
+
interface McpRuntimeManagerPort<GenerationKey = string> {
|
|
213
|
+
ensureOnline(generationKey: GenerationKey, signal?: AbortSignal): Promise<McpRuntimeStateSnapshot>;
|
|
214
|
+
setOffline(generationKey: GenerationKey): Promise<McpRuntimeStateSnapshot>;
|
|
215
|
+
retire(generationKey: GenerationKey): Promise<void>;
|
|
216
|
+
probe(generationKey: GenerationKey, options?: AbortSignal | McpRuntimeOperationOptions): Promise<McpRuntimeProbeSnapshot>;
|
|
217
|
+
refreshCatalog(generationKey: GenerationKey, options?: AbortSignal | McpRuntimeOperationOptions): Promise<McpRuntimeCatalogSnapshot>;
|
|
218
|
+
/** Execute a protocol-aware integration operation under the generation's managed lease. */
|
|
219
|
+
withClientRuntime<Result>(generationKey: GenerationKey, operation: McpManagedClientRuntimeOperation<Result>, options?: AbortSignal | McpRuntimeOperationOptions): Promise<Result>;
|
|
220
|
+
/** A positional `AbortSignal` stays accepted as the cancellation-only form of the options. */
|
|
221
|
+
callTool(generationKey: GenerationKey, name: string, arguments_: Readonly<Record<string, unknown>>, options?: AbortSignal | McpRuntimeToolCallOptions): Promise<CallToolResult>;
|
|
222
|
+
readResource(generationKey: GenerationKey, uri: string, options?: AbortSignal | McpRuntimeOperationOptions): Promise<ReadResourceResult>;
|
|
223
|
+
getPrompt(generationKey: GenerationKey, name: string, arguments_: Readonly<Record<string, string>> | undefined, options?: AbortSignal | McpRuntimeOperationOptions): Promise<GetPromptResult>;
|
|
224
|
+
state(generationKey: GenerationKey): McpRuntimeStateSnapshot;
|
|
225
|
+
snapshot(): McpRuntimeManagerSnapshot;
|
|
226
|
+
subscribe(listener: McpRuntimeStateListener): () => void;
|
|
227
|
+
close(): Promise<void>;
|
|
228
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
229
|
+
}
|
|
230
|
+
//#endregion
|
|
231
|
+
//#region src/runtime-manager.d.ts
|
|
232
|
+
declare const MCP_RUNTIME_MANAGER_DEFAULTS: Readonly<{
|
|
233
|
+
maxConnections: 100;
|
|
234
|
+
maxQueuedOperations: 100;
|
|
235
|
+
maxConcurrentOperationsPerAdmissionKey: 4;
|
|
236
|
+
maxStateEntries: 1000;
|
|
237
|
+
requestTimeoutMs: 10000;
|
|
238
|
+
shutdownTimeoutMs: 30000;
|
|
239
|
+
maxDiscoveryPages: 16;
|
|
240
|
+
maxDiscoveryItems: 1000;
|
|
241
|
+
}>;
|
|
242
|
+
declare class McpRuntimeManager<GenerationKey = string> implements McpRuntimeManagerPort<GenerationKey>, AsyncDisposable {
|
|
243
|
+
#private;
|
|
244
|
+
constructor(options: McpRuntimeManagerOptions<GenerationKey>);
|
|
245
|
+
ensureOnline(generationKey: GenerationKey, signal?: AbortSignal): Promise<McpRuntimeStateSnapshot>;
|
|
246
|
+
setOffline(generationKey: GenerationKey): Promise<McpRuntimeStateSnapshot>;
|
|
247
|
+
retire(generationKey: GenerationKey): Promise<void>;
|
|
248
|
+
probe(generationKey: GenerationKey, options?: AbortSignal | McpRuntimeOperationOptions): Promise<McpRuntimeProbeSnapshot>;
|
|
249
|
+
refreshCatalog(generationKey: GenerationKey, options?: AbortSignal | McpRuntimeOperationOptions): Promise<McpRuntimeCatalogSnapshot>;
|
|
250
|
+
withClientRuntime<Result>(generationKey: GenerationKey, operation: McpManagedClientRuntimeOperation<Result>, options?: AbortSignal | McpRuntimeOperationOptions): Promise<Result>;
|
|
251
|
+
callTool(generationKey: GenerationKey, name: string, arguments_: Readonly<Record<string, unknown>>, options?: AbortSignal | McpRuntimeToolCallOptions): Promise<CallToolResult>;
|
|
252
|
+
readResource(generationKey: GenerationKey, uri: string, options?: AbortSignal | McpRuntimeOperationOptions): Promise<ReadResourceResult>;
|
|
253
|
+
getPrompt(generationKey: GenerationKey, name: string, arguments_: Readonly<Record<string, string>> | undefined, options?: AbortSignal | McpRuntimeOperationOptions): Promise<GetPromptResult>;
|
|
254
|
+
state(generationKey: GenerationKey): McpRuntimeStateSnapshot;
|
|
255
|
+
snapshot(): McpRuntimeManagerSnapshot;
|
|
256
|
+
subscribe(listener: McpRuntimeStateListener): () => void;
|
|
257
|
+
close(): Promise<void>;
|
|
258
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
259
|
+
}
|
|
260
|
+
//#endregion
|
|
261
|
+
//#region src/runtime-ownership.d.ts
|
|
262
|
+
declare const MCP_RUNTIME_OWNERSHIP_DEFAULTS: Readonly<{
|
|
263
|
+
maxOwners: 1000;
|
|
264
|
+
maxGenerations: 1000;
|
|
265
|
+
maxReferences: 10000;
|
|
266
|
+
}>;
|
|
267
|
+
declare const MCP_RUNTIME_OWNERSHIP_INVALID_OPTIONS: "MCP_RUNTIME_OWNERSHIP_INVALID_OPTIONS";
|
|
268
|
+
declare const MCP_RUNTIME_OWNERSHIP_CAPACITY_EXCEEDED: "MCP_RUNTIME_OWNERSHIP_CAPACITY_EXCEEDED";
|
|
269
|
+
declare const MCP_RUNTIME_OWNER_RELEASED: "MCP_RUNTIME_OWNER_RELEASED";
|
|
270
|
+
declare const MCP_RUNTIME_GENERATION_FENCED: "MCP_RUNTIME_GENERATION_FENCED";
|
|
271
|
+
declare const MCP_RUNTIME_RETIREMENT_FAILED: "MCP_RUNTIME_RETIREMENT_FAILED";
|
|
272
|
+
type McpRuntimeOwnershipErrorCode = typeof MCP_RUNTIME_OWNERSHIP_INVALID_OPTIONS | typeof MCP_RUNTIME_OWNERSHIP_CAPACITY_EXCEEDED | typeof MCP_RUNTIME_OWNER_RELEASED | typeof MCP_RUNTIME_GENERATION_FENCED | typeof MCP_RUNTIME_RETIREMENT_FAILED;
|
|
273
|
+
/** Stable ownership failure that never retains a generation key or caught manager error. */
|
|
274
|
+
declare class McpRuntimeOwnershipError extends Error {
|
|
275
|
+
readonly code: McpRuntimeOwnershipErrorCode;
|
|
276
|
+
constructor(code: McpRuntimeOwnershipErrorCode, message: string);
|
|
277
|
+
}
|
|
278
|
+
/** The only manager operation taken into ownership by this coordinator. */
|
|
279
|
+
type McpRuntimeRetirementPort<GenerationKey> = Pick<McpRuntimeManagerPort<GenerationKey>, "retire">;
|
|
280
|
+
interface McpRuntimeOwnershipOptions<GenerationKey> {
|
|
281
|
+
readonly manager: McpRuntimeRetirementPort<GenerationKey>;
|
|
282
|
+
/** Hard bound over live owner capabilities. */
|
|
283
|
+
readonly maxOwners?: number;
|
|
284
|
+
/** Hard bound over active generations and retained retirement fences. */
|
|
285
|
+
readonly maxGenerations?: number;
|
|
286
|
+
/** Hard bound over distinct owner-to-generation references. */
|
|
287
|
+
readonly maxReferences?: number;
|
|
288
|
+
}
|
|
289
|
+
interface McpRuntimeOwner<GenerationKey> extends AsyncDisposable {
|
|
290
|
+
readonly released: boolean;
|
|
291
|
+
/** Retains after any older retirement barrier settles; concurrent duplicates share one task. */
|
|
292
|
+
retain(generationKey: GenerationKey): Promise<void>;
|
|
293
|
+
/** Releases every retained generation. Repeated calls share one settlement. */
|
|
294
|
+
release(): Promise<void>;
|
|
295
|
+
}
|
|
296
|
+
/** Aggregate diagnostics deliberately omit generation keys and manager failures. */
|
|
297
|
+
interface McpRuntimeOwnershipSnapshot {
|
|
298
|
+
readonly maxOwners: number;
|
|
299
|
+
readonly maxGenerations: number;
|
|
300
|
+
readonly maxReferences: number;
|
|
301
|
+
readonly ownerCount: number;
|
|
302
|
+
readonly generationCount: number;
|
|
303
|
+
readonly referenceCount: number;
|
|
304
|
+
readonly pendingReferenceCount: number;
|
|
305
|
+
readonly retiringGenerationCount: number;
|
|
306
|
+
readonly fencedGenerationCount: number;
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Bounded, framework-neutral cooperative ownership for opaque runtime generations.
|
|
310
|
+
*
|
|
311
|
+
* Equal keys use `Map` identity. The final cooperative release retires the manager generation.
|
|
312
|
+
* `forceRetire` immediately revokes every current reference and permanently fences every owner
|
|
313
|
+
* that existed when the force began. No retain can cross an unsettled retirement barrier.
|
|
314
|
+
*/
|
|
315
|
+
declare class McpRuntimeOwnership<GenerationKey> {
|
|
316
|
+
#private;
|
|
317
|
+
constructor(options: McpRuntimeOwnershipOptions<GenerationKey>);
|
|
318
|
+
createOwner(): McpRuntimeOwner<GenerationKey>;
|
|
319
|
+
/**
|
|
320
|
+
* Retires a generation regardless of cooperative references.
|
|
321
|
+
* Repeated calls against the same generation barrier share one settlement.
|
|
322
|
+
*/
|
|
323
|
+
forceRetire(generationKey: GenerationKey): Promise<void>;
|
|
324
|
+
snapshot(): McpRuntimeOwnershipSnapshot;
|
|
325
|
+
}
|
|
326
|
+
//#endregion
|
|
327
|
+
//#region src/runtime-snapshots.d.ts
|
|
328
|
+
/** Every `McpRuntimePhase`, in lifecycle order, for hosts that persist state projections. */
|
|
329
|
+
declare const MCP_RUNTIME_PHASES: readonly ["offline", "queued", "connecting", "online", "degraded", "draining", "failed", "quarantined"];
|
|
330
|
+
/** Every `McpRuntimeProtocolEra` a connected managed generation can report. */
|
|
331
|
+
declare const MCP_RUNTIME_PROTOCOL_ERAS: readonly ["legacy", "modern"];
|
|
332
|
+
/**
|
|
333
|
+
* Standard Schema v1 validator for one snapshot shape produced by the manager.
|
|
334
|
+
*
|
|
335
|
+
* Validation is synchronous and dependency-free. It accepts exactly what the
|
|
336
|
+
* manager itself emits, rejects unknown properties, and returns a frozen
|
|
337
|
+
* normalized snapshot so persisting a validated value round-trips unchanged.
|
|
338
|
+
*
|
|
339
|
+
* @see https://standardschema.dev
|
|
340
|
+
*/
|
|
341
|
+
type McpRuntimeSnapshotSchema<Snapshot> = StandardSchemaV1Sync<unknown, Snapshot>;
|
|
342
|
+
/** Validates a persisted `McpRuntimeCapabilitiesSnapshot`. */
|
|
343
|
+
declare const mcpRuntimeCapabilitiesSnapshotSchema: McpRuntimeSnapshotSchema<McpRuntimeCapabilitiesSnapshot>;
|
|
344
|
+
/** Validates a persisted `McpRuntimeStateSnapshot`, including an optional capability projection. */
|
|
345
|
+
declare const mcpRuntimeStateSnapshotSchema: McpRuntimeSnapshotSchema<McpRuntimeStateSnapshot>;
|
|
346
|
+
/** Validates a persisted `McpRuntimeProbeSnapshot`, including its nested state projection. */
|
|
347
|
+
declare const mcpRuntimeProbeSnapshotSchema: McpRuntimeSnapshotSchema<McpRuntimeProbeSnapshot>;
|
|
348
|
+
//#endregion
|
|
349
|
+
export { MCP_RUNTIME_ADMISSION_TIMEOUT, MCP_RUNTIME_CAPACITY_EXCEEDED, MCP_RUNTIME_CLEANUP_FAILED, MCP_RUNTIME_CONNECTION_LOST, MCP_RUNTIME_DISCOVERY_LIMIT_EXCEEDED, MCP_RUNTIME_GENERATION_FENCED, MCP_RUNTIME_GENERATION_RETIRED, MCP_RUNTIME_LEASE_MODE_CONFLICT, MCP_RUNTIME_MANAGER_CLOSED, MCP_RUNTIME_MANAGER_DEFAULTS, MCP_RUNTIME_NOT_READY, MCP_RUNTIME_OWNERSHIP_CAPACITY_EXCEEDED, MCP_RUNTIME_OWNERSHIP_DEFAULTS, MCP_RUNTIME_OWNERSHIP_INVALID_OPTIONS, MCP_RUNTIME_OWNER_RELEASED, MCP_RUNTIME_PHASES, MCP_RUNTIME_PROTOCOL_ERAS, MCP_RUNTIME_QUARANTINED, MCP_RUNTIME_QUEUE_FULL, MCP_RUNTIME_RETIREMENT_FAILED, MCP_RUNTIME_UPSTREAM_FAILED, type McpAdmittedRuntimeGeneration, type McpManagedClientRuntime, type McpManagedClientRuntimeContext, type McpManagedClientRuntimeOperation, type McpRuntimeAdmissionEvent, type McpRuntimeCapabilitiesSnapshot, type McpRuntimeCatalogSnapshot, type McpRuntimeGenerationResolver, McpRuntimeManager, McpRuntimeManagerError, type McpRuntimeManagerErrorCode, type McpRuntimeManagerOptions, type McpRuntimeManagerPort, type McpRuntimeManagerSnapshot, type McpRuntimeOperationLeaseMode, type McpRuntimeOperationOptions, type McpRuntimeOwner, McpRuntimeOwnership, McpRuntimeOwnershipError, type McpRuntimeOwnershipErrorCode, type McpRuntimeOwnershipOptions, type McpRuntimeOwnershipSnapshot, type McpRuntimePhase, type McpRuntimeProbeSnapshot, type McpRuntimeProtocolEra, type McpRuntimeRetirementPort, type McpRuntimeSnapshotSchema, type McpRuntimeStateErrorCode, type McpRuntimeStateListener, type McpRuntimeStateSnapshot, type McpRuntimeStateTransitionEvent, type McpRuntimeToolCallOptions, mcpRuntimeCapabilitiesSnapshotSchema, mcpRuntimeProbeSnapshotSchema, mcpRuntimeStateSnapshotSchema };
|
|
350
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/errors.ts","../src/types.ts","../src/runtime-manager.ts","../src/runtime-ownership.ts","../src/runtime-snapshots.ts"],"mappings":";;;;cAMa;cACA;cAEA;cACA;cACA;cACA;cACA;cACA;cACA;cACA;cAEA;cACA;KAED,oCACF,uCACA,gCACA,uCACA,8CACA,wCACA,yCACA,+BACA,iCACA,oCACA;KAEE,2BACT,oCACO,oCACA;;cAIG,+BAA+B;WAClC,MAAM;EAEf,YAAY,MAAM,4BAA4B,iBAAiB,UAAU;;;;KC7B9D;;KAWA,wBAAwB,YAAY;UAE/B;WACP;WACA;WACA;WACA;WACA;;;;;;;;UASO;WACP,OAAO;WACP;WACA;WACA,cAAc;WACd;WACA,YAAY;WACZ,eAAe;;;UAIR;WACP;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;;UAGO;WACP;WACA,gBAAgB;WAChB,oBAAoB;WACpB,4BAA4B;WAC5B,kBAAkB;;UAGX;WACP;WACA;WACA;WACA,cAAc;WACd,eAAe;WACf,SAAS;;;;;;;;;;;;;KAcP;UAEK;WACP;WACA;WACA;WACA;;UAGO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