@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,67 +0,0 @@
1
- import type { Client } from '@modelcontextprotocol/sdk/client/index.js';
2
- import type { RequestOptions } from '@modelcontextprotocol/sdk/shared/protocol.js';
3
- import type { CallToolRequest, CallToolResult, CompleteRequest, CompleteResult, GetPromptRequest, GetPromptResult, Implementation, ListPromptsRequest, ListPromptsResult, ListResourceTemplatesRequest, ListResourceTemplatesResult, ListResourcesRequest, ListResourcesResult, ListToolsRequest, ListToolsResult, LoggingLevel, Prompt, ReadResourceRequest, ReadResourceResult, Resource, ResourceTemplate, ServerCapabilities, SubscribeRequest, Tool, UnsubscribeRequest } from '@modelcontextprotocol/sdk/types.js';
4
- import type { McpElicitationHandler, McpElicitationHandlerOptions, McpRootsHandler, McpSamplingHandler } from '../interfaces/client-options.interface';
5
- type PingResult = Awaited<ReturnType<Client['ping']>>;
6
- export declare class MockMcpClient {
7
- readonly name: string;
8
- private _connected;
9
- private _callToolResult;
10
- private _readResourceResult;
11
- private _listToolsResult;
12
- private _listResourcesResult;
13
- private _listResourceTemplatesResult;
14
- private _getPromptResult;
15
- private _listPromptsResult;
16
- private _completeResult;
17
- private _pingResult;
18
- private _serverCapabilities;
19
- private _serverVersion;
20
- private _instructions;
21
- private readonly _notificationHandlers;
22
- constructor(name?: string);
23
- connect(): Promise<void>;
24
- disconnect(): Promise<void>;
25
- isConnected(): boolean;
26
- callTool(_params: CallToolRequest['params'], _options?: RequestOptions): Promise<CallToolResult>;
27
- readResource(_params: ReadResourceRequest['params'], _options?: RequestOptions): Promise<ReadResourceResult>;
28
- listTools(_params?: ListToolsRequest['params'], _options?: RequestOptions): Promise<ListToolsResult>;
29
- listResources(_params?: ListResourcesRequest['params'], _options?: RequestOptions): Promise<ListResourcesResult>;
30
- listResourceTemplates(_params?: ListResourceTemplatesRequest['params'], _options?: RequestOptions): Promise<ListResourceTemplatesResult>;
31
- getPrompt(_params: GetPromptRequest['params'], _options?: RequestOptions): Promise<GetPromptResult>;
32
- listPrompts(_params?: ListPromptsRequest['params'], _options?: RequestOptions): Promise<ListPromptsResult>;
33
- listAllTools(_options?: RequestOptions): Promise<Tool[]>;
34
- listAllResources(_options?: RequestOptions): Promise<Resource[]>;
35
- listAllResourceTemplates(_options?: RequestOptions): Promise<ResourceTemplate[]>;
36
- listAllPrompts(_options?: RequestOptions): Promise<Prompt[]>;
37
- ping(_options?: RequestOptions): Promise<PingResult>;
38
- subscribeResource(_params: SubscribeRequest['params'], _options?: RequestOptions): Promise<Record<string, never>>;
39
- unsubscribeResource(_params: UnsubscribeRequest['params'], _options?: RequestOptions): Promise<Record<string, never>>;
40
- setLoggingLevel(_level: LoggingLevel, _options?: RequestOptions): Promise<Record<string, never>>;
41
- complete(_params: CompleteRequest['params'], _options?: RequestOptions): Promise<CompleteResult>;
42
- sendRootsListChanged(): Promise<void>;
43
- setSamplingHandler(_handler: McpSamplingHandler): void;
44
- setElicitationHandler(_handler: McpElicitationHandler, _options?: McpElicitationHandlerOptions): void;
45
- setRootsHandler(_handler: McpRootsHandler): void;
46
- onNotification(method: string, handler: (notification: {
47
- method: string;
48
- params?: Record<string, unknown>;
49
- }) => void | Promise<void>): void;
50
- getServerCapabilities(): ServerCapabilities | undefined;
51
- getServerVersion(): Implementation | undefined;
52
- getInstructions(): string | undefined;
53
- getClient(): Client | null;
54
- setCallToolResult(result: CallToolResult): this;
55
- setReadResourceResult(result: ReadResourceResult): this;
56
- setListToolsResult(result: ListToolsResult): this;
57
- setListResourcesResult(result: ListResourcesResult): this;
58
- setListResourceTemplatesResult(result: ListResourceTemplatesResult): this;
59
- setGetPromptResult(result: GetPromptResult): this;
60
- setListPromptsResult(result: ListPromptsResult): this;
61
- setCompleteResult(result: CompleteResult): this;
62
- setServerCapabilities(capabilities: ServerCapabilities): this;
63
- setServerVersion(version: Implementation): this;
64
- setInstructions(instructions: string): this;
65
- }
66
- export {};
67
- //# sourceMappingURL=mock-client.d.ts.map
@@ -1,154 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MockMcpClient = void 0;
4
- class MockMcpClient {
5
- name;
6
- _connected = false;
7
- _callToolResult = { content: [] };
8
- _readResourceResult = { contents: [] };
9
- _listToolsResult = { tools: [] };
10
- _listResourcesResult = { resources: [] };
11
- _listResourceTemplatesResult = { resourceTemplates: [] };
12
- _getPromptResult = { messages: [] };
13
- _listPromptsResult = { prompts: [] };
14
- _completeResult = { completion: { values: [] } };
15
- _pingResult = {};
16
- _serverCapabilities;
17
- _serverVersion;
18
- _instructions;
19
- _notificationHandlers = new Map();
20
- constructor(name = 'mock') {
21
- this.name = name;
22
- }
23
- async connect() {
24
- this._connected = true;
25
- }
26
- async disconnect() {
27
- this._connected = false;
28
- }
29
- isConnected() {
30
- return this._connected;
31
- }
32
- async callTool(_params, _options) {
33
- return this._callToolResult;
34
- }
35
- async readResource(_params, _options) {
36
- return this._readResourceResult;
37
- }
38
- async listTools(_params, _options) {
39
- return this._listToolsResult;
40
- }
41
- async listResources(_params, _options) {
42
- return this._listResourcesResult;
43
- }
44
- async listResourceTemplates(_params, _options) {
45
- return this._listResourceTemplatesResult;
46
- }
47
- async getPrompt(_params, _options) {
48
- return this._getPromptResult;
49
- }
50
- async listPrompts(_params, _options) {
51
- return this._listPromptsResult;
52
- }
53
- async listAllTools(_options) {
54
- return (this._listToolsResult.tools ?? []);
55
- }
56
- async listAllResources(_options) {
57
- return (this._listResourcesResult.resources ?? []);
58
- }
59
- async listAllResourceTemplates(_options) {
60
- return (this._listResourceTemplatesResult.resourceTemplates ?? []);
61
- }
62
- async listAllPrompts(_options) {
63
- return (this._listPromptsResult.prompts ?? []);
64
- }
65
- async ping(_options) {
66
- return this._pingResult;
67
- }
68
- async subscribeResource(_params, _options) {
69
- return {};
70
- }
71
- async unsubscribeResource(_params, _options) {
72
- return {};
73
- }
74
- async setLoggingLevel(_level, _options) {
75
- return {};
76
- }
77
- async complete(_params, _options) {
78
- return this._completeResult;
79
- }
80
- async sendRootsListChanged() {
81
- // no-op
82
- }
83
- setSamplingHandler(_handler) {
84
- // no-op in mock — handler not invoked
85
- }
86
- setElicitationHandler(_handler, _options) {
87
- // no-op in mock — handler not invoked
88
- }
89
- setRootsHandler(_handler) {
90
- // no-op in mock — handler not invoked
91
- }
92
- onNotification(method, handler) {
93
- this._notificationHandlers.set(method, handler);
94
- }
95
- getServerCapabilities() {
96
- return this._serverCapabilities;
97
- }
98
- getServerVersion() {
99
- return this._serverVersion;
100
- }
101
- getInstructions() {
102
- return this._instructions;
103
- }
104
- getClient() {
105
- return null;
106
- }
107
- // Helpers for setting mock return values
108
- setCallToolResult(result) {
109
- this._callToolResult = result;
110
- return this;
111
- }
112
- setReadResourceResult(result) {
113
- this._readResourceResult = result;
114
- return this;
115
- }
116
- setListToolsResult(result) {
117
- this._listToolsResult = result;
118
- return this;
119
- }
120
- setListResourcesResult(result) {
121
- this._listResourcesResult = result;
122
- return this;
123
- }
124
- setListResourceTemplatesResult(result) {
125
- this._listResourceTemplatesResult = result;
126
- return this;
127
- }
128
- setGetPromptResult(result) {
129
- this._getPromptResult = result;
130
- return this;
131
- }
132
- setListPromptsResult(result) {
133
- this._listPromptsResult = result;
134
- return this;
135
- }
136
- setCompleteResult(result) {
137
- this._completeResult = result;
138
- return this;
139
- }
140
- setServerCapabilities(capabilities) {
141
- this._serverCapabilities = capabilities;
142
- return this;
143
- }
144
- setServerVersion(version) {
145
- this._serverVersion = version;
146
- return this;
147
- }
148
- setInstructions(instructions) {
149
- this._instructions = instructions;
150
- return this;
151
- }
152
- }
153
- exports.MockMcpClient = MockMcpClient;
154
- //# sourceMappingURL=mock-client.js.map
@@ -1,3 +0,0 @@
1
- import type { McpClientAuthOptions } from '../interfaces/client-options.interface';
2
- export declare function applyAuthHeaders(requestInit: RequestInit | undefined, auth: McpClientAuthOptions | undefined): RequestInit;
3
- //# sourceMappingURL=apply-auth-headers.d.ts.map
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.applyAuthHeaders = applyAuthHeaders;
4
- function applyAuthHeaders(requestInit, auth) {
5
- const init = { ...(requestInit ?? {}) };
6
- if (auth) {
7
- const headers = new Headers(init.headers);
8
- headers.set('Authorization', `Bearer ${auth.token}`);
9
- init.headers = headers;
10
- }
11
- return init;
12
- }
13
- //# sourceMappingURL=apply-auth-headers.js.map
@@ -1,4 +0,0 @@
1
- import type { Transport } from '@modelcontextprotocol/sdk/shared/transport.js';
2
- import type { McpClientConnection } from '../interfaces/client-options.interface';
3
- export declare function createClientTransport(connection: McpClientConnection): Transport;
4
- //# sourceMappingURL=client-transport.factory.d.ts.map
@@ -1,21 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createClientTransport = createClientTransport;
4
- const sse_client_transport_1 = require("./sse-client.transport");
5
- const stdio_client_transport_1 = require("./stdio-client.transport");
6
- const streamable_client_transport_1 = require("./streamable-client.transport");
7
- function createClientTransport(connection) {
8
- switch (connection.transport) {
9
- case 'streamable-http':
10
- return (0, streamable_client_transport_1.createStreamableHttpTransport)(connection);
11
- case 'sse':
12
- return (0, sse_client_transport_1.createSseTransport)(connection);
13
- case 'stdio':
14
- return (0, stdio_client_transport_1.createStdioTransport)(connection);
15
- default: {
16
- const _exhaustive = connection;
17
- throw new Error(`Unsupported transport type: ${_exhaustive.transport}`);
18
- }
19
- }
20
- }
21
- //# sourceMappingURL=client-transport.factory.js.map
@@ -1,4 +0,0 @@
1
- import type { Transport } from '@modelcontextprotocol/sdk/shared/transport.js';
2
- import type { McpClientSseConnection } from '../interfaces/client-options.interface';
3
- export declare function createSseTransport(connection: McpClientSseConnection): Transport;
4
- //# sourceMappingURL=sse-client.transport.d.ts.map
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createSseTransport = createSseTransport;
4
- const sse_js_1 = require("@modelcontextprotocol/sdk/client/sse.js");
5
- const apply_auth_headers_1 = require("./apply-auth-headers");
6
- function createSseTransport(connection) {
7
- const url = new URL(connection.url);
8
- const requestInit = (0, apply_auth_headers_1.applyAuthHeaders)(connection.requestInit, connection.auth);
9
- return new sse_js_1.SSEClientTransport(url, {
10
- requestInit,
11
- authProvider: connection.authProvider,
12
- ...(connection.fetch && { fetch: connection.fetch }),
13
- });
14
- }
15
- //# sourceMappingURL=sse-client.transport.js.map
@@ -1,4 +0,0 @@
1
- import type { Transport } from '@modelcontextprotocol/sdk/shared/transport.js';
2
- import type { McpClientStdioConnection } from '../interfaces/client-options.interface';
3
- export declare function createStdioTransport(connection: McpClientStdioConnection): Transport;
4
- //# sourceMappingURL=stdio-client.transport.d.ts.map
@@ -1,14 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createStdioTransport = createStdioTransport;
4
- const stdio_js_1 = require("@modelcontextprotocol/sdk/client/stdio.js");
5
- function createStdioTransport(connection) {
6
- return new stdio_js_1.StdioClientTransport({
7
- command: connection.command,
8
- args: connection.args,
9
- env: connection.env,
10
- cwd: connection.cwd,
11
- ...(connection.stderr !== undefined && { stderr: connection.stderr }),
12
- });
13
- }
14
- //# sourceMappingURL=stdio-client.transport.js.map
@@ -1,4 +0,0 @@
1
- import type { Transport } from '@modelcontextprotocol/sdk/shared/transport.js';
2
- import type { McpClientStreamableHttpConnection } from '../interfaces/client-options.interface';
3
- export declare function createStreamableHttpTransport(connection: McpClientStreamableHttpConnection): Transport;
4
- //# sourceMappingURL=streamable-client.transport.d.ts.map
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createStreamableHttpTransport = createStreamableHttpTransport;
4
- const streamableHttp_js_1 = require("@modelcontextprotocol/sdk/client/streamableHttp.js");
5
- const apply_auth_headers_1 = require("./apply-auth-headers");
6
- function createStreamableHttpTransport(connection) {
7
- const url = new URL(connection.url);
8
- const requestInit = (0, apply_auth_headers_1.applyAuthHeaders)(connection.requestInit, connection.auth);
9
- return new streamableHttp_js_1.StreamableHTTPClientTransport(url, {
10
- requestInit,
11
- authProvider: connection.authProvider,
12
- ...(connection.fetch && { fetch: connection.fetch }),
13
- ...(connection.reconnectionOptions && { reconnectionOptions: connection.reconnectionOptions }),
14
- ...(connection.sessionId && { sessionId: connection.sessionId }),
15
- });
16
- }
17
- //# sourceMappingURL=streamable-client.transport.js.map
@@ -1,2 +0,0 @@
1
- export declare function formatErrorMessage(err: unknown): string;
2
- //# sourceMappingURL=format-error-message.d.ts.map
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.formatErrorMessage = formatErrorMessage;
4
- function formatErrorMessage(err) {
5
- return err instanceof Error ? err.message : String(err);
6
- }
7
- //# sourceMappingURL=format-error-message.js.map