@nest-mcp/client 0.1.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 (46) hide show
  1. package/dist/decorators/inject-mcp-client.decorator.d.ts +3 -0
  2. package/dist/decorators/inject-mcp-client.decorator.d.ts.map +1 -0
  3. package/dist/decorators/inject-mcp-client.decorator.js +12 -0
  4. package/dist/decorators/on-notification.decorator.d.ts +7 -0
  5. package/dist/decorators/on-notification.decorator.d.ts.map +1 -0
  6. package/dist/decorators/on-notification.decorator.js +13 -0
  7. package/dist/health/mcp-client.health.d.ts +20 -0
  8. package/dist/health/mcp-client.health.d.ts.map +1 -0
  9. package/dist/health/mcp-client.health.js +42 -0
  10. package/dist/index.d.ts +20 -0
  11. package/dist/index.d.ts.map +1 -0
  12. package/dist/index.js +47 -0
  13. package/dist/interfaces/client-options.interface.d.ts +76 -0
  14. package/dist/interfaces/client-options.interface.d.ts.map +1 -0
  15. package/dist/interfaces/client-options.interface.js +3 -0
  16. package/dist/mcp-client.module.d.ts +20 -0
  17. package/dist/mcp-client.module.d.ts.map +1 -0
  18. package/dist/mcp-client.module.js +184 -0
  19. package/dist/mcp-client.service.d.ts +490 -0
  20. package/dist/mcp-client.service.d.ts.map +1 -0
  21. package/dist/mcp-client.service.js +292 -0
  22. package/dist/mcp-clients.service.d.ts +8 -0
  23. package/dist/mcp-clients.service.d.ts.map +1 -0
  24. package/dist/mcp-clients.service.js +39 -0
  25. package/dist/testing/mock-client.d.ts +67 -0
  26. package/dist/testing/mock-client.d.ts.map +1 -0
  27. package/dist/testing/mock-client.js +154 -0
  28. package/dist/transport/apply-auth-headers.d.ts +3 -0
  29. package/dist/transport/apply-auth-headers.d.ts.map +1 -0
  30. package/dist/transport/apply-auth-headers.js +13 -0
  31. package/dist/transport/client-transport.factory.d.ts +4 -0
  32. package/dist/transport/client-transport.factory.d.ts.map +1 -0
  33. package/dist/transport/client-transport.factory.js +21 -0
  34. package/dist/transport/sse-client.transport.d.ts +4 -0
  35. package/dist/transport/sse-client.transport.d.ts.map +1 -0
  36. package/dist/transport/sse-client.transport.js +14 -0
  37. package/dist/transport/stdio-client.transport.d.ts +4 -0
  38. package/dist/transport/stdio-client.transport.d.ts.map +1 -0
  39. package/dist/transport/stdio-client.transport.js +13 -0
  40. package/dist/transport/streamable-client.transport.d.ts +4 -0
  41. package/dist/transport/streamable-client.transport.d.ts.map +1 -0
  42. package/dist/transport/streamable-client.transport.js +14 -0
  43. package/dist/utils/format-error-message.d.ts +2 -0
  44. package/dist/utils/format-error-message.d.ts.map +1 -0
  45. package/dist/utils/format-error-message.js +7 -0
  46. package/package.json +49 -0
@@ -0,0 +1,3 @@
1
+ export declare function getMcpClientToken(name: string): string;
2
+ export declare function InjectMcpClient(name: string): ParameterDecorator;
3
+ //# sourceMappingURL=inject-mcp-client.decorator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inject-mcp-client.decorator.d.ts","sourceRoot":"","sources":["../../src/decorators/inject-mcp-client.decorator.ts"],"names":[],"mappings":"AAEA,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEtD;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,kBAAkB,CAEhE"}
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getMcpClientToken = getMcpClientToken;
4
+ exports.InjectMcpClient = InjectMcpClient;
5
+ const common_1 = require("@nestjs/common");
6
+ function getMcpClientToken(name) {
7
+ return `MCP_CLIENT_${name}`;
8
+ }
9
+ function InjectMcpClient(name) {
10
+ return (0, common_1.Inject)(getMcpClientToken(name));
11
+ }
12
+ //# sourceMappingURL=inject-mcp-client.decorator.js.map
@@ -0,0 +1,7 @@
1
+ export declare const MCP_NOTIFICATION_METADATA: unique symbol;
2
+ export interface McpNotificationMetadata {
3
+ connectionName: string;
4
+ method: string;
5
+ }
6
+ export declare function OnMcpNotification(connectionName: string, method: string): MethodDecorator;
7
+ //# sourceMappingURL=on-notification.decorator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"on-notification.decorator.d.ts","sourceRoot":"","sources":["../../src/decorators/on-notification.decorator.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,yBAAyB,eAAoC,CAAC;AAE3E,MAAM,WAAW,uBAAuB;IACtC,cAAc,EAAE,MAAM,CAAC;IACvB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,wBAAgB,iBAAiB,CAAC,cAAc,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,eAAe,CAKzF"}
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MCP_NOTIFICATION_METADATA = void 0;
4
+ exports.OnMcpNotification = OnMcpNotification;
5
+ const common_1 = require("@nestjs/common");
6
+ exports.MCP_NOTIFICATION_METADATA = Symbol('mcp:client-notification');
7
+ function OnMcpNotification(connectionName, method) {
8
+ return (0, common_1.SetMetadata)(exports.MCP_NOTIFICATION_METADATA, {
9
+ connectionName,
10
+ method,
11
+ });
12
+ }
13
+ //# sourceMappingURL=on-notification.decorator.js.map
@@ -0,0 +1,20 @@
1
+ import type { McpClient } from '../mcp-client.service';
2
+ export interface McpClientHealthStatus {
3
+ name: string;
4
+ connected: boolean;
5
+ serverVersion?: {
6
+ name: string;
7
+ version: string;
8
+ };
9
+ error?: string;
10
+ }
11
+ export interface McpClientHealthResult {
12
+ status: 'up' | 'down';
13
+ connections: McpClientHealthStatus[];
14
+ }
15
+ export declare class McpClientHealthIndicator {
16
+ private readonly clients;
17
+ constructor(clients: McpClient[]);
18
+ check(): Promise<McpClientHealthResult>;
19
+ }
20
+ //# sourceMappingURL=mcp-client.health.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-client.health.d.ts","sourceRoot":"","sources":["../../src/health/mcp-client.health.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAGvD,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,OAAO,CAAC;IACnB,aAAa,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IAClD,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,qBAAqB;IACpC,MAAM,EAAE,IAAI,GAAG,MAAM,CAAC;IACtB,WAAW,EAAE,qBAAqB,EAAE,CAAC;CACtC;AAED,qBAAa,wBAAwB;IACvB,OAAO,CAAC,QAAQ,CAAC,OAAO;gBAAP,OAAO,EAAE,SAAS,EAAE;IAE3C,KAAK,IAAI,OAAO,CAAC,qBAAqB,CAAC;CAiC9C"}
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.McpClientHealthIndicator = void 0;
4
+ const format_error_message_1 = require("../utils/format-error-message");
5
+ class McpClientHealthIndicator {
6
+ clients;
7
+ constructor(clients) {
8
+ this.clients = clients;
9
+ }
10
+ async check() {
11
+ const connections = [];
12
+ for (const client of this.clients) {
13
+ if (!client.isConnected()) {
14
+ connections.push({ name: client.name, connected: false });
15
+ continue;
16
+ }
17
+ try {
18
+ await client.ping();
19
+ const version = client.getServerVersion();
20
+ connections.push({
21
+ name: client.name,
22
+ connected: true,
23
+ ...(version && { serverVersion: { name: version.name, version: version.version } }),
24
+ });
25
+ }
26
+ catch (err) {
27
+ connections.push({
28
+ name: client.name,
29
+ connected: false,
30
+ error: (0, format_error_message_1.formatErrorMessage)(err),
31
+ });
32
+ }
33
+ }
34
+ const allUp = connections.length > 0 && connections.every((c) => c.connected);
35
+ return {
36
+ status: allUp ? 'up' : 'down',
37
+ connections,
38
+ };
39
+ }
40
+ }
41
+ exports.McpClientHealthIndicator = McpClientHealthIndicator;
42
+ //# sourceMappingURL=mcp-client.health.js.map
@@ -0,0 +1,20 @@
1
+ export { McpClientModule, McpClientBootstrap } from './mcp-client.module';
2
+ export { McpClient } from './mcp-client.service';
3
+ export { McpClientsService } from './mcp-clients.service';
4
+ export { InjectMcpClient, getMcpClientToken } from './decorators/inject-mcp-client.decorator';
5
+ export { OnMcpNotification, MCP_NOTIFICATION_METADATA, } from './decorators/on-notification.decorator';
6
+ export type { McpNotificationMetadata } from './decorators/on-notification.decorator';
7
+ export type { McpClientModuleOptions, McpClientModuleAsyncOptions, McpClientConnection, McpClientHttpConnectionBase, McpClientStreamableHttpConnection, McpClientSseConnection, McpClientStdioConnection, McpClientReconnectOptions, McpClientAuthOptions, McpClientTransportType, McpSamplingHandler, McpElicitationHandler, McpRootsHandler, } from './interfaces/client-options.interface';
8
+ export { createClientTransport } from './transport/client-transport.factory';
9
+ export { createStreamableHttpTransport } from './transport/streamable-client.transport';
10
+ export { createSseTransport } from './transport/sse-client.transport';
11
+ export { createStdioTransport } from './transport/stdio-client.transport';
12
+ export { applyAuthHeaders } from './transport/apply-auth-headers';
13
+ export { formatErrorMessage } from './utils/format-error-message';
14
+ export { McpClientHealthIndicator } from './health/mcp-client.health';
15
+ export type { McpClientHealthStatus, McpClientHealthResult, } from './health/mcp-client.health';
16
+ export { MockMcpClient } from './testing/mock-client';
17
+ export { auth, extractWWWAuthenticateParams, discoverAuthorizationServerMetadata, discoverOAuthProtectedResourceMetadata, } from '@modelcontextprotocol/sdk/client/auth.js';
18
+ export type { OAuthClientProvider, AuthResult, } from '@modelcontextprotocol/sdk/client/auth.js';
19
+ export type { OAuthClientMetadata, OAuthTokens, AuthorizationServerMetadata, OAuthProtectedResourceMetadata, } from '@modelcontextprotocol/sdk/shared/auth.js';
20
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,qBAAqB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3B,8BAA8B,GAC/B,MAAM,0CAA0C,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ // @nest-mcp/client - NestJS MCP Client
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.discoverOAuthProtectedResourceMetadata = exports.discoverAuthorizationServerMetadata = exports.extractWWWAuthenticateParams = exports.auth = exports.MockMcpClient = exports.McpClientHealthIndicator = exports.formatErrorMessage = exports.applyAuthHeaders = exports.createStdioTransport = exports.createSseTransport = exports.createStreamableHttpTransport = exports.createClientTransport = exports.MCP_NOTIFICATION_METADATA = exports.OnMcpNotification = exports.getMcpClientToken = exports.InjectMcpClient = exports.McpClientsService = exports.McpClient = exports.McpClientBootstrap = exports.McpClientModule = void 0;
5
+ // Module
6
+ var mcp_client_module_1 = require("./mcp-client.module");
7
+ Object.defineProperty(exports, "McpClientModule", { enumerable: true, get: function () { return mcp_client_module_1.McpClientModule; } });
8
+ Object.defineProperty(exports, "McpClientBootstrap", { enumerable: true, get: function () { return mcp_client_module_1.McpClientBootstrap; } });
9
+ // Service
10
+ var mcp_client_service_1 = require("./mcp-client.service");
11
+ Object.defineProperty(exports, "McpClient", { enumerable: true, get: function () { return mcp_client_service_1.McpClient; } });
12
+ var mcp_clients_service_1 = require("./mcp-clients.service");
13
+ Object.defineProperty(exports, "McpClientsService", { enumerable: true, get: function () { return mcp_clients_service_1.McpClientsService; } });
14
+ // Decorators
15
+ var inject_mcp_client_decorator_1 = require("./decorators/inject-mcp-client.decorator");
16
+ Object.defineProperty(exports, "InjectMcpClient", { enumerable: true, get: function () { return inject_mcp_client_decorator_1.InjectMcpClient; } });
17
+ Object.defineProperty(exports, "getMcpClientToken", { enumerable: true, get: function () { return inject_mcp_client_decorator_1.getMcpClientToken; } });
18
+ var on_notification_decorator_1 = require("./decorators/on-notification.decorator");
19
+ Object.defineProperty(exports, "OnMcpNotification", { enumerable: true, get: function () { return on_notification_decorator_1.OnMcpNotification; } });
20
+ Object.defineProperty(exports, "MCP_NOTIFICATION_METADATA", { enumerable: true, get: function () { return on_notification_decorator_1.MCP_NOTIFICATION_METADATA; } });
21
+ // Transport
22
+ var client_transport_factory_1 = require("./transport/client-transport.factory");
23
+ Object.defineProperty(exports, "createClientTransport", { enumerable: true, get: function () { return client_transport_factory_1.createClientTransport; } });
24
+ var streamable_client_transport_1 = require("./transport/streamable-client.transport");
25
+ Object.defineProperty(exports, "createStreamableHttpTransport", { enumerable: true, get: function () { return streamable_client_transport_1.createStreamableHttpTransport; } });
26
+ var sse_client_transport_1 = require("./transport/sse-client.transport");
27
+ Object.defineProperty(exports, "createSseTransport", { enumerable: true, get: function () { return sse_client_transport_1.createSseTransport; } });
28
+ var stdio_client_transport_1 = require("./transport/stdio-client.transport");
29
+ Object.defineProperty(exports, "createStdioTransport", { enumerable: true, get: function () { return stdio_client_transport_1.createStdioTransport; } });
30
+ var apply_auth_headers_1 = require("./transport/apply-auth-headers");
31
+ Object.defineProperty(exports, "applyAuthHeaders", { enumerable: true, get: function () { return apply_auth_headers_1.applyAuthHeaders; } });
32
+ // Utilities
33
+ var format_error_message_1 = require("./utils/format-error-message");
34
+ Object.defineProperty(exports, "formatErrorMessage", { enumerable: true, get: function () { return format_error_message_1.formatErrorMessage; } });
35
+ // Health
36
+ var mcp_client_health_1 = require("./health/mcp-client.health");
37
+ Object.defineProperty(exports, "McpClientHealthIndicator", { enumerable: true, get: function () { return mcp_client_health_1.McpClientHealthIndicator; } });
38
+ // Testing
39
+ var mock_client_1 = require("./testing/mock-client");
40
+ Object.defineProperty(exports, "MockMcpClient", { enumerable: true, get: function () { return mock_client_1.MockMcpClient; } });
41
+ // OAuth
42
+ var auth_js_1 = require("@modelcontextprotocol/sdk/client/auth.js");
43
+ Object.defineProperty(exports, "auth", { enumerable: true, get: function () { return auth_js_1.auth; } });
44
+ Object.defineProperty(exports, "extractWWWAuthenticateParams", { enumerable: true, get: function () { return auth_js_1.extractWWWAuthenticateParams; } });
45
+ Object.defineProperty(exports, "discoverAuthorizationServerMetadata", { enumerable: true, get: function () { return auth_js_1.discoverAuthorizationServerMetadata; } });
46
+ Object.defineProperty(exports, "discoverOAuthProtectedResourceMetadata", { enumerable: true, get: function () { return auth_js_1.discoverOAuthProtectedResourceMetadata; } });
47
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,76 @@
1
+ import type { OAuthClientProvider } from '@modelcontextprotocol/sdk/client/auth.js';
2
+ import type { ClientCapabilities, CreateMessageRequest, CreateMessageResult, ElicitRequestFormParams, ElicitRequestURLParams, ElicitResult, ListRootsResult } from '@modelcontextprotocol/sdk/types.js';
3
+ import type { InjectionToken, ModuleMetadata } from '@nestjs/common';
4
+ export type McpClientTransportType = 'streamable-http' | 'sse' | 'stdio';
5
+ export type McpSamplingHandler = (request: CreateMessageRequest) => CreateMessageResult | Promise<CreateMessageResult>;
6
+ export type McpElicitationHandler = (params: ElicitRequestFormParams | ElicitRequestURLParams) => ElicitResult | Promise<ElicitResult>;
7
+ export type McpRootsHandler = () => ListRootsResult | Promise<ListRootsResult>;
8
+ export interface McpClientReconnectOptions {
9
+ maxAttempts?: number;
10
+ delay?: number;
11
+ }
12
+ export interface McpClientAuthOptions {
13
+ type: 'bearer';
14
+ token: string;
15
+ }
16
+ interface McpClientConnectionBase {
17
+ name: string;
18
+ connectTimeout?: number;
19
+ reconnect?: McpClientReconnectOptions;
20
+ /**
21
+ * Client capabilities to advertise during the MCP initialization handshake.
22
+ * Merged with any capabilities implicitly declared by setSamplingHandler / setElicitationHandler / setRootsHandler.
23
+ */
24
+ capabilities?: ClientCapabilities;
25
+ /**
26
+ * Register a handler for server-to-client `sampling/createMessage` requests.
27
+ * Setting this automatically declares the `sampling` client capability.
28
+ * Must be a stable reference (module-level function or class method) when used in forRoot options.
29
+ */
30
+ samplingHandler?: McpSamplingHandler;
31
+ /**
32
+ * Register a handler for server-to-client `elicitation/create` requests.
33
+ * Setting this automatically declares the `elicitation` client capability.
34
+ */
35
+ elicitationHandler?: McpElicitationHandler;
36
+ /**
37
+ * Register a handler for server-to-client `roots/list` requests.
38
+ * Setting this automatically declares the `roots` client capability.
39
+ */
40
+ rootsHandler?: McpRootsHandler;
41
+ }
42
+ export interface McpClientHttpConnectionBase extends McpClientConnectionBase {
43
+ url: string;
44
+ auth?: McpClientAuthOptions;
45
+ authProvider?: OAuthClientProvider;
46
+ requestInit?: RequestInit;
47
+ }
48
+ export interface McpClientStreamableHttpConnection extends McpClientHttpConnectionBase {
49
+ transport: 'streamable-http';
50
+ }
51
+ export interface McpClientSseConnection extends McpClientHttpConnectionBase {
52
+ transport: 'sse';
53
+ }
54
+ export interface McpClientStdioConnection extends McpClientConnectionBase {
55
+ transport: 'stdio';
56
+ command: string;
57
+ args?: string[];
58
+ env?: Record<string, string>;
59
+ cwd?: string;
60
+ }
61
+ export type McpClientConnection = McpClientStreamableHttpConnection | McpClientSseConnection | McpClientStdioConnection;
62
+ export interface McpClientModuleOptions {
63
+ connections: McpClientConnection[];
64
+ }
65
+ export interface McpClientModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
66
+ useFactory: (...args: any[]) => McpClientModuleOptions | Promise<McpClientModuleOptions>;
67
+ inject?: InjectionToken[];
68
+ /**
69
+ * Declare connection names to enable @InjectMcpClient('name') with forRootAsync.
70
+ * Each name listed here creates a named provider that extracts the matching
71
+ * client from the connections array returned by useFactory.
72
+ */
73
+ connectionNames?: string[];
74
+ }
75
+ export {};
76
+ //# sourceMappingURL=client-options.interface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client-options.interface.d.ts","sourceRoot":"","sources":["../../src/interfaces/client-options.interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0CAA0C,CAAC;AACpF,OAAO,KAAK,EACV,kBAAkB,EAClB,oBAAoB,EACpB,mBAAmB,EACnB,uBAAuB,EACvB,sBAAsB,EACtB,YAAY,EACZ,eAAe,EAChB,MAAM,oCAAoC,CAAC;AAC5C,OAAO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,iBAAiB,CAAC;CAC9B;AAED,MAAM,WAAW,sBAAuB,SAAQ,2BAA2B;IACzE,SAAS,EAAE,KAAK,CAAC;CAClB;AAED,MAAM,WAAW,wBAAyB,SAAQ,uBAAuB;IACvE,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,MAAM,mBAAmB,GAC3B,iCAAiC,GACjC,sBAAsB,GACtB,wBAAwB,CAAC;AAE7B,MAAM,WAAW,sBAAsB;IACrC,WAAW,EAAE,mBAAmB,EAAE,CAAC;CACpC;AAED,MAAM,WAAW,2BAA4B,SAAQ,IAAI,CAAC,cAAc,EAAE,SAAS,CAAC;IAElF,UAAU,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,sBAAsB,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAAC;IACzF,MAAM,CAAC,EAAE,cAAc,EAAE,CAAC;IAC1B;;;;OAIG;IACH,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;CAC5B"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=client-options.interface.js.map
@@ -0,0 +1,20 @@
1
+ import { type DynamicModule, type OnApplicationBootstrap, type OnApplicationShutdown } from '@nestjs/common';
2
+ import { ModulesContainer } from '@nestjs/core';
3
+ import type { McpClientModuleAsyncOptions, McpClientModuleOptions } from './interfaces/client-options.interface';
4
+ import { McpClient } from './mcp-client.service';
5
+ export declare class McpClientModule {
6
+ private static readonly logger;
7
+ static forRoot(options: McpClientModuleOptions): DynamicModule;
8
+ static forRootAsync(options: McpClientModuleAsyncOptions): DynamicModule;
9
+ private static createConnectionProviders;
10
+ }
11
+ export declare class McpClientBootstrap implements OnApplicationBootstrap, OnApplicationShutdown {
12
+ private readonly modulesContainer?;
13
+ private readonly logger;
14
+ private readonly clients;
15
+ constructor(clients: McpClient[], modulesContainer?: ModulesContainer | undefined);
16
+ onApplicationBootstrap(): Promise<void>;
17
+ onApplicationShutdown(): Promise<void>;
18
+ private wireNotificationHandlers;
19
+ }
20
+ //# sourceMappingURL=mcp-client.module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-client.module.d.ts","sourceRoot":"","sources":["../src/mcp-client.module.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,aAAa,EAGlB,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,EAC3B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAMhD,OAAO,KAAK,EACV,2BAA2B,EAC3B,sBAAsB,EACvB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAGjD,qBAEa,eAAe;IAC1B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAiC;IAE/D,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,sBAAsB,GAAG,aAAa;IAkC9D,MAAM,CAAC,YAAY,CAAC,OAAO,EAAE,2BAA2B,GAAG,aAAa;IAgExE,OAAO,CAAC,MAAM,CAAC,yBAAyB;CAMzC;AAED,qBAAa,kBAAmB,YAAW,sBAAsB,EAAE,qBAAqB;IAMpF,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAC;IALpC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAoC;IAC3D,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAmB;gBAGzC,OAAO,EAAE,SAAS,EAAE,EACH,gBAAgB,CAAC,EAAE,gBAAgB,YAAA;IAKhD,sBAAsB,IAAI,OAAO,CAAC,IAAI,CAAC;IAcvC,qBAAqB,IAAI,OAAO,CAAC,IAAI,CAAC;IAa5C,OAAO,CAAC,wBAAwB;CAgDjC"}
@@ -0,0 +1,184 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var McpClientModule_1;
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.McpClientBootstrap = exports.McpClientModule = void 0;
11
+ const common_1 = require("@nest-mcp/common");
12
+ const common_2 = require("@nestjs/common");
13
+ const core_1 = require("@nestjs/core");
14
+ const inject_mcp_client_decorator_1 = require("./decorators/inject-mcp-client.decorator");
15
+ const on_notification_decorator_1 = require("./decorators/on-notification.decorator");
16
+ const mcp_client_service_1 = require("./mcp-client.service");
17
+ const mcp_clients_service_1 = require("./mcp-clients.service");
18
+ let McpClientModule = class McpClientModule {
19
+ static { McpClientModule_1 = this; }
20
+ static logger = new common_2.Logger('McpClientModule');
21
+ static forRoot(options) {
22
+ const connectionProviders = McpClientModule_1.createConnectionProviders(options);
23
+ const connectionsAggregateProvider = {
24
+ provide: 'MCP_CLIENT_CONNECTIONS',
25
+ useFactory: (...clients) => clients,
26
+ inject: connectionProviders.map((p) => p.provide),
27
+ };
28
+ const bootstrapProvider = {
29
+ provide: McpClientBootstrap,
30
+ useFactory: (clients, modulesContainer) => new McpClientBootstrap(clients, modulesContainer),
31
+ inject: ['MCP_CLIENT_CONNECTIONS', core_1.ModulesContainer],
32
+ };
33
+ return {
34
+ module: McpClientModule_1,
35
+ global: true,
36
+ providers: [
37
+ { provide: common_1.MCP_CLIENT_OPTIONS, useValue: options },
38
+ ...connectionProviders,
39
+ connectionsAggregateProvider,
40
+ bootstrapProvider,
41
+ mcp_clients_service_1.McpClientsService,
42
+ ],
43
+ exports: [
44
+ common_1.MCP_CLIENT_OPTIONS,
45
+ ...connectionProviders.map((p) => p.provide),
46
+ mcp_clients_service_1.McpClientsService,
47
+ ],
48
+ };
49
+ }
50
+ static forRootAsync(options) {
51
+ const asyncOptionsProvider = {
52
+ provide: common_1.MCP_CLIENT_OPTIONS,
53
+ useFactory: options.useFactory,
54
+ inject: options.inject ?? [],
55
+ };
56
+ const connectionsProvider = {
57
+ provide: 'MCP_CLIENT_CONNECTIONS',
58
+ useFactory: async (opts) => {
59
+ const clients = [];
60
+ for (const conn of opts.connections) {
61
+ const client = new mcp_client_service_1.McpClient(conn.name, conn);
62
+ clients.push(client);
63
+ }
64
+ return clients;
65
+ },
66
+ inject: [common_1.MCP_CLIENT_OPTIONS],
67
+ };
68
+ const bootstrapProvider = {
69
+ provide: McpClientBootstrap,
70
+ useFactory: (clients, modulesContainer) => new McpClientBootstrap(clients, modulesContainer),
71
+ inject: ['MCP_CLIENT_CONNECTIONS', core_1.ModulesContainer],
72
+ };
73
+ // When using forRootAsync, connection names are resolved at runtime.
74
+ // Use @Inject('MCP_CLIENT_CONNECTIONS') and find clients by name,
75
+ // or use the connectionNames option to enable @InjectMcpClient('name').
76
+ const namedProviders = (options.connectionNames ?? []).map((name) => ({
77
+ provide: (0, inject_mcp_client_decorator_1.getMcpClientToken)(name),
78
+ useFactory: (clients) => {
79
+ const client = clients.find((c) => c.name === name);
80
+ if (!client) {
81
+ throw new Error(`McpClientModule: No connection named "${name}" found. Ensure the name matches a connection in the factory options.`);
82
+ }
83
+ return client;
84
+ },
85
+ inject: ['MCP_CLIENT_CONNECTIONS'],
86
+ }));
87
+ return {
88
+ module: McpClientModule_1,
89
+ global: true,
90
+ imports: options.imports ?? [],
91
+ providers: [
92
+ asyncOptionsProvider,
93
+ connectionsProvider,
94
+ ...namedProviders,
95
+ bootstrapProvider,
96
+ mcp_clients_service_1.McpClientsService,
97
+ ],
98
+ exports: [
99
+ common_1.MCP_CLIENT_OPTIONS,
100
+ connectionsProvider.provide,
101
+ ...namedProviders.map((p) => p.provide),
102
+ mcp_clients_service_1.McpClientsService,
103
+ ],
104
+ };
105
+ }
106
+ static createConnectionProviders(options) {
107
+ return options.connections.map((connection) => ({
108
+ provide: (0, inject_mcp_client_decorator_1.getMcpClientToken)(connection.name),
109
+ useFactory: () => new mcp_client_service_1.McpClient(connection.name, connection),
110
+ }));
111
+ }
112
+ };
113
+ exports.McpClientModule = McpClientModule;
114
+ exports.McpClientModule = McpClientModule = McpClientModule_1 = __decorate([
115
+ (0, common_2.Module)({})
116
+ // biome-ignore lint/complexity/noStaticOnlyClass: NestJS requires module classes for DI
117
+ ], McpClientModule);
118
+ class McpClientBootstrap {
119
+ modulesContainer;
120
+ logger = new common_2.Logger('McpClientBootstrap');
121
+ clients = [];
122
+ constructor(clients, modulesContainer) {
123
+ this.modulesContainer = modulesContainer;
124
+ this.clients = clients;
125
+ }
126
+ async onApplicationBootstrap() {
127
+ for (const client of this.clients) {
128
+ try {
129
+ await client.connect();
130
+ }
131
+ catch (err) {
132
+ this.logger.error(`Failed to connect client "${client.name}": ${err instanceof Error ? err.message : String(err)}`);
133
+ }
134
+ }
135
+ this.wireNotificationHandlers();
136
+ }
137
+ async onApplicationShutdown() {
138
+ for (const client of this.clients) {
139
+ try {
140
+ await client.disconnect();
141
+ }
142
+ catch (err) {
143
+ this.logger.error(`Failed to disconnect client "${client.name}": ${err instanceof Error ? err.message : String(err)}`);
144
+ }
145
+ }
146
+ }
147
+ // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: nested iteration over NestJS module/provider graph is inherently complex
148
+ wireNotificationHandlers() {
149
+ if (!this.modulesContainer)
150
+ return;
151
+ let wiredCount = 0;
152
+ for (const [, moduleRef] of this.modulesContainer) {
153
+ for (const [, wrapper] of moduleRef.providers) {
154
+ const instance = wrapper?.instance;
155
+ if (!instance || !instance.constructor)
156
+ continue;
157
+ const prototype = Object.getPrototypeOf(instance);
158
+ const methodNames = Object.getOwnPropertyNames(prototype).filter((name) => name !== 'constructor');
159
+ for (const methodName of methodNames) {
160
+ // NestJS SetMetadata stores metadata on the descriptor.value (the method
161
+ // function itself), so we read from prototype[methodName] rather than
162
+ // using the (target, propertyKey) overload.
163
+ const metadata = Reflect.getMetadata(on_notification_decorator_1.MCP_NOTIFICATION_METADATA, prototype[methodName]);
164
+ if (!metadata)
165
+ continue;
166
+ const client = this.clients.find((c) => c.name === metadata.connectionName);
167
+ if (!client) {
168
+ this.logger.warn(`@OnMcpNotification on ${instance.constructor.name}.${methodName}: ` +
169
+ `no client named "${metadata.connectionName}" found, skipping`);
170
+ continue;
171
+ }
172
+ const boundHandler = instance[methodName].bind(instance);
173
+ client.onNotification(metadata.method, boundHandler);
174
+ wiredCount++;
175
+ }
176
+ }
177
+ }
178
+ if (wiredCount > 0) {
179
+ this.logger.log(`Wired ${wiredCount} @OnMcpNotification handler(s)`);
180
+ }
181
+ }
182
+ }
183
+ exports.McpClientBootstrap = McpClientBootstrap;
184
+ //# sourceMappingURL=mcp-client.module.js.map