@nest-mcp/client 1.0.2 → 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.
Files changed (54) hide show
  1. package/CHANGELOG.md +139 -0
  2. package/README.md +845 -69
  3. package/dist/ai-sdk/index.d.mts +14 -0
  4. package/dist/ai-sdk/index.d.mts.map +1 -0
  5. package/dist/ai-sdk/index.mjs +27 -0
  6. package/dist/ai-sdk/index.mjs.map +1 -0
  7. package/dist/bootstrap-BIAcDnHp.d.mts +394 -0
  8. package/dist/bootstrap-BIAcDnHp.d.mts.map +1 -0
  9. package/dist/index.d.mts +480 -0
  10. package/dist/index.d.mts.map +1 -0
  11. package/dist/index.mjs +1960 -0
  12. package/dist/index.mjs.map +1 -0
  13. package/dist/oauth/dynamic-registration.d.mts +92 -0
  14. package/dist/oauth/dynamic-registration.d.mts.map +1 -0
  15. package/dist/oauth/dynamic-registration.mjs +392 -0
  16. package/dist/oauth/dynamic-registration.mjs.map +1 -0
  17. package/dist/oauth/index.d.mts +422 -0
  18. package/dist/oauth/index.d.mts.map +1 -0
  19. package/dist/oauth/index.mjs +3349 -0
  20. package/dist/oauth/index.mjs.map +1 -0
  21. package/dist/scope-CxGBCDdr.mjs +22 -0
  22. package/dist/scope-CxGBCDdr.mjs.map +1 -0
  23. package/package.json +76 -50
  24. package/scripts/external-smoke.mjs +693 -0
  25. package/dist/decorators/inject-mcp-client.decorator.d.ts +0 -3
  26. package/dist/decorators/inject-mcp-client.decorator.js +0 -12
  27. package/dist/decorators/on-notification.decorator.d.ts +0 -7
  28. package/dist/decorators/on-notification.decorator.js +0 -13
  29. package/dist/health/mcp-client.health.d.ts +0 -20
  30. package/dist/health/mcp-client.health.js +0 -42
  31. package/dist/index.d.ts +0 -21
  32. package/dist/index.js +0 -64
  33. package/dist/interfaces/client-options.interface.d.ts +0 -139
  34. package/dist/interfaces/client-options.interface.js +0 -3
  35. package/dist/mcp-client.module.d.ts +0 -20
  36. package/dist/mcp-client.module.js +0 -188
  37. package/dist/mcp-client.service.d.ts +0 -558
  38. package/dist/mcp-client.service.js +0 -532
  39. package/dist/mcp-clients.service.d.ts +0 -39
  40. package/dist/mcp-clients.service.js +0 -104
  41. package/dist/testing/mock-client.d.ts +0 -67
  42. package/dist/testing/mock-client.js +0 -154
  43. package/dist/transport/apply-auth-headers.d.ts +0 -3
  44. package/dist/transport/apply-auth-headers.js +0 -13
  45. package/dist/transport/client-transport.factory.d.ts +0 -4
  46. package/dist/transport/client-transport.factory.js +0 -21
  47. package/dist/transport/sse-client.transport.d.ts +0 -4
  48. package/dist/transport/sse-client.transport.js +0 -15
  49. package/dist/transport/stdio-client.transport.d.ts +0 -4
  50. package/dist/transport/stdio-client.transport.js +0 -14
  51. package/dist/transport/streamable-client.transport.d.ts +0 -4
  52. package/dist/transport/streamable-client.transport.js +0 -17
  53. package/dist/utils/format-error-message.d.ts +0 -2
  54. package/dist/utils/format-error-message.js +0 -7
@@ -1,558 +0,0 @@
1
- import { Client } from '@modelcontextprotocol/sdk/client/index.js';
2
- import type { RequestOptions } from '@modelcontextprotocol/sdk/shared/protocol.js';
3
- import type { CallToolRequest, CompleteRequest, GetPromptRequest, ListPromptsRequest, ListResourceTemplatesRequest, ListResourcesRequest, ListToolsRequest, LoggingLevel, Prompt, ReadResourceRequest, Resource, ResourceTemplate, SubscribeRequest, Tool, UnsubscribeRequest } from '@modelcontextprotocol/sdk/types.js';
4
- import type { McpClientConnection, McpElicitationHandler, McpElicitationHandlerOptions, McpRootsHandler, McpSamplingHandler } from './interfaces/client-options.interface';
5
- type McpNotificationHandler = (notification: {
6
- method: string;
7
- params?: Record<string, unknown>;
8
- }) => void | Promise<void>;
9
- export declare class McpClient {
10
- readonly name: string;
11
- private readonly connection;
12
- private readonly logger;
13
- private client;
14
- private transport;
15
- private connected;
16
- private reconnectAttempts;
17
- private reconnecting;
18
- /** Set by `disconnect()`; stops reconnection and suppresses transport error handling. */
19
- private closing;
20
- /** Incremented by every `disconnect()`, so a reconnect loop started earlier can detect it. */
21
- private lifecycle;
22
- /** Whether a transport has been created at least once (`sessionId` only applies to the first). */
23
- private transportCreated;
24
- private readonly _notificationHandlerStore;
25
- /** URIs subscribed through `subscribeResource`, replayed after a reconnect. */
26
- private readonly _subscriptions;
27
- /** Capabilities passed by the user in the connection options. */
28
- private readonly _userCapabilities;
29
- /** Capabilities implied by registered handlers (sampling, elicitation, roots). */
30
- private _handlerCapabilities;
31
- private _samplingHandler?;
32
- private _elicitationHandler?;
33
- private _rootsHandler?;
34
- constructor(name: string, connection: McpClientConnection);
35
- /** Capabilities advertised on the next handshake: handler defaults, overridden by user values. */
36
- private get _declaredCapabilities();
37
- private _clientInfo;
38
- private _createClient;
39
- connect(): Promise<void>;
40
- /**
41
- * Close the connection. For Streamable HTTP, the session is ended first with an HTTP DELETE
42
- * (errors, including a 405 from servers that do not support it, are ignored). Stops any
43
- * reconnection in progress and forgets tracked resource subscriptions.
44
- */
45
- disconnect(): Promise<void>;
46
- isConnected(): boolean;
47
- getClient(): Client;
48
- callTool(params: CallToolRequest['params'], options?: RequestOptions): Promise<{
49
- [x: string]: unknown;
50
- content: ({
51
- type: "text";
52
- text: string;
53
- annotations?: {
54
- audience?: ("user" | "assistant")[] | undefined;
55
- priority?: number | undefined;
56
- lastModified?: string | undefined;
57
- } | undefined;
58
- _meta?: Record<string, unknown> | undefined;
59
- } | {
60
- type: "image";
61
- data: string;
62
- mimeType: string;
63
- annotations?: {
64
- audience?: ("user" | "assistant")[] | undefined;
65
- priority?: number | undefined;
66
- lastModified?: string | undefined;
67
- } | undefined;
68
- _meta?: Record<string, unknown> | undefined;
69
- } | {
70
- type: "audio";
71
- data: string;
72
- mimeType: string;
73
- annotations?: {
74
- audience?: ("user" | "assistant")[] | undefined;
75
- priority?: number | undefined;
76
- lastModified?: string | undefined;
77
- } | undefined;
78
- _meta?: Record<string, unknown> | undefined;
79
- } | {
80
- type: "resource";
81
- resource: {
82
- uri: string;
83
- text: string;
84
- mimeType?: string | undefined;
85
- _meta?: Record<string, unknown> | undefined;
86
- } | {
87
- uri: string;
88
- blob: string;
89
- mimeType?: string | undefined;
90
- _meta?: Record<string, unknown> | undefined;
91
- };
92
- annotations?: {
93
- audience?: ("user" | "assistant")[] | undefined;
94
- priority?: number | undefined;
95
- lastModified?: string | undefined;
96
- } | undefined;
97
- _meta?: Record<string, unknown> | undefined;
98
- } | {
99
- uri: string;
100
- name: string;
101
- type: "resource_link";
102
- description?: string | undefined;
103
- mimeType?: string | undefined;
104
- size?: number | undefined;
105
- annotations?: {
106
- audience?: ("user" | "assistant")[] | undefined;
107
- priority?: number | undefined;
108
- lastModified?: string | undefined;
109
- } | undefined;
110
- _meta?: {
111
- [x: string]: unknown;
112
- } | undefined;
113
- icons?: {
114
- src: string;
115
- mimeType?: string | undefined;
116
- sizes?: string[] | undefined;
117
- theme?: "light" | "dark" | undefined;
118
- }[] | undefined;
119
- title?: string | undefined;
120
- })[];
121
- _meta?: {
122
- [x: string]: unknown;
123
- progressToken?: string | number | undefined;
124
- "io.modelcontextprotocol/related-task"?: {
125
- taskId: string;
126
- } | undefined;
127
- } | undefined;
128
- structuredContent?: Record<string, unknown> | undefined;
129
- isError?: boolean | undefined;
130
- } | {
131
- [x: string]: unknown;
132
- toolResult: unknown;
133
- _meta?: {
134
- [x: string]: unknown;
135
- progressToken?: string | number | undefined;
136
- "io.modelcontextprotocol/related-task"?: {
137
- taskId: string;
138
- } | undefined;
139
- } | undefined;
140
- }>;
141
- readResource(params: ReadResourceRequest['params'], options?: RequestOptions): Promise<{
142
- [x: string]: unknown;
143
- contents: ({
144
- uri: string;
145
- text: string;
146
- mimeType?: string | undefined;
147
- _meta?: Record<string, unknown> | undefined;
148
- } | {
149
- uri: string;
150
- blob: string;
151
- mimeType?: string | undefined;
152
- _meta?: Record<string, unknown> | undefined;
153
- })[];
154
- _meta?: {
155
- [x: string]: unknown;
156
- progressToken?: string | number | undefined;
157
- "io.modelcontextprotocol/related-task"?: {
158
- taskId: string;
159
- } | undefined;
160
- } | undefined;
161
- }>;
162
- listTools(params?: ListToolsRequest['params'], options?: RequestOptions): Promise<{
163
- [x: string]: unknown;
164
- tools: {
165
- inputSchema: {
166
- [x: string]: unknown;
167
- type: "object";
168
- properties?: Record<string, object> | undefined;
169
- required?: string[] | undefined;
170
- };
171
- name: string;
172
- description?: string | undefined;
173
- outputSchema?: {
174
- [x: string]: unknown;
175
- type: "object";
176
- properties?: Record<string, object> | undefined;
177
- required?: string[] | undefined;
178
- } | undefined;
179
- annotations?: {
180
- title?: string | undefined;
181
- readOnlyHint?: boolean | undefined;
182
- destructiveHint?: boolean | undefined;
183
- idempotentHint?: boolean | undefined;
184
- openWorldHint?: boolean | undefined;
185
- } | undefined;
186
- execution?: {
187
- taskSupport?: "optional" | "required" | "forbidden" | undefined;
188
- } | undefined;
189
- _meta?: Record<string, unknown> | undefined;
190
- icons?: {
191
- src: string;
192
- mimeType?: string | undefined;
193
- sizes?: string[] | undefined;
194
- theme?: "light" | "dark" | undefined;
195
- }[] | undefined;
196
- title?: string | undefined;
197
- }[];
198
- _meta?: {
199
- [x: string]: unknown;
200
- progressToken?: string | number | undefined;
201
- "io.modelcontextprotocol/related-task"?: {
202
- taskId: string;
203
- } | undefined;
204
- } | undefined;
205
- nextCursor?: string | undefined;
206
- }>;
207
- listResources(params?: ListResourcesRequest['params'], options?: RequestOptions): Promise<{
208
- [x: string]: unknown;
209
- resources: {
210
- uri: string;
211
- name: string;
212
- description?: string | undefined;
213
- mimeType?: string | undefined;
214
- size?: number | undefined;
215
- annotations?: {
216
- audience?: ("user" | "assistant")[] | undefined;
217
- priority?: number | undefined;
218
- lastModified?: string | undefined;
219
- } | undefined;
220
- _meta?: {
221
- [x: string]: unknown;
222
- } | undefined;
223
- icons?: {
224
- src: string;
225
- mimeType?: string | undefined;
226
- sizes?: string[] | undefined;
227
- theme?: "light" | "dark" | undefined;
228
- }[] | undefined;
229
- title?: string | undefined;
230
- }[];
231
- _meta?: {
232
- [x: string]: unknown;
233
- progressToken?: string | number | undefined;
234
- "io.modelcontextprotocol/related-task"?: {
235
- taskId: string;
236
- } | undefined;
237
- } | undefined;
238
- nextCursor?: string | undefined;
239
- }>;
240
- listResourceTemplates(params?: ListResourceTemplatesRequest['params'], options?: RequestOptions): Promise<{
241
- [x: string]: unknown;
242
- resourceTemplates: {
243
- uriTemplate: string;
244
- name: string;
245
- description?: string | undefined;
246
- mimeType?: string | undefined;
247
- annotations?: {
248
- audience?: ("user" | "assistant")[] | undefined;
249
- priority?: number | undefined;
250
- lastModified?: string | undefined;
251
- } | undefined;
252
- _meta?: {
253
- [x: string]: unknown;
254
- } | undefined;
255
- icons?: {
256
- src: string;
257
- mimeType?: string | undefined;
258
- sizes?: string[] | undefined;
259
- theme?: "light" | "dark" | undefined;
260
- }[] | undefined;
261
- title?: string | undefined;
262
- }[];
263
- _meta?: {
264
- [x: string]: unknown;
265
- progressToken?: string | number | undefined;
266
- "io.modelcontextprotocol/related-task"?: {
267
- taskId: string;
268
- } | undefined;
269
- } | undefined;
270
- nextCursor?: string | undefined;
271
- }>;
272
- getPrompt(params: GetPromptRequest['params'], options?: RequestOptions): Promise<{
273
- [x: string]: unknown;
274
- messages: {
275
- role: "user" | "assistant";
276
- content: {
277
- type: "text";
278
- text: string;
279
- annotations?: {
280
- audience?: ("user" | "assistant")[] | undefined;
281
- priority?: number | undefined;
282
- lastModified?: string | undefined;
283
- } | undefined;
284
- _meta?: Record<string, unknown> | undefined;
285
- } | {
286
- type: "image";
287
- data: string;
288
- mimeType: string;
289
- annotations?: {
290
- audience?: ("user" | "assistant")[] | undefined;
291
- priority?: number | undefined;
292
- lastModified?: string | undefined;
293
- } | undefined;
294
- _meta?: Record<string, unknown> | undefined;
295
- } | {
296
- type: "audio";
297
- data: string;
298
- mimeType: string;
299
- annotations?: {
300
- audience?: ("user" | "assistant")[] | undefined;
301
- priority?: number | undefined;
302
- lastModified?: string | undefined;
303
- } | undefined;
304
- _meta?: Record<string, unknown> | undefined;
305
- } | {
306
- type: "resource";
307
- resource: {
308
- uri: string;
309
- text: string;
310
- mimeType?: string | undefined;
311
- _meta?: Record<string, unknown> | undefined;
312
- } | {
313
- uri: string;
314
- blob: string;
315
- mimeType?: string | undefined;
316
- _meta?: Record<string, unknown> | undefined;
317
- };
318
- annotations?: {
319
- audience?: ("user" | "assistant")[] | undefined;
320
- priority?: number | undefined;
321
- lastModified?: string | undefined;
322
- } | undefined;
323
- _meta?: Record<string, unknown> | undefined;
324
- } | {
325
- uri: string;
326
- name: string;
327
- type: "resource_link";
328
- description?: string | undefined;
329
- mimeType?: string | undefined;
330
- size?: number | undefined;
331
- annotations?: {
332
- audience?: ("user" | "assistant")[] | undefined;
333
- priority?: number | undefined;
334
- lastModified?: string | undefined;
335
- } | undefined;
336
- _meta?: {
337
- [x: string]: unknown;
338
- } | undefined;
339
- icons?: {
340
- src: string;
341
- mimeType?: string | undefined;
342
- sizes?: string[] | undefined;
343
- theme?: "light" | "dark" | undefined;
344
- }[] | undefined;
345
- title?: string | undefined;
346
- };
347
- }[];
348
- _meta?: {
349
- [x: string]: unknown;
350
- progressToken?: string | number | undefined;
351
- "io.modelcontextprotocol/related-task"?: {
352
- taskId: string;
353
- } | undefined;
354
- } | undefined;
355
- description?: string | undefined;
356
- }>;
357
- listPrompts(params?: ListPromptsRequest['params'], options?: RequestOptions): Promise<{
358
- [x: string]: unknown;
359
- prompts: {
360
- name: string;
361
- description?: string | undefined;
362
- arguments?: {
363
- name: string;
364
- description?: string | undefined;
365
- required?: boolean | undefined;
366
- }[] | undefined;
367
- _meta?: {
368
- [x: string]: unknown;
369
- } | undefined;
370
- icons?: {
371
- src: string;
372
- mimeType?: string | undefined;
373
- sizes?: string[] | undefined;
374
- theme?: "light" | "dark" | undefined;
375
- }[] | undefined;
376
- title?: string | undefined;
377
- }[];
378
- _meta?: {
379
- [x: string]: unknown;
380
- progressToken?: string | number | undefined;
381
- "io.modelcontextprotocol/related-task"?: {
382
- taskId: string;
383
- } | undefined;
384
- } | undefined;
385
- nextCursor?: string | undefined;
386
- }>;
387
- listAllTools(options?: RequestOptions): Promise<Tool[]>;
388
- listAllResources(options?: RequestOptions): Promise<Resource[]>;
389
- listAllResourceTemplates(options?: RequestOptions): Promise<ResourceTemplate[]>;
390
- listAllPrompts(options?: RequestOptions): Promise<Prompt[]>;
391
- ping(options?: RequestOptions): Promise<{
392
- _meta?: {
393
- [x: string]: unknown;
394
- progressToken?: string | number | undefined;
395
- "io.modelcontextprotocol/related-task"?: {
396
- taskId: string;
397
- } | undefined;
398
- } | undefined;
399
- }>;
400
- /**
401
- * Subscribe to updates for a resource. Successful subscriptions are remembered and
402
- * re-sent after the client reconnects.
403
- */
404
- subscribeResource(params: SubscribeRequest['params'], options?: RequestOptions): Promise<{
405
- _meta?: {
406
- [x: string]: unknown;
407
- progressToken?: string | number | undefined;
408
- "io.modelcontextprotocol/related-task"?: {
409
- taskId: string;
410
- } | undefined;
411
- } | undefined;
412
- }>;
413
- /**
414
- * Unsubscribe from a resource. The URI is always dropped from the set replayed on reconnect,
415
- * even if the request itself fails.
416
- */
417
- unsubscribeResource(params: UnsubscribeRequest['params'], options?: RequestOptions): Promise<{
418
- _meta?: {
419
- [x: string]: unknown;
420
- progressToken?: string | number | undefined;
421
- "io.modelcontextprotocol/related-task"?: {
422
- taskId: string;
423
- } | undefined;
424
- } | undefined;
425
- }>;
426
- setLoggingLevel(level: LoggingLevel, options?: RequestOptions): Promise<{
427
- _meta?: {
428
- [x: string]: unknown;
429
- progressToken?: string | number | undefined;
430
- "io.modelcontextprotocol/related-task"?: {
431
- taskId: string;
432
- } | undefined;
433
- } | undefined;
434
- }>;
435
- complete(params: CompleteRequest['params'], options?: RequestOptions): Promise<{
436
- [x: string]: unknown;
437
- completion: {
438
- [x: string]: unknown;
439
- values: string[];
440
- total?: number | undefined;
441
- hasMore?: boolean | undefined;
442
- };
443
- _meta?: {
444
- [x: string]: unknown;
445
- progressToken?: string | number | undefined;
446
- "io.modelcontextprotocol/related-task"?: {
447
- taskId: string;
448
- } | undefined;
449
- } | undefined;
450
- }>;
451
- sendRootsListChanged(): Promise<void>;
452
- /**
453
- * Register a handler for server→client `sampling/createMessage` requests.
454
- * Automatically declares the `sampling` capability. Should be called before `connect()`
455
- * so the capability is advertised during initialization.
456
- */
457
- setSamplingHandler(handler: McpSamplingHandler): void;
458
- /**
459
- * Register a handler for server→client `elicitation/create` requests.
460
- * Automatically declares the `elicitation` capability: form mode only by default, or the
461
- * modes listed in `options.modes` (e.g. `['form', 'url']` to also accept URL-mode requests).
462
- */
463
- setElicitationHandler(handler: McpElicitationHandler, options?: McpElicitationHandlerOptions): void;
464
- /**
465
- * Register a handler for server→client `roots/list` requests.
466
- * Automatically declares the `roots` capability with `listChanged: true`.
467
- */
468
- setRootsHandler(handler: McpRootsHandler): void;
469
- /**
470
- * Register a handler for a server notification method. Several handlers can be registered for
471
- * the same method; they run in registration order, each isolated from the others' errors.
472
- * Handlers the SDK installs itself (e.g. for `notifications/progress` and
473
- * `notifications/cancelled`) keep running before them. Handlers survive reconnects.
474
- */
475
- onNotification(method: string, handler: McpNotificationHandler): void;
476
- getServerCapabilities(): {
477
- experimental?: {
478
- [x: string]: object;
479
- } | undefined;
480
- logging?: object | undefined;
481
- completions?: object | undefined;
482
- prompts?: {
483
- listChanged?: boolean | undefined;
484
- } | undefined;
485
- resources?: {
486
- subscribe?: boolean | undefined;
487
- listChanged?: boolean | undefined;
488
- } | undefined;
489
- tools?: {
490
- listChanged?: boolean | undefined;
491
- } | undefined;
492
- tasks?: {
493
- [x: string]: unknown;
494
- list?: object | undefined;
495
- cancel?: object | undefined;
496
- requests?: {
497
- [x: string]: unknown;
498
- tools?: {
499
- [x: string]: unknown;
500
- call?: object | undefined;
501
- } | undefined;
502
- } | undefined;
503
- } | undefined;
504
- extensions?: {
505
- [x: string]: object;
506
- } | undefined;
507
- } | undefined;
508
- getServerVersion(): {
509
- version: string;
510
- name: string;
511
- websiteUrl?: string | undefined;
512
- description?: string | undefined;
513
- icons?: {
514
- src: string;
515
- mimeType?: string | undefined;
516
- sizes?: string[] | undefined;
517
- theme?: "light" | "dark" | undefined;
518
- }[] | undefined;
519
- title?: string | undefined;
520
- } | undefined;
521
- getInstructions(): string | undefined;
522
- /**
523
- * Record a handler-implied capability and, while not connected, register the resulting
524
- * capability on the current SDK client. User-supplied values for the same key win.
525
- */
526
- private _declareCapability;
527
- private _applySamplingHandler;
528
- private _applyElicitationHandler;
529
- private _applyRootsHandler;
530
- private _applyRequestHandlers;
531
- /**
532
- * The SDK only exposes `setNotificationHandler` with a schema carrying a literal method, so the
533
- * dispatcher is installed in its handler map directly. The handler already there (if any) is
534
- * kept and called first.
535
- */
536
- private _sdkNotificationHandlers;
537
- private _installNotificationDispatcher;
538
- private _installNotificationDispatchers;
539
- private _warnTruncated;
540
- private _connectOptions;
541
- /** Create a transport; a configured `sessionId` is only used for the very first one. */
542
- private _createTransport;
543
- private _bindTransport;
544
- private _handleTransportError;
545
- private _terminateSession;
546
- private _replaySubscriptions;
547
- private assertConnected;
548
- private handleDisconnect;
549
- /** Whether the reconnect loop started in `lifecycle` must stop. */
550
- private _reconnectCancelled;
551
- private attemptReconnect;
552
- /** One reconnection attempt with a fresh SDK client and transport; throws if it fails. */
553
- private _reconnectOnce;
554
- private _closeQuietly;
555
- private sleep;
556
- }
557
- export {};
558
- //# sourceMappingURL=mcp-client.service.d.ts.map