@nestjs-mcp/server 0.1.1 → 0.2.0-alpha.1

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 (106) hide show
  1. package/README.md +66 -0
  2. package/dist/controllers/sse/sse.controller.d.ts +3 -1
  3. package/dist/controllers/sse/sse.controller.js +8 -2
  4. package/dist/controllers/sse/sse.controller.js.map +1 -1
  5. package/dist/controllers/sse/sse.service.d.ts +3 -2
  6. package/dist/controllers/sse/sse.service.js +21 -6
  7. package/dist/controllers/sse/sse.service.js.map +1 -1
  8. package/dist/controllers/streamable/streamable.service.d.ts +6 -11
  9. package/dist/controllers/streamable/streamable.service.js +36 -11
  10. package/dist/controllers/streamable/streamable.service.js.map +1 -1
  11. package/dist/index.d.ts +1 -0
  12. package/dist/index.js +1 -0
  13. package/dist/index.js.map +1 -1
  14. package/dist/interfaces/capabilities.interface.d.ts +32 -2
  15. package/dist/interfaces/capabilities.interface.js +51 -0
  16. package/dist/interfaces/capabilities.interface.js.map +1 -1
  17. package/dist/interfaces/context.interface.d.ts +6 -0
  18. package/dist/interfaces/context.interface.js +3 -0
  19. package/dist/interfaces/context.interface.js.map +1 -0
  20. package/dist/interfaces/index.d.ts +2 -1
  21. package/dist/interfaces/index.js +2 -1
  22. package/dist/interfaces/index.js.map +1 -1
  23. package/dist/interfaces/mcp-server-options.interface.d.ts +2 -2
  24. package/dist/interfaces/message.types.d.ts +8 -0
  25. package/dist/interfaces/{guards.interface.js → message.types.js} +1 -1
  26. package/dist/interfaces/message.types.js.map +1 -0
  27. package/dist/mcp.module.js +13 -1
  28. package/dist/mcp.module.js.map +1 -1
  29. package/dist/registry/registry.service.d.ts +7 -1
  30. package/dist/registry/registry.service.js +72 -6
  31. package/dist/registry/registry.service.js.map +1 -1
  32. package/dist/services/index.d.ts +1 -0
  33. package/dist/services/index.js +18 -0
  34. package/dist/services/index.js.map +1 -0
  35. package/dist/services/session.manager.d.ts +14 -0
  36. package/dist/services/session.manager.js +27 -0
  37. package/dist/services/session.manager.js.map +1 -0
  38. package/dist/tsconfig.build.tsbuildinfo +1 -1
  39. package/package.json +23 -16
  40. package/.copilotignore +0 -38
  41. package/.devcontainer/Dockerfile.dev +0 -28
  42. package/.devcontainer/devcontainer.json +0 -56
  43. package/.devcontainer/docker-compose.yml +0 -15
  44. package/.dockerignore +0 -37
  45. package/.prettierrc +0 -4
  46. package/coverage/clover.xml +0 -507
  47. package/coverage/coverage-final.json +0 -19
  48. package/coverage/lcov-report/base.css +0 -224
  49. package/coverage/lcov-report/block-navigation.js +0 -87
  50. package/coverage/lcov-report/favicon.png +0 -0
  51. package/coverage/lcov-report/index.html +0 -206
  52. package/coverage/lcov-report/prettify.css +0 -1
  53. package/coverage/lcov-report/prettify.js +0 -2
  54. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  55. package/coverage/lcov-report/sorter.js +0 -196
  56. package/coverage/lcov-report/src/controllers/sse/index.html +0 -146
  57. package/coverage/lcov-report/src/controllers/sse/index.ts.html +0 -91
  58. package/coverage/lcov-report/src/controllers/sse/sse.controller.ts.html +0 -160
  59. package/coverage/lcov-report/src/controllers/sse/sse.service.ts.html +0 -403
  60. package/coverage/lcov-report/src/controllers/streamable/index.html +0 -146
  61. package/coverage/lcov-report/src/controllers/streamable/index.ts.html +0 -91
  62. package/coverage/lcov-report/src/controllers/streamable/streamable.controller.ts.html +0 -157
  63. package/coverage/lcov-report/src/controllers/streamable/streamable.service.ts.html +0 -655
  64. package/coverage/lcov-report/src/decorators/capabilities.constants.ts.html +0 -106
  65. package/coverage/lcov-report/src/decorators/capabilities.decorators.ts.html +0 -535
  66. package/coverage/lcov-report/src/decorators/index.html +0 -146
  67. package/coverage/lcov-report/src/decorators/index.ts.html +0 -91
  68. package/coverage/lcov-report/src/index.html +0 -131
  69. package/coverage/lcov-report/src/index.ts.html +0 -118
  70. package/coverage/lcov-report/src/interfaces/capabilities.interface.ts.html +0 -703
  71. package/coverage/lcov-report/src/interfaces/index.html +0 -131
  72. package/coverage/lcov-report/src/interfaces/index.ts.html +0 -91
  73. package/coverage/lcov-report/src/mcp.module.ts.html +0 -817
  74. package/coverage/lcov-report/src/registry/discovery.service.ts.html +0 -433
  75. package/coverage/lcov-report/src/registry/index.html +0 -161
  76. package/coverage/lcov-report/src/registry/index.ts.html +0 -91
  77. package/coverage/lcov-report/src/registry/logger.service.ts.html +0 -514
  78. package/coverage/lcov-report/src/registry/registry.service.ts.html +0 -1183
  79. package/coverage/lcov-report/src/services/index.html +0 -116
  80. package/coverage/lcov-report/src/services/session.manager.ts.html +0 -163
  81. package/coverage/lcov.info +0 -912
  82. package/dist/interfaces/guards.interface.d.ts +0 -4
  83. package/dist/interfaces/guards.interface.js.map +0 -1
  84. package/eslint.config.mjs +0 -40
  85. package/src/controllers/sse/index.ts +0 -2
  86. package/src/controllers/sse/sse.controller.ts +0 -25
  87. package/src/controllers/sse/sse.service.ts +0 -106
  88. package/src/controllers/streamable/index.ts +0 -2
  89. package/src/controllers/streamable/streamable.controller.ts +0 -24
  90. package/src/controllers/streamable/streamable.service.ts +0 -190
  91. package/src/decorators/capabilities.constants.ts +0 -7
  92. package/src/decorators/capabilities.decorators.ts +0 -150
  93. package/src/decorators/index.ts +0 -2
  94. package/src/index.ts +0 -11
  95. package/src/interfaces/capabilities.interface.ts +0 -206
  96. package/src/interfaces/context.interface.ts +0 -33
  97. package/src/interfaces/index.ts +0 -2
  98. package/src/interfaces/mcp-server-options.interface.ts +0 -105
  99. package/src/interfaces/message.types.ts +0 -13
  100. package/src/mcp.module.ts +0 -244
  101. package/src/mcp.service.spec.ts +0 -28
  102. package/src/registry/discovery.service.ts +0 -116
  103. package/src/registry/index.ts +0 -2
  104. package/src/registry/logger.service.ts +0 -143
  105. package/src/registry/registry.service.ts +0 -366
  106. package/src/services/session.manager.ts +0 -26
@@ -1,206 +0,0 @@
1
- import {
2
- CompleteResourceTemplateCallback,
3
- ListResourcesCallback,
4
- } from '@modelcontextprotocol/sdk/server/mcp.js';
5
- import { RequestHandlerExtra as SdkRequestHandlerExtra } from '@modelcontextprotocol/sdk/shared/protocol.js';
6
- import {
7
- ServerNotification,
8
- ServerRequest,
9
- } from '@modelcontextprotocol/sdk/types.js';
10
- import {
11
- z,
12
- ZodOptional,
13
- ZodRawShape,
14
- ZodType,
15
- ZodTypeAny,
16
- ZodTypeDef,
17
- } from 'zod';
18
-
19
- export interface ResourceBaseOptions {
20
- name: string;
21
- }
22
-
23
- export interface ResourceUriOptions extends ResourceBaseOptions {
24
- uri: string;
25
- }
26
-
27
- export interface ResourceUriWithMetadataOptions extends ResourceUriOptions {
28
- metadata: Record<string, any>;
29
- }
30
-
31
- export interface ResourceTemplateOptions extends ResourceBaseOptions {
32
- template: string;
33
- }
34
-
35
- export interface ResourceTemplateWithMetadataOptions
36
- extends ResourceTemplateOptions {
37
- metadata: Record<string, any>;
38
- }
39
-
40
- export type ResourceOptions =
41
- | ResourceUriOptions
42
- | ResourceUriWithMetadataOptions
43
- | ResourceTemplateOptions
44
- | ResourceTemplateWithMetadataOptions;
45
-
46
- export interface ToolNameOptions {
47
- name: string;
48
- }
49
-
50
- export interface ToolWithDescriptionOptions extends ToolNameOptions {
51
- description: string;
52
- }
53
-
54
- export interface ToolWithParamSchemaOptions extends ToolNameOptions {
55
- paramSchema: ZodRawShape;
56
- }
57
-
58
- export interface ToolWithDescriptionAndParamSchemaOptions
59
- extends ToolWithDescriptionOptions,
60
- ToolWithParamSchemaOptions {}
61
-
62
- export type ToolOptions =
63
- | ToolNameOptions
64
- | ToolWithDescriptionOptions
65
- | ToolWithParamSchemaOptions
66
- | ToolWithDescriptionAndParamSchemaOptions;
67
-
68
- export interface PromptBaseOptions {
69
- name: string;
70
- }
71
-
72
- export interface PromptWithDescriptionOptions extends PromptBaseOptions {
73
- description: string;
74
- }
75
-
76
- type PromptArgsRawShape = {
77
- [k: string]:
78
- | ZodType<string, ZodTypeDef, string>
79
- | ZodOptional<ZodType<string, ZodTypeDef, string>>;
80
- };
81
-
82
- export interface PromptWithArgsSchemaOptions extends PromptBaseOptions {
83
- argsSchema: PromptArgsRawShape;
84
- }
85
-
86
- export interface PromptWithDescriptionAndArgsSchemaOptions
87
- extends PromptWithDescriptionOptions,
88
- PromptWithArgsSchemaOptions {}
89
-
90
- export type PromptOptions =
91
- | PromptBaseOptions
92
- | PromptWithDescriptionOptions
93
- | PromptWithArgsSchemaOptions
94
- | PromptWithDescriptionAndArgsSchemaOptions;
95
-
96
- export interface TemplateCallbacks {
97
- /**
98
- * A callback to list all resources matching this template. This is required to specified, even if `undefined`, to avoid accidentally forgetting resource listing.
99
- */
100
- list: ListResourcesCallback | undefined;
101
- /**
102
- * An optional callback to autocomplete variables within the URI template. Useful for clients and users to discover possible values.
103
- */
104
- complete?: {
105
- [variable: string]: CompleteResourceTemplateCallback;
106
- };
107
- }
108
-
109
- export type RequestHandlerExtra = SdkRequestHandlerExtra<
110
- ServerRequest,
111
- ServerNotification
112
- >;
113
-
114
- export class ResourceUriHandlerParams {
115
- public readonly uri: URL;
116
- public readonly extra: RequestHandlerExtra;
117
-
118
- private constructor(uri: URL, extra: RequestHandlerExtra) {
119
- this.uri = uri;
120
- this.extra = extra;
121
- }
122
-
123
- static from(uri: URL, extra: RequestHandlerExtra): ResourceUriHandlerParams {
124
- return new ResourceUriHandlerParams(uri, extra);
125
- }
126
- }
127
-
128
- export class ResourceTemplateHandlerParams {
129
- public readonly uri: URL;
130
- public readonly variables?: Record<string, string>;
131
- public readonly extra: RequestHandlerExtra;
132
-
133
- private constructor(
134
- uri: URL,
135
- extra: RequestHandlerExtra,
136
- variables?: Record<string, string>,
137
- ) {
138
- this.uri = uri;
139
- this.extra = extra;
140
- this.variables = variables;
141
- }
142
-
143
- static from(
144
- uri: URL,
145
- extra: RequestHandlerExtra,
146
- variables?: Record<string, string>,
147
- ): ResourceTemplateHandlerParams {
148
- return new ResourceTemplateHandlerParams(uri, extra, variables);
149
- }
150
- }
151
-
152
- export class PromptHandlerParams<
153
- Args extends PromptArgsRawShape | undefined = undefined,
154
- > {
155
- public readonly args?: Args extends PromptArgsRawShape
156
- ? z.objectOutputType<Args, ZodTypeAny>
157
- : undefined;
158
- public readonly extra: RequestHandlerExtra;
159
-
160
- private constructor(
161
- extra: RequestHandlerExtra,
162
- args?: Args extends PromptArgsRawShape
163
- ? z.objectOutputType<Args, ZodTypeAny>
164
- : undefined,
165
- ) {
166
- this.extra = extra;
167
- this.args = args;
168
- }
169
-
170
- static from<Args extends PromptArgsRawShape | undefined>(
171
- extra: RequestHandlerExtra,
172
- args?: Args extends PromptArgsRawShape
173
- ? z.objectOutputType<Args, ZodTypeAny>
174
- : undefined,
175
- ): PromptHandlerParams<Args> {
176
- return new PromptHandlerParams<Args>(extra, args);
177
- }
178
- }
179
-
180
- export class ToolHandlerParams<
181
- Args extends ZodRawShape | undefined = undefined,
182
- > {
183
- public readonly args?: Args extends ZodRawShape
184
- ? z.objectOutputType<Args, ZodTypeAny>
185
- : undefined;
186
- public readonly extra: RequestHandlerExtra;
187
-
188
- private constructor(
189
- extra: RequestHandlerExtra,
190
- args?: Args extends ZodRawShape
191
- ? z.objectOutputType<Args, ZodTypeAny>
192
- : undefined,
193
- ) {
194
- this.extra = extra;
195
- this.args = args;
196
- }
197
-
198
- static from<Args extends ZodRawShape | undefined>(
199
- extra: RequestHandlerExtra,
200
- args?: Args extends ZodRawShape
201
- ? z.objectOutputType<Args, ZodTypeAny>
202
- : undefined,
203
- ): ToolHandlerParams<Args> {
204
- return new ToolHandlerParams<Args>(extra, args);
205
- }
206
- }
@@ -1,33 +0,0 @@
1
- import { ExecutionContext } from '@nestjs/common';
2
-
3
- import {
4
- PromptHandlerParams,
5
- ResourceTemplateHandlerParams,
6
- ResourceUriHandlerParams,
7
- ToolHandlerParams,
8
- } from './capabilities.interface';
9
- /**
10
- * Custom execution context for MCP guards.
11
- * Extends NestJS ExecutionContext and adds args for MCP method arguments.
12
- *
13
- * @property args - The arguments passed to the MCP method
14
- * @property message - The current message from the request
15
- */
16
- // TODO: Remove extends ExecutionContext we don't need it
17
- export interface McpExecutionContext extends ExecutionContext {
18
- // TODO: Remove this once the getArgs method implementation is complete.
19
- args:
20
- | ResourceUriHandlerParams
21
- | ResourceTemplateHandlerParams
22
- | PromptHandlerParams
23
- | ToolHandlerParams;
24
-
25
- // TODO: Uncomment this once the getArgs type is fixed
26
- // getArgs: () =>
27
- // | ResourceUriHandlerParams
28
- // | ResourceTemplateHandlerParams
29
- // | PromptHandlerParams
30
- // | ToolHandlerParams;
31
-
32
- getSessionId: () => string;
33
- }
@@ -1,2 +0,0 @@
1
- export * from './context.interface';
2
- export * from './mcp-server-options.interface';
@@ -1,105 +0,0 @@
1
- import { StreamableHTTPServerTransportOptions } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
2
- import { ProtocolOptions } from '@modelcontextprotocol/sdk/shared/protocol.js';
3
- import {
4
- Implementation,
5
- ServerCapabilities,
6
- } from '@modelcontextprotocol/sdk/types.js';
7
- import { Provider, Type } from '@nestjs/common';
8
-
9
- export type ServerOptions = {
10
- instructions?: string;
11
- capabilities?: ServerCapabilities;
12
- protocolOptions?: ProtocolOptions;
13
- };
14
-
15
- export type McpServerOptions = {
16
- serverInfo: Implementation;
17
- options?: ServerOptions;
18
- logging?: McpLoggingOptions;
19
- };
20
-
21
- /**
22
- * Opciones para configurar el logging del servidor MCP
23
- */
24
- export interface McpLoggingOptions {
25
- /**
26
- * Habilitar o deshabilitar el logging
27
- * @default true
28
- */
29
- enabled?: boolean;
30
-
31
- /**
32
- * Nivel de detalle del logging
33
- * @default 'verbose'
34
- */
35
- level?: 'debug' | 'verbose' | 'log' | 'warn' | 'error';
36
- }
37
-
38
- /**
39
- * Options for configuring the global MCP server module
40
- */
41
- export interface McpModuleOptions {
42
- /**
43
- * Additional modules to import
44
- */
45
- imports?: Type<any>[];
46
- /**
47
- * Providers to register in the module
48
- * These will be available globally
49
- */
50
- providers?: Provider[];
51
- /**
52
- * Name of the MCP server
53
- */
54
- name: string;
55
- /**
56
- * Version of the MCP server
57
- */
58
- version: string;
59
- /**
60
- * Description to give the AI about the server
61
- */
62
- instructions?: string;
63
- /**
64
- * Describes the server's purpose or behavior for the AI
65
- */
66
- capabilities?: ServerCapabilities;
67
- /**
68
- * Protocol-specific options
69
- */
70
- protocolOptions?: ProtocolOptions;
71
- /**
72
- * Options for configuring MCP server logging
73
- */
74
- logging?: McpLoggingOptions;
75
- /**
76
- * Options for configuring a feature module with MCP capabilities
77
- */
78
- transports?: McpModuleTransportOptions;
79
- }
80
-
81
- export type McpModuleTransportOptions = {
82
- streamable?: {
83
- enabled: boolean;
84
- /**
85
- * Streamable transport options. sessionIdGenerator is optional here, even if required in the SDK type.
86
- */
87
- options?: Omit<
88
- StreamableHTTPServerTransportOptions,
89
- 'onsessioninitialized' | 'sessionIdGenerator'
90
- > & {
91
- sessionIdGenerator?: () => string | undefined;
92
- };
93
- };
94
- sse?: {
95
- enabled: boolean;
96
- };
97
- };
98
-
99
- /**
100
- * Options for configuring a feature module with MCP capabilities
101
- */
102
- // eslint-disable-next-line @typescript-eslint/no-empty-object-type
103
- export interface McpFeatureOptions {
104
- // TODO: Maybe its needed to implement Guards for all capabilities in this module o a specific logger configuration
105
- }
@@ -1,13 +0,0 @@
1
- import {
2
- Request as ExpressRequest,
3
- Response as ExpressResponse,
4
- } from 'express';
5
-
6
- export type Request = ExpressRequest & {
7
- auth?: any;
8
- };
9
-
10
- export type McpMessage = {
11
- req: Request;
12
- res: ExpressResponse;
13
- };
package/src/mcp.module.ts DELETED
@@ -1,244 +0,0 @@
1
- import { Implementation } from '@modelcontextprotocol/sdk/types.js';
2
- import { DynamicModule, Module, Provider, Type } from '@nestjs/common';
3
- import { DiscoveryModule } from '@nestjs/core';
4
- import { AsyncLocalStorage } from 'async_hooks';
5
-
6
- import { SseController, SseService } from './controllers/sse';
7
- import {
8
- StreamableController,
9
- StreamableService,
10
- } from './controllers/streamable';
11
- import {
12
- McpFeatureOptions,
13
- McpLoggingOptions,
14
- McpModuleOptions,
15
- McpModuleTransportOptions,
16
- ServerOptions,
17
- } from './interfaces/mcp-server-options.interface';
18
- import { DiscoveryService } from './registry/discovery.service';
19
- import { McpLoggerService } from './registry/logger.service';
20
- import { RegistryService } from './registry/registry.service';
21
- import { SessionManager } from './services/session.manager';
22
- @Module({
23
- imports: [DiscoveryModule],
24
- providers: [
25
- RegistryService,
26
- DiscoveryService,
27
- {
28
- provide: AsyncLocalStorage,
29
- useValue: new AsyncLocalStorage(),
30
- },
31
- McpLoggerService,
32
- SessionManager,
33
- ],
34
- exports: [SessionManager],
35
- })
36
- export class McpModule {
37
- /**
38
- * Helper: Get active transport controllers and providers
39
- */
40
- private static getActiveTransportControllersAndProviders(
41
- transports?: McpModuleTransportOptions,
42
- ) {
43
- const controllers = new Set<Type<any>>();
44
- const providers = new Set<Provider>();
45
-
46
- // Transport configurations
47
- const STREAMABLE_TRANSPORT = {
48
- controller: StreamableController,
49
- service: StreamableService,
50
- };
51
-
52
- const SSE_TRANSPORT = {
53
- controller: SseController,
54
- service: SseService,
55
- };
56
-
57
- // Default configuration
58
- const defaultTransports: McpModuleTransportOptions = {
59
- streamable: { enabled: true },
60
- sse: { enabled: true },
61
- };
62
-
63
- // Merge default with provided transports
64
- const config = {
65
- streamable: {
66
- ...defaultTransports.streamable,
67
- ...(transports?.streamable ?? {}),
68
- },
69
- sse: {
70
- ...defaultTransports.sse,
71
- ...(transports?.sse ?? {}),
72
- },
73
- };
74
-
75
- // Add controllers and providers based on enabled transports
76
- if (config.streamable.enabled) {
77
- controllers.add(STREAMABLE_TRANSPORT.controller);
78
- providers.add(STREAMABLE_TRANSPORT.service);
79
- }
80
-
81
- if (config.sse.enabled) {
82
- controllers.add(SSE_TRANSPORT.controller);
83
- providers.add(SSE_TRANSPORT.service);
84
- }
85
-
86
- return {
87
- controllers: Array.from(controllers),
88
- providers: Array.from(providers),
89
- };
90
- }
91
-
92
- /**
93
- * Helper to build server info, options, and logging config
94
- */
95
- private static buildServerConfig(options: McpModuleOptions) {
96
- const serverInfo: Implementation = {
97
- name: options.name,
98
- version: options.version,
99
- };
100
- const serverOptions: ServerOptions = {
101
- instructions: options?.instructions,
102
- capabilities: options?.capabilities,
103
- ...(options?.protocolOptions || {}),
104
- };
105
- const loggingOptions: McpLoggingOptions = {
106
- enabled: options.logging?.enabled !== false,
107
- level: options.logging?.level || 'verbose',
108
- };
109
- return { serverInfo, serverOptions, loggingOptions };
110
- }
111
-
112
- /**
113
- * Configures the MCP module with global options
114
- *
115
- * @param options Configuration options for the MCP server
116
- * @returns Dynamic module configuration
117
- */
118
- static forRoot(options: McpModuleOptions): DynamicModule {
119
- const imports = options.imports || [];
120
- const { controllers, providers } =
121
- this.getActiveTransportControllersAndProviders(options.transports);
122
- const allProviders = [...(options.providers || []), ...providers];
123
- const { serverInfo, serverOptions, loggingOptions } =
124
- this.buildServerConfig(options);
125
- return {
126
- module: McpModule,
127
- imports,
128
- controllers,
129
- providers: [
130
- ...allProviders,
131
- {
132
- provide: 'MCP_SERVER_OPTIONS',
133
- useValue: {
134
- serverInfo,
135
- options: serverOptions,
136
- logging: loggingOptions,
137
- },
138
- },
139
- {
140
- provide: 'MCP_LOGGING_OPTIONS',
141
- useValue: loggingOptions,
142
- },
143
- {
144
- provide: 'MCP_TRANSPORT_OPTIONS',
145
- useValue: options.transports,
146
- },
147
- ],
148
- global: true,
149
- };
150
- }
151
-
152
- /**
153
- * Configures the MCP module with global options and ConfigModule support
154
- * Allows using environment variables and centralized configurations
155
- *
156
- * @param options Configuration options for the MCP server
157
- * @returns Dynamic module configuration
158
- */
159
- static forRootAsync(options: {
160
- imports?: any[];
161
- useFactory: (
162
- ...args: unknown[]
163
- ) => Promise<McpModuleOptions> | McpModuleOptions;
164
- inject?: any[];
165
- }): DynamicModule {
166
- const { imports = [], useFactory, inject = [] } = options;
167
- const safeInject = Array.isArray(inject) ? inject : [];
168
- const safeImports = Array.isArray(imports) ? imports : [];
169
- const providers = [
170
- {
171
- provide: 'MCP_SERVER_OPTIONS',
172
- useFactory: async (...args: unknown[]) => {
173
- const mcpOptions = await useFactory(...args);
174
- const { serverInfo, serverOptions, loggingOptions } =
175
- this.buildServerConfig(mcpOptions);
176
- return {
177
- serverInfo,
178
- options: serverOptions,
179
- logging: loggingOptions,
180
- };
181
- },
182
- inject: safeInject,
183
- },
184
- {
185
- provide: 'MCP_LOGGING_OPTIONS',
186
- useFactory: async (...args: unknown[]) => {
187
- const mcpOptions = await useFactory(...args);
188
- return {
189
- enabled: mcpOptions.logging?.enabled !== false,
190
- level: mcpOptions.logging?.level || 'verbose',
191
- };
192
- },
193
- inject: safeInject,
194
- },
195
- ];
196
- const asyncControllersFactory = async (...args: unknown[]) => {
197
- const mcpOptions = await useFactory(...args);
198
- return this.getActiveTransportControllersAndProviders(
199
- mcpOptions.transports,
200
- ).controllers;
201
- };
202
- const asyncProvidersFactory = async (...args: unknown[]) => {
203
- const mcpOptions = await useFactory(...args);
204
- const { providers } = this.getActiveTransportControllersAndProviders(
205
- mcpOptions.transports,
206
- );
207
- return [...(mcpOptions.providers || []), ...providers];
208
- };
209
- return {
210
- module: McpModule,
211
- imports: safeImports,
212
- controllers: [], // Will be resolved at runtime by NestJS
213
- providers: [
214
- ...providers,
215
- {
216
- provide: '__MCP_ASYNC_CONTROLLERS__',
217
- useFactory: asyncControllersFactory,
218
- inject: safeInject,
219
- },
220
- {
221
- provide: '__MCP_ASYNC_PROVIDERS__',
222
- useFactory: asyncProvidersFactory,
223
- inject: safeInject,
224
- },
225
- ],
226
- global: true,
227
- };
228
- }
229
-
230
- /**
231
- * Registers feature-specific capabilities like tools, prompts, and resources
232
- * through dedicated service providers
233
- *
234
- * @param options Configuration options for the feature module
235
- * @returns A dynamic module configuration
236
- */
237
- // TODO: Implement specific Module options
238
-
239
- static forFeature(_options?: McpFeatureOptions): DynamicModule {
240
- return {
241
- module: McpModule,
242
- };
243
- }
244
- }
@@ -1,28 +0,0 @@
1
- import { Test, TestingModule } from '@nestjs/testing';
2
-
3
- import { SseService } from './controllers/sse';
4
- import { StreamableService } from './controllers/streamable';
5
- import { McpModule } from './mcp.module';
6
- describe('NestjsMcpServerService', () => {
7
- let streamableService: StreamableService;
8
- let sseService: SseService;
9
-
10
- beforeEach(async () => {
11
- const module: TestingModule = await Test.createTestingModule({
12
- imports: [
13
- McpModule.forRoot({
14
- name: 'test',
15
- version: '1.0.0',
16
- }),
17
- ],
18
- }).compile();
19
-
20
- streamableService = module.get<StreamableService>(StreamableService);
21
- sseService = module.get<SseService>(SseService);
22
- });
23
-
24
- it('should be defined', () => {
25
- expect(streamableService).toBeDefined();
26
- expect(sseService).toBeDefined();
27
- });
28
- });