@nest-mcp/client 1.0.1 → 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 +139 -0
- package/README.md +845 -69
- package/dist/ai-sdk/index.d.mts +14 -0
- package/dist/ai-sdk/index.d.mts.map +1 -0
- package/dist/ai-sdk/index.mjs +27 -0
- package/dist/ai-sdk/index.mjs.map +1 -0
- package/dist/bootstrap-BIAcDnHp.d.mts +394 -0
- package/dist/bootstrap-BIAcDnHp.d.mts.map +1 -0
- package/dist/index.d.mts +480 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +1960 -0
- package/dist/index.mjs.map +1 -0
- package/dist/oauth/dynamic-registration.d.mts +92 -0
- package/dist/oauth/dynamic-registration.d.mts.map +1 -0
- package/dist/oauth/dynamic-registration.mjs +392 -0
- package/dist/oauth/dynamic-registration.mjs.map +1 -0
- package/dist/oauth/index.d.mts +422 -0
- package/dist/oauth/index.d.mts.map +1 -0
- package/dist/oauth/index.mjs +3349 -0
- package/dist/oauth/index.mjs.map +1 -0
- package/dist/scope-CxGBCDdr.mjs +22 -0
- package/dist/scope-CxGBCDdr.mjs.map +1 -0
- package/package.json +76 -50
- package/scripts/external-smoke.mjs +693 -0
- package/dist/decorators/inject-mcp-client.decorator.d.ts +0 -3
- package/dist/decorators/inject-mcp-client.decorator.js +0 -12
- package/dist/decorators/on-notification.decorator.d.ts +0 -7
- package/dist/decorators/on-notification.decorator.js +0 -13
- package/dist/health/mcp-client.health.d.ts +0 -20
- package/dist/health/mcp-client.health.js +0 -42
- package/dist/index.d.ts +0 -21
- package/dist/index.js +0 -64
- package/dist/interfaces/client-options.interface.d.ts +0 -139
- package/dist/interfaces/client-options.interface.js +0 -3
- package/dist/mcp-client.module.d.ts +0 -20
- package/dist/mcp-client.module.js +0 -188
- package/dist/mcp-client.service.d.ts +0 -558
- package/dist/mcp-client.service.js +0 -532
- package/dist/mcp-clients.service.d.ts +0 -39
- package/dist/mcp-clients.service.js +0 -104
- package/dist/testing/mock-client.d.ts +0 -67
- package/dist/testing/mock-client.js +0 -154
- package/dist/transport/apply-auth-headers.d.ts +0 -3
- package/dist/transport/apply-auth-headers.js +0 -13
- package/dist/transport/client-transport.factory.d.ts +0 -4
- package/dist/transport/client-transport.factory.js +0 -21
- package/dist/transport/sse-client.transport.d.ts +0 -4
- package/dist/transport/sse-client.transport.js +0 -15
- package/dist/transport/stdio-client.transport.d.ts +0 -4
- package/dist/transport/stdio-client.transport.js +0 -14
- package/dist/transport/streamable-client.transport.d.ts +0 -4
- package/dist/transport/streamable-client.transport.js +0 -17
- package/dist/utils/format-error-message.d.ts +0 -2
- package/dist/utils/format-error-message.js +0 -7
|
@@ -1,7 +0,0 @@
|
|
|
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
|
|
@@ -1,13 +0,0 @@
|
|
|
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
|
|
@@ -1,20 +0,0 @@
|
|
|
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
|
|
@@ -1,42 +0,0 @@
|
|
|
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
|
package/dist/index.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
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, McpElicitationHandlerOptions, McpElicitationMode, McpRootsHandler, McpClientRequestHandlerExtra, McpClientInfo, } 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 * from '@nest-mcp/common';
|
|
18
|
-
export { auth, extractWWWAuthenticateParams, discoverAuthorizationServerMetadata, discoverOAuthProtectedResourceMetadata, } from '@modelcontextprotocol/sdk/client/auth.js';
|
|
19
|
-
export type { OAuthClientProvider, AuthResult, } from '@modelcontextprotocol/sdk/client/auth.js';
|
|
20
|
-
export type { OAuthClientMetadata, OAuthTokens, AuthorizationServerMetadata, OAuthProtectedResourceMetadata, } from '@modelcontextprotocol/sdk/shared/auth.js';
|
|
21
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// @nest-mcp/client - NestJS MCP Client
|
|
3
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
-
if (k2 === undefined) k2 = k;
|
|
5
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
-
}
|
|
9
|
-
Object.defineProperty(o, k2, desc);
|
|
10
|
-
}) : (function(o, m, k, k2) {
|
|
11
|
-
if (k2 === undefined) k2 = k;
|
|
12
|
-
o[k2] = m[k];
|
|
13
|
-
}));
|
|
14
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
15
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
16
|
-
};
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
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;
|
|
19
|
-
// Module
|
|
20
|
-
var mcp_client_module_1 = require("./mcp-client.module");
|
|
21
|
-
Object.defineProperty(exports, "McpClientModule", { enumerable: true, get: function () { return mcp_client_module_1.McpClientModule; } });
|
|
22
|
-
Object.defineProperty(exports, "McpClientBootstrap", { enumerable: true, get: function () { return mcp_client_module_1.McpClientBootstrap; } });
|
|
23
|
-
// Service
|
|
24
|
-
var mcp_client_service_1 = require("./mcp-client.service");
|
|
25
|
-
Object.defineProperty(exports, "McpClient", { enumerable: true, get: function () { return mcp_client_service_1.McpClient; } });
|
|
26
|
-
var mcp_clients_service_1 = require("./mcp-clients.service");
|
|
27
|
-
Object.defineProperty(exports, "McpClientsService", { enumerable: true, get: function () { return mcp_clients_service_1.McpClientsService; } });
|
|
28
|
-
// Decorators
|
|
29
|
-
var inject_mcp_client_decorator_1 = require("./decorators/inject-mcp-client.decorator");
|
|
30
|
-
Object.defineProperty(exports, "InjectMcpClient", { enumerable: true, get: function () { return inject_mcp_client_decorator_1.InjectMcpClient; } });
|
|
31
|
-
Object.defineProperty(exports, "getMcpClientToken", { enumerable: true, get: function () { return inject_mcp_client_decorator_1.getMcpClientToken; } });
|
|
32
|
-
var on_notification_decorator_1 = require("./decorators/on-notification.decorator");
|
|
33
|
-
Object.defineProperty(exports, "OnMcpNotification", { enumerable: true, get: function () { return on_notification_decorator_1.OnMcpNotification; } });
|
|
34
|
-
Object.defineProperty(exports, "MCP_NOTIFICATION_METADATA", { enumerable: true, get: function () { return on_notification_decorator_1.MCP_NOTIFICATION_METADATA; } });
|
|
35
|
-
// Transport
|
|
36
|
-
var client_transport_factory_1 = require("./transport/client-transport.factory");
|
|
37
|
-
Object.defineProperty(exports, "createClientTransport", { enumerable: true, get: function () { return client_transport_factory_1.createClientTransport; } });
|
|
38
|
-
var streamable_client_transport_1 = require("./transport/streamable-client.transport");
|
|
39
|
-
Object.defineProperty(exports, "createStreamableHttpTransport", { enumerable: true, get: function () { return streamable_client_transport_1.createStreamableHttpTransport; } });
|
|
40
|
-
var sse_client_transport_1 = require("./transport/sse-client.transport");
|
|
41
|
-
Object.defineProperty(exports, "createSseTransport", { enumerable: true, get: function () { return sse_client_transport_1.createSseTransport; } });
|
|
42
|
-
var stdio_client_transport_1 = require("./transport/stdio-client.transport");
|
|
43
|
-
Object.defineProperty(exports, "createStdioTransport", { enumerable: true, get: function () { return stdio_client_transport_1.createStdioTransport; } });
|
|
44
|
-
var apply_auth_headers_1 = require("./transport/apply-auth-headers");
|
|
45
|
-
Object.defineProperty(exports, "applyAuthHeaders", { enumerable: true, get: function () { return apply_auth_headers_1.applyAuthHeaders; } });
|
|
46
|
-
// Utilities
|
|
47
|
-
var format_error_message_1 = require("./utils/format-error-message");
|
|
48
|
-
Object.defineProperty(exports, "formatErrorMessage", { enumerable: true, get: function () { return format_error_message_1.formatErrorMessage; } });
|
|
49
|
-
// Health
|
|
50
|
-
var mcp_client_health_1 = require("./health/mcp-client.health");
|
|
51
|
-
Object.defineProperty(exports, "McpClientHealthIndicator", { enumerable: true, get: function () { return mcp_client_health_1.McpClientHealthIndicator; } });
|
|
52
|
-
// Testing
|
|
53
|
-
var mock_client_1 = require("./testing/mock-client");
|
|
54
|
-
Object.defineProperty(exports, "MockMcpClient", { enumerable: true, get: function () { return mock_client_1.MockMcpClient; } });
|
|
55
|
-
// Re-export everything from @nest-mcp/common for convenience —
|
|
56
|
-
// users only need to install @nest-mcp/client
|
|
57
|
-
__exportStar(require("@nest-mcp/common"), exports);
|
|
58
|
-
// OAuth
|
|
59
|
-
var auth_js_1 = require("@modelcontextprotocol/sdk/client/auth.js");
|
|
60
|
-
Object.defineProperty(exports, "auth", { enumerable: true, get: function () { return auth_js_1.auth; } });
|
|
61
|
-
Object.defineProperty(exports, "extractWWWAuthenticateParams", { enumerable: true, get: function () { return auth_js_1.extractWWWAuthenticateParams; } });
|
|
62
|
-
Object.defineProperty(exports, "discoverAuthorizationServerMetadata", { enumerable: true, get: function () { return auth_js_1.discoverAuthorizationServerMetadata; } });
|
|
63
|
-
Object.defineProperty(exports, "discoverOAuthProtectedResourceMetadata", { enumerable: true, get: function () { return auth_js_1.discoverOAuthProtectedResourceMetadata; } });
|
|
64
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import type { OAuthClientProvider } from '@modelcontextprotocol/sdk/client/auth.js';
|
|
2
|
-
import type { StdioServerParameters } from '@modelcontextprotocol/sdk/client/stdio.js';
|
|
3
|
-
import type { StreamableHTTPReconnectionOptions } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
|
|
4
|
-
import type { RequestHandlerExtra } from '@modelcontextprotocol/sdk/shared/protocol.js';
|
|
5
|
-
import type { FetchLike } from '@modelcontextprotocol/sdk/shared/transport.js';
|
|
6
|
-
import type { ClientCapabilities, ClientNotification, ClientRequest, CreateMessageRequest, CreateMessageResult, ElicitRequestFormParams, ElicitRequestURLParams, ElicitResult, Implementation, ListRootsResult, Notification as McpNotification, Request as McpRequest } from '@modelcontextprotocol/sdk/types.js';
|
|
7
|
-
import type { InjectionToken, ModuleMetadata } from '@nestjs/common';
|
|
8
|
-
export type McpClientTransportType = 'streamable-http' | 'sse' | 'stdio';
|
|
9
|
-
/**
|
|
10
|
-
* Per-request context the SDK passes to server-to-client request handlers: the abort `signal`
|
|
11
|
-
* (fired when the server cancels the request), `requestId`, `_meta`, and `sendNotification` /
|
|
12
|
-
* `sendRequest` for messages related to the request being handled.
|
|
13
|
-
*/
|
|
14
|
-
export type McpClientRequestHandlerExtra = RequestHandlerExtra<ClientRequest | McpRequest, ClientNotification | McpNotification>;
|
|
15
|
-
export type McpSamplingHandler = (request: CreateMessageRequest, extra?: McpClientRequestHandlerExtra) => CreateMessageResult | Promise<CreateMessageResult>;
|
|
16
|
-
export type McpElicitationHandler = (params: ElicitRequestFormParams | ElicitRequestURLParams, extra?: McpClientRequestHandlerExtra) => ElicitResult | Promise<ElicitResult>;
|
|
17
|
-
export type McpRootsHandler = (extra?: McpClientRequestHandlerExtra) => ListRootsResult | Promise<ListRootsResult>;
|
|
18
|
-
/** Elicitation modes a client can declare support for. */
|
|
19
|
-
export type McpElicitationMode = 'form' | 'url';
|
|
20
|
-
export interface McpElicitationHandlerOptions {
|
|
21
|
-
/**
|
|
22
|
-
* Elicitation modes to advertise in the `elicitation` capability.
|
|
23
|
-
* Omitted or empty: form mode only (declared as `elicitation: {}`, the backward-compatible form).
|
|
24
|
-
* `['form', 'url']` declares `{ form: {}, url: {} }`; `['url']` declares URL mode only.
|
|
25
|
-
*/
|
|
26
|
-
modes?: McpElicitationMode[];
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* `clientInfo` sent in the `initialize` request. Every field is optional; `name` defaults to
|
|
30
|
-
* `nestjs-mcp-client-<connection name>` and `version` to `1.0.0`.
|
|
31
|
-
*/
|
|
32
|
-
export type McpClientInfo = Partial<Implementation>;
|
|
33
|
-
export interface McpClientReconnectOptions {
|
|
34
|
-
maxAttempts?: number;
|
|
35
|
-
delay?: number;
|
|
36
|
-
}
|
|
37
|
-
export interface McpClientAuthOptions {
|
|
38
|
-
type: 'bearer';
|
|
39
|
-
token: string;
|
|
40
|
-
}
|
|
41
|
-
interface McpClientConnectionBase {
|
|
42
|
-
name: string;
|
|
43
|
-
/**
|
|
44
|
-
* Timeout in milliseconds for the `initialize` handshake performed by `connect()` and by each
|
|
45
|
-
* reconnection attempt. Defaults to the SDK request timeout (60 seconds).
|
|
46
|
-
*/
|
|
47
|
-
connectTimeout?: number;
|
|
48
|
-
reconnect?: McpClientReconnectOptions;
|
|
49
|
-
/**
|
|
50
|
-
* Identity sent as `clientInfo` in the `initialize` request.
|
|
51
|
-
* Defaults to `{ name: 'nestjs-mcp-client-<connection name>', version: '1.0.0' }`.
|
|
52
|
-
*/
|
|
53
|
-
clientInfo?: McpClientInfo;
|
|
54
|
-
/**
|
|
55
|
-
* Client capabilities to advertise during the MCP initialization handshake.
|
|
56
|
-
* Merged per key with the capabilities implicitly declared by setSamplingHandler /
|
|
57
|
-
* setElicitationHandler / setRootsHandler; values set here win over those defaults.
|
|
58
|
-
*/
|
|
59
|
-
capabilities?: ClientCapabilities;
|
|
60
|
-
/**
|
|
61
|
-
* Register a handler for server-to-client `sampling/createMessage` requests.
|
|
62
|
-
* Setting this automatically declares the `sampling` client capability.
|
|
63
|
-
* Must be a stable reference (module-level function or class method) when used in forRoot options.
|
|
64
|
-
*/
|
|
65
|
-
samplingHandler?: McpSamplingHandler;
|
|
66
|
-
/**
|
|
67
|
-
* Register a handler for server-to-client `elicitation/create` requests.
|
|
68
|
-
* Setting this automatically declares the `elicitation` client capability.
|
|
69
|
-
*/
|
|
70
|
-
elicitationHandler?: McpElicitationHandler;
|
|
71
|
-
/**
|
|
72
|
-
* Elicitation modes declared for `elicitationHandler`. Defaults to form mode only.
|
|
73
|
-
* Include `'url'` to accept URL-mode elicitation requests.
|
|
74
|
-
*/
|
|
75
|
-
elicitationModes?: McpElicitationMode[];
|
|
76
|
-
/**
|
|
77
|
-
* Register a handler for server-to-client `roots/list` requests.
|
|
78
|
-
* Setting this automatically declares the `roots` client capability.
|
|
79
|
-
*/
|
|
80
|
-
rootsHandler?: McpRootsHandler;
|
|
81
|
-
}
|
|
82
|
-
export interface McpClientHttpConnectionBase extends McpClientConnectionBase {
|
|
83
|
-
url: string;
|
|
84
|
-
/**
|
|
85
|
-
* Static bearer token sent as the `Authorization` header on every request.
|
|
86
|
-
* Do not combine with `authProvider`: this header overrides the OAuth access token.
|
|
87
|
-
*/
|
|
88
|
-
auth?: McpClientAuthOptions;
|
|
89
|
-
authProvider?: OAuthClientProvider;
|
|
90
|
-
requestInit?: RequestInit;
|
|
91
|
-
/** Custom `fetch` implementation the transport uses for its HTTP requests. */
|
|
92
|
-
fetch?: FetchLike;
|
|
93
|
-
}
|
|
94
|
-
export interface McpClientStreamableHttpConnection extends McpClientHttpConnectionBase {
|
|
95
|
-
transport: 'streamable-http';
|
|
96
|
-
/**
|
|
97
|
-
* How the transport itself re-opens dropped SSE streams (the GET stream and resumable request
|
|
98
|
-
* streams). Independent of the client-level `reconnect` option.
|
|
99
|
-
*/
|
|
100
|
-
reconnectionOptions?: StreamableHTTPReconnectionOptions;
|
|
101
|
-
/**
|
|
102
|
-
* Resume an existing session instead of starting a new one. When set, the SDK skips the
|
|
103
|
-
* `initialize` handshake on the first connect, so server capabilities, server version and
|
|
104
|
-
* instructions are not available. Only used for the first connect; reconnections always
|
|
105
|
-
* start a new session.
|
|
106
|
-
*/
|
|
107
|
-
sessionId?: string;
|
|
108
|
-
}
|
|
109
|
-
export interface McpClientSseConnection extends McpClientHttpConnectionBase {
|
|
110
|
-
transport: 'sse';
|
|
111
|
-
}
|
|
112
|
-
export interface McpClientStdioConnection extends McpClientConnectionBase {
|
|
113
|
-
transport: 'stdio';
|
|
114
|
-
command: string;
|
|
115
|
-
args?: string[];
|
|
116
|
-
env?: Record<string, string>;
|
|
117
|
-
cwd?: string;
|
|
118
|
-
/**
|
|
119
|
-
* How the child process's stderr is handled. The SDK default is `'inherit'`. Use `'pipe'` to
|
|
120
|
-
* read it from the transport's `stderr` stream, or `'ignore'` to discard it.
|
|
121
|
-
*/
|
|
122
|
-
stderr?: StdioServerParameters['stderr'];
|
|
123
|
-
}
|
|
124
|
-
export type McpClientConnection = McpClientStreamableHttpConnection | McpClientSseConnection | McpClientStdioConnection;
|
|
125
|
-
export interface McpClientModuleOptions {
|
|
126
|
-
connections: McpClientConnection[];
|
|
127
|
-
}
|
|
128
|
-
export interface McpClientModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
|
|
129
|
-
useFactory: (...args: any[]) => McpClientModuleOptions | Promise<McpClientModuleOptions>;
|
|
130
|
-
inject?: InjectionToken[];
|
|
131
|
-
/**
|
|
132
|
-
* Declare connection names to enable @InjectMcpClient('name') with forRootAsync.
|
|
133
|
-
* Each name listed here creates a named provider that extracts the matching
|
|
134
|
-
* client from the connections array returned by useFactory.
|
|
135
|
-
*/
|
|
136
|
-
connectionNames?: string[];
|
|
137
|
-
}
|
|
138
|
-
export {};
|
|
139
|
-
//# sourceMappingURL=client-options.interface.d.ts.map
|
|
@@ -1,20 +0,0 @@
|
|
|
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
|
|
@@ -1,188 +0,0 @@
|
|
|
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
|
-
const descriptor = Object.getOwnPropertyDescriptor(prototype, methodName);
|
|
161
|
-
const method = descriptor?.value;
|
|
162
|
-
if (typeof method !== 'function')
|
|
163
|
-
continue;
|
|
164
|
-
// NestJS SetMetadata stores metadata on the descriptor.value (the method
|
|
165
|
-
// function itself), so we read from the method rather than using the
|
|
166
|
-
// (target, propertyKey) overload.
|
|
167
|
-
const metadata = Reflect.getMetadata(on_notification_decorator_1.MCP_NOTIFICATION_METADATA, method);
|
|
168
|
-
if (!metadata)
|
|
169
|
-
continue;
|
|
170
|
-
const client = this.clients.find((c) => c.name === metadata.connectionName);
|
|
171
|
-
if (!client) {
|
|
172
|
-
this.logger.warn(`@OnMcpNotification on ${instance.constructor.name}.${methodName}: ` +
|
|
173
|
-
`no client named "${metadata.connectionName}" found, skipping`);
|
|
174
|
-
continue;
|
|
175
|
-
}
|
|
176
|
-
const boundHandler = method.bind(instance);
|
|
177
|
-
client.onNotification(metadata.method, boundHandler);
|
|
178
|
-
wiredCount++;
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
if (wiredCount > 0) {
|
|
183
|
-
this.logger.log(`Wired ${wiredCount} @OnMcpNotification handler(s)`);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
exports.McpClientBootstrap = McpClientBootstrap;
|
|
188
|
-
//# sourceMappingURL=mcp-client.module.js.map
|