@rekog/mcp-nest 1.5.0-beta.0 → 1.5.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 (94) hide show
  1. package/.idea/codeStyles/Project.xml +59 -0
  2. package/.idea/codeStyles/codeStyleConfig.xml +5 -0
  3. package/.idea/inspectionProfiles/Project_Default.xml +6 -0
  4. package/.idea/modules.xml +8 -0
  5. package/.idea/nest-mcp.iml +12 -0
  6. package/.idea/vcs.xml +6 -0
  7. package/README.md +100 -18
  8. package/coverage/clover.xml +310 -212
  9. package/coverage/coverage-final.json +11 -10
  10. package/coverage/lcov-report/decorators/constants.ts.html +4 -4
  11. package/coverage/lcov-report/decorators/index.html +1 -1
  12. package/coverage/lcov-report/decorators/index.ts.html +5 -5
  13. package/coverage/lcov-report/decorators/prompt.decorator.ts.html +17 -5
  14. package/coverage/lcov-report/decorators/resource.decorator.ts.html +21 -6
  15. package/coverage/lcov-report/decorators/tool.decorator.ts.html +6 -6
  16. package/coverage/lcov-report/index.html +50 -50
  17. package/coverage/lcov-report/services/handlers/index.html +161 -0
  18. package/coverage/lcov-report/services/handlers/mcp-handler.base.ts.html +421 -0
  19. package/coverage/lcov-report/services/handlers/mcp-prompts.handler.ts.html +385 -0
  20. package/coverage/lcov-report/services/handlers/mcp-resources.handler.ts.html +361 -0
  21. package/coverage/lcov-report/services/handlers/mcp-tools.handler.ts.html +355 -0
  22. package/coverage/lcov-report/services/index.html +49 -19
  23. package/coverage/lcov-report/services/mcp-executor.service.ts.html +199 -0
  24. package/coverage/lcov-report/services/mcp-registry.service.ts.html +27 -15
  25. package/coverage/lcov-report/services/sse-ping.service.ts.html +499 -0
  26. package/coverage/lcov-report/tests/index.html +7 -7
  27. package/coverage/lcov-report/tests/utils.ts.html +115 -7
  28. package/coverage/lcov-report/transport/index.html +131 -0
  29. package/coverage/lcov-report/transport/sse.controller.factory.ts.html +532 -0
  30. package/coverage/lcov-report/transport/streamable-http.controller.factory.ts.html +1258 -0
  31. package/coverage/lcov.info +538 -365
  32. package/dist/decorators/prompt.decorator.d.ts +5 -1
  33. package/dist/decorators/prompt.decorator.d.ts.map +1 -1
  34. package/dist/decorators/prompt.decorator.js.map +1 -1
  35. package/dist/decorators/resource.decorator.d.ts +7 -2
  36. package/dist/decorators/resource.decorator.d.ts.map +1 -1
  37. package/dist/decorators/resource.decorator.js.map +1 -1
  38. package/dist/decorators/tool.decorator.d.ts +1 -1
  39. package/dist/decorators/tool.decorator.d.ts.map +1 -1
  40. package/dist/interfaces/mcp-options.interface.d.ts +6 -14
  41. package/dist/interfaces/mcp-options.interface.d.ts.map +1 -1
  42. package/dist/interfaces/mcp-options.interface.js +1 -1
  43. package/dist/interfaces/mcp-options.interface.js.map +1 -1
  44. package/dist/mcp.module.d.ts.map +1 -1
  45. package/dist/mcp.module.js +42 -12
  46. package/dist/mcp.module.js.map +1 -1
  47. package/dist/services/handlers/mcp-handler.base.d.ts +2 -1
  48. package/dist/services/handlers/mcp-handler.base.d.ts.map +1 -1
  49. package/dist/services/handlers/mcp-handler.base.js +27 -0
  50. package/dist/services/handlers/mcp-handler.base.js.map +1 -1
  51. package/dist/services/handlers/mcp-tools.handler.d.ts +1 -1
  52. package/dist/services/handlers/mcp-tools.handler.d.ts.map +1 -1
  53. package/dist/services/handlers/mcp-tools.handler.js +1 -1
  54. package/dist/services/handlers/mcp-tools.handler.js.map +1 -1
  55. package/dist/services/mcp-registry.service.d.ts +2 -2
  56. package/dist/services/mcp-registry.service.d.ts.map +1 -1
  57. package/dist/services/mcp-registry.service.js +3 -0
  58. package/dist/services/mcp-registry.service.js.map +1 -1
  59. package/dist/stdio.js +76070 -0
  60. package/dist/transport/custom-decorator.spec.d.ts +2 -0
  61. package/dist/transport/custom-decorator.spec.d.ts.map +1 -0
  62. package/dist/transport/custom-decorator.spec.js +34 -0
  63. package/dist/transport/custom-decorator.spec.js.map +1 -0
  64. package/dist/transport/sse.controller.factory.d.ts +23 -0
  65. package/dist/transport/sse.controller.factory.d.ts.map +1 -0
  66. package/dist/transport/sse.controller.factory.js +107 -0
  67. package/dist/transport/sse.controller.factory.js.map +1 -0
  68. package/dist/transport/stdio.service.d.ts +11 -0
  69. package/dist/transport/stdio.service.d.ts.map +1 -0
  70. package/dist/transport/stdio.service.js +56 -0
  71. package/dist/transport/stdio.service.js.map +1 -0
  72. package/dist/transport/streamable-http.controller.factory.d.ts +34 -0
  73. package/dist/transport/streamable-http.controller.factory.d.ts.map +1 -0
  74. package/dist/transport/streamable-http.controller.factory.js +282 -0
  75. package/dist/transport/streamable-http.controller.factory.js.map +1 -0
  76. package/package.json +7 -3
  77. package/playground/README.md +11 -3
  78. package/playground/clients/http-sse.ts +82 -0
  79. package/playground/{http-streamable-client.ts → clients/http-streamable-client.ts} +9 -6
  80. package/playground/clients/stdio-client.ts +95 -0
  81. package/playground/{greeting.prompt.ts → resources/greeting.prompt.ts} +1 -1
  82. package/playground/{greeting.resource.ts → resources/greeting.resource.ts} +1 -1
  83. package/playground/{greeting.tool.ts → resources/greeting.tool.ts} +2 -2
  84. package/playground/servers/server-stateful.ts +32 -0
  85. package/playground/{server.ts → servers/server-stateless.ts} +5 -8
  86. package/playground/servers/stdio.ts +27 -0
  87. package/tests/mcp-prompt.e2e.spec.ts +4 -4
  88. package/tests/mcp-resource.e2e.spec.ts +5 -5
  89. package/tests/mcp-tool-auth.e2e.spec.ts +4 -4
  90. package/tests/mcp-tool.e2e.spec.ts +23 -8
  91. package/tests/mcp.version.e2e.spec.ts +2 -2
  92. package/tests/sample/stdio-server.ts +158 -0
  93. package/tests/utils.ts +38 -2
  94. package/tsconfig.build.tsbuildinfo +1 -1
@@ -0,0 +1,59 @@
1
+ <component name="ProjectCodeStyleConfiguration">
2
+ <code_scheme name="Project" version="173">
3
+ <HTMLCodeStyleSettings>
4
+ <option name="HTML_SPACE_INSIDE_EMPTY_TAG" value="true" />
5
+ </HTMLCodeStyleSettings>
6
+ <JSCodeStyleSettings version="0">
7
+ <option name="FORCE_SEMICOLON_STYLE" value="true" />
8
+ <option name="SPACE_BEFORE_FUNCTION_LEFT_PARENTH" value="false" />
9
+ <option name="USE_DOUBLE_QUOTES" value="false" />
10
+ <option name="FORCE_QUOTE_STYlE" value="true" />
11
+ <option name="ENFORCE_TRAILING_COMMA" value="WhenMultiline" />
12
+ <option name="SPACES_WITHIN_OBJECT_LITERAL_BRACES" value="true" />
13
+ <option name="SPACES_WITHIN_IMPORTS" value="true" />
14
+ </JSCodeStyleSettings>
15
+ <TypeScriptCodeStyleSettings version="0">
16
+ <option name="FORCE_SEMICOLON_STYLE" value="true" />
17
+ <option name="SPACE_BEFORE_FUNCTION_LEFT_PARENTH" value="false" />
18
+ <option name="USE_DOUBLE_QUOTES" value="false" />
19
+ <option name="FORCE_QUOTE_STYlE" value="true" />
20
+ <option name="ENFORCE_TRAILING_COMMA" value="WhenMultiline" />
21
+ <option name="SPACES_WITHIN_OBJECT_LITERAL_BRACES" value="true" />
22
+ <option name="SPACES_WITHIN_IMPORTS" value="true" />
23
+ </TypeScriptCodeStyleSettings>
24
+ <VueCodeStyleSettings>
25
+ <option name="INTERPOLATION_NEW_LINE_AFTER_START_DELIMITER" value="false" />
26
+ <option name="INTERPOLATION_NEW_LINE_BEFORE_END_DELIMITER" value="false" />
27
+ </VueCodeStyleSettings>
28
+ <codeStyleSettings language="HTML">
29
+ <option name="SOFT_MARGINS" value="80" />
30
+ <indentOptions>
31
+ <option name="INDENT_SIZE" value="2" />
32
+ <option name="CONTINUATION_INDENT_SIZE" value="2" />
33
+ <option name="TAB_SIZE" value="2" />
34
+ </indentOptions>
35
+ </codeStyleSettings>
36
+ <codeStyleSettings language="JavaScript">
37
+ <option name="SOFT_MARGINS" value="80" />
38
+ <indentOptions>
39
+ <option name="INDENT_SIZE" value="2" />
40
+ <option name="CONTINUATION_INDENT_SIZE" value="2" />
41
+ <option name="TAB_SIZE" value="2" />
42
+ </indentOptions>
43
+ </codeStyleSettings>
44
+ <codeStyleSettings language="TypeScript">
45
+ <option name="SOFT_MARGINS" value="80" />
46
+ <indentOptions>
47
+ <option name="INDENT_SIZE" value="2" />
48
+ <option name="CONTINUATION_INDENT_SIZE" value="2" />
49
+ <option name="TAB_SIZE" value="2" />
50
+ </indentOptions>
51
+ </codeStyleSettings>
52
+ <codeStyleSettings language="Vue">
53
+ <option name="SOFT_MARGINS" value="80" />
54
+ <indentOptions>
55
+ <option name="CONTINUATION_INDENT_SIZE" value="2" />
56
+ </indentOptions>
57
+ </codeStyleSettings>
58
+ </code_scheme>
59
+ </component>
@@ -0,0 +1,5 @@
1
+ <component name="ProjectCodeStyleConfiguration">
2
+ <state>
3
+ <option name="USE_PER_PROJECT_SETTINGS" value="true" />
4
+ </state>
5
+ </component>
@@ -0,0 +1,6 @@
1
+ <component name="InspectionProjectProfileManager">
2
+ <profile version="1.0">
3
+ <option name="myName" value="Project Default" />
4
+ <inspection_tool class="Eslint" enabled="true" level="WARNING" enabled_by_default="true" />
5
+ </profile>
6
+ </component>
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/nest-mcp.iml" filepath="$PROJECT_DIR$/.idea/nest-mcp.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
@@ -0,0 +1,12 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="WEB_MODULE" version="4">
3
+ <component name="NewModuleRootManager">
4
+ <content url="file://$MODULE_DIR$">
5
+ <excludeFolder url="file://$MODULE_DIR$/.tmp" />
6
+ <excludeFolder url="file://$MODULE_DIR$/temp" />
7
+ <excludeFolder url="file://$MODULE_DIR$/tmp" />
8
+ </content>
9
+ <orderEntry type="inheritedJdk" />
10
+ <orderEntry type="sourceFolder" forTests="false" />
11
+ </component>
12
+ </module>
package/.idea/vcs.xml ADDED
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="" vcs="Git" />
5
+ </component>
6
+ </project>
package/README.md CHANGED
@@ -12,16 +12,18 @@
12
12
 
13
13
  A NestJS module to effortlessly expose tools, resources, and prompts for AI, from your NestJS applications using the **Model Context Protocol (MCP)**.
14
14
 
15
- `@rekog/mcp-nest` handles the complexity of setting up MCP servers. You define tools, resources, and prompts in a way that's familiar in NestJS and leverage the full power of dependency injection to utilize your existing services.
15
+ with `@rekog/mcp-nest` you define tools, resources, and prompts in a way that's familiar in NestJS and leverage the full power of dependency injection to utilize your existing codebase in building complex enterprise ready MCP servers.
16
16
 
17
17
  ## Features
18
18
 
19
- - 🚀 HTTP+SSE and Streamable HTTP Transport
19
+ - 🚀 Support for all Transport Types:
20
+ - Streamable HTTP
21
+ - HTTP+SSE
22
+ - STDIO
20
23
  - 🔍 Automatic `tool`, `resource`, and `prompt` discovery and registration
21
- - 💯 Zod-based request validation
24
+ - 💯 Zod-based tool call validation
22
25
  - 📊 Progress notifications
23
26
  - 🔒 Guard-based authentication
24
- - ⏱️ Automatic SSE ping to maintain long connections
25
27
 
26
28
  ## Installation
27
29
 
@@ -114,17 +116,65 @@ export class GreetingTool {
114
116
 
115
117
  You are done!
116
118
 
119
+ ## Quick Start for STDIO
120
+
121
+ The main difference is that you need to provide the `transport` option when importing the module.
122
+
123
+ ```typescript
124
+ McpModule.forRoot({
125
+ name: 'playground-stdio-server',
126
+ version: '0.0.1',
127
+ transport: McpTransportType.STDIO,
128
+ });
129
+ ```
130
+
131
+ The rest is the same, you can define tools, resources, and prompts as usual. An example of a standalone NestJS application using the STDIO transport is the following:
132
+
133
+ ```typescript
134
+ async function bootstrap() {
135
+ const app = await NestFactory.createApplicationContext(AppModule, {
136
+ logger: false,
137
+ });
138
+ return app.close();
139
+ }
140
+
141
+ void bootstrap();
142
+ ```
143
+
144
+ Next, you can use the MCP server with an MCP Stdio Client ([see example](playground/clients/stdio-client.ts)), or after building your prject you can use it with the following MCP Client configuration:
145
+
146
+ ```json
147
+ {
148
+ "mcpServers": {
149
+ "greeting": {
150
+ "command": "node",
151
+ "args": [
152
+ "<path to dist js file>",
153
+ ]
154
+ }
155
+ }
156
+ }
157
+ ```
158
+
117
159
  ## API Endpoints
118
160
 
161
+ HTTP+SSE transport exposes two endpoints:
162
+
119
163
  - `GET /sse`: SSE connection endpoint (Protected by guards if configured)
120
164
  - `POST /messages`: Tool execution endpoint (Protected by guards if configured)
121
165
 
166
+ Streamable HTTP transport exposes the following endpoints:
167
+
168
+ - `POST /mcp`: Main endpoint for all MCP operations (tool execution, resource access, etc.). In stateful mode, this creates and maintains sessions.
169
+ - `GET /mcp`: Establishes Server-Sent Events (SSE) streams for real-time updates and progress notifications. **Only available in stateful mode.**
170
+ - `DELETE /mcp`: Terminates MCP sessions. **Only available in stateful mode.**
171
+
122
172
  ### Tips
123
173
 
124
174
  It's possible to use the module with global prefix, but the recommended way is to exclude those endpoints with:
125
175
 
126
176
  ```typescript
127
- app.setGlobalPrefix('/api', { exclude: ['sse', 'messages'] });
177
+ app.setGlobalPrefix('/api', { exclude: ['sse', 'messages', 'mcp'] });
128
178
  ```
129
179
 
130
180
  ## Authentication
@@ -163,30 +213,62 @@ export class AppModule {}
163
213
 
164
214
  That's it! The rest is the same as NestJS Guards.
165
215
 
166
- ## SSE Ping Service
167
-
168
- The module includes an SSE ping service that helps maintain long-lived SSE connections by preventing browser/client timeouts. This is especially useful for clients such as IDE's using your MCP server remotely.
169
-
170
- ### Configuration
171
-
172
- You can configure the SSE ping behavior when importing the module:
216
+ ## Playground
217
+
218
+ The `playground` directory contains examples to quickly test MCP and `@rekog/mcp-nest` features.
219
+ Refer to the [`playground/README.md`](playground/README.md) for more details.
220
+
221
+ ## Configuration
222
+
223
+ The `McpModule.forRoot()` method accepts an `McpOptions` object to configure the server. Here are the available options:
224
+
225
+ | Option | Description | Default |
226
+ | ------------------ | ----------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------- |
227
+ | `name` | **Required.** The name of your MCP server. | - |
228
+ | `version` | **Required.** The version of your MCP server. | - |
229
+ | `capabilities` | Optional MCP server capabilities to advertise. See [@modelcontextprotocol/sdk](https://www.npmjs.com/package/@modelcontextprotocol/sdk). | `undefined` |
230
+ | `instructions` | Optional instructions for the client on how to interact with the server. | `undefined` |
231
+ | `transport` | Specifies the transport type(s) to enable. | `[McpTransportType.SSE, McpTransportType.STREAMABLE_HTTP, McpTransportType.STDIO]` |
232
+ | `sseEndpoint` | The endpoint path for the SSE connection (used with `SSE` transport). | `'sse'` |
233
+ | `messagesEndpoint` | The endpoint path for sending messages (used with `SSE` transport). | `'messages'` |
234
+ | `mcpEndpoint` | The base endpoint path for MCP operations (used with `STREAMABLE_HTTP` transport). | `'mcp'` |
235
+ | `globalApiPrefix` | A global prefix for all MCP endpoints. Useful if integrating into an existing application. | `''` |
236
+ | `guards` | An array of NestJS Guards to apply to the MCP endpoints for authentication/authorization. | `[]` |
237
+ | `decorators` | An array of NestJS Class Decorators to apply to the generated MCP controllers. | `[]` |
238
+ | `sse` | Configuration specific to the `SSE` transport. | `{ pingEnabled: true, pingIntervalMs: 30000 }` |
239
+ | `sse.pingEnabled` | Whether to enable periodic SSE ping messages to keep the connection alive. | `true` |
240
+ | `sse.pingIntervalMs` | The interval (in milliseconds) for sending SSE ping messages. | `30000` |
241
+ | `streamableHttp` | Configuration specific to the `STREAMABLE_HTTP` transport. | `{ enableJsonResponse: true, sessionIdGenerator: undefined, statelessMode: true }` |
242
+ | `streamableHttp.enableJsonResponse` | If `true`, allows the `/mcp` endpoint to return JSON responses for non-streaming requests (like `listTools`). | `true` |
243
+ | `streamableHttp.sessionIdGenerator` | A function to generate unique session IDs when running in stateful mode. Required if `statelessMode` is `false`. | `undefined` |
244
+ | `streamableHttp.statelessMode` | If `true`, the `STREAMABLE_HTTP` transport operates statelessly (no sessions). If `false`, it operates statefully, requiring a `sessionIdGenerator`. | `true` |
245
+
246
+ **Example:**
173
247
 
174
248
  ```typescript
175
249
  // app.module.ts
176
250
  import { Module } from '@nestjs/common';
177
- import { McpModule } from '@rekog/mcp-nest';
251
+ import { McpModule, McpTransportType } from '@rekog/mcp-nest';
252
+ import { GreetingTool } from './greeting.tool';
253
+ import { AuthGuard } from './auth.guard'; // Your custom guard
254
+ import { randomUUID } from 'crypto';
178
255
 
179
256
  @Module({
180
257
  imports: [
181
258
  McpModule.forRoot({
182
- name: 'my-mcp-server',
183
- version: '1.0.0',
184
- sse: {
185
- pingEnabled: true, // Default is true
186
- pingIntervalMs: 30000, // Default is 30 seconds (30000ms)
259
+ name: 'my-stateful-mcp-server',
260
+ version: '2.1.0',
261
+ transport: McpTransportType.STREAMABLE_HTTP, // Only enable Streamable HTTP
262
+ mcpEndpoint: 'api/mcp', // Custom endpoint
263
+ guards: [AuthGuard], // Apply authentication
264
+ streamableHttp: {
265
+ statelessMode: false, // Enable stateful mode
266
+ sessionIdGenerator: () => randomUUID(), // Provide a session ID generator
267
+ enableJsonResponse: false, // Disable JSON responses for non-streaming requests
187
268
  },
188
269
  }),
189
270
  ],
271
+ providers: [GreetingTool, AuthGuard],
190
272
  })
191
273
  export class AppModule {}
192
274
  ```