@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.
- package/.idea/codeStyles/Project.xml +59 -0
- package/.idea/codeStyles/codeStyleConfig.xml +5 -0
- package/.idea/inspectionProfiles/Project_Default.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/nest-mcp.iml +12 -0
- package/.idea/vcs.xml +6 -0
- package/README.md +100 -18
- package/coverage/clover.xml +310 -212
- package/coverage/coverage-final.json +11 -10
- package/coverage/lcov-report/decorators/constants.ts.html +4 -4
- package/coverage/lcov-report/decorators/index.html +1 -1
- package/coverage/lcov-report/decorators/index.ts.html +5 -5
- package/coverage/lcov-report/decorators/prompt.decorator.ts.html +17 -5
- package/coverage/lcov-report/decorators/resource.decorator.ts.html +21 -6
- package/coverage/lcov-report/decorators/tool.decorator.ts.html +6 -6
- package/coverage/lcov-report/index.html +50 -50
- package/coverage/lcov-report/services/handlers/index.html +161 -0
- package/coverage/lcov-report/services/handlers/mcp-handler.base.ts.html +421 -0
- package/coverage/lcov-report/services/handlers/mcp-prompts.handler.ts.html +385 -0
- package/coverage/lcov-report/services/handlers/mcp-resources.handler.ts.html +361 -0
- package/coverage/lcov-report/services/handlers/mcp-tools.handler.ts.html +355 -0
- package/coverage/lcov-report/services/index.html +49 -19
- package/coverage/lcov-report/services/mcp-executor.service.ts.html +199 -0
- package/coverage/lcov-report/services/mcp-registry.service.ts.html +27 -15
- package/coverage/lcov-report/services/sse-ping.service.ts.html +499 -0
- package/coverage/lcov-report/tests/index.html +7 -7
- package/coverage/lcov-report/tests/utils.ts.html +115 -7
- package/coverage/lcov-report/transport/index.html +131 -0
- package/coverage/lcov-report/transport/sse.controller.factory.ts.html +532 -0
- package/coverage/lcov-report/transport/streamable-http.controller.factory.ts.html +1258 -0
- package/coverage/lcov.info +538 -365
- package/dist/decorators/prompt.decorator.d.ts +5 -1
- package/dist/decorators/prompt.decorator.d.ts.map +1 -1
- package/dist/decorators/prompt.decorator.js.map +1 -1
- package/dist/decorators/resource.decorator.d.ts +7 -2
- package/dist/decorators/resource.decorator.d.ts.map +1 -1
- package/dist/decorators/resource.decorator.js.map +1 -1
- package/dist/decorators/tool.decorator.d.ts +1 -1
- package/dist/decorators/tool.decorator.d.ts.map +1 -1
- package/dist/interfaces/mcp-options.interface.d.ts +6 -14
- package/dist/interfaces/mcp-options.interface.d.ts.map +1 -1
- package/dist/interfaces/mcp-options.interface.js +1 -1
- package/dist/interfaces/mcp-options.interface.js.map +1 -1
- package/dist/mcp.module.d.ts.map +1 -1
- package/dist/mcp.module.js +42 -12
- package/dist/mcp.module.js.map +1 -1
- package/dist/services/handlers/mcp-handler.base.d.ts +2 -1
- package/dist/services/handlers/mcp-handler.base.d.ts.map +1 -1
- package/dist/services/handlers/mcp-handler.base.js +27 -0
- package/dist/services/handlers/mcp-handler.base.js.map +1 -1
- package/dist/services/handlers/mcp-tools.handler.d.ts +1 -1
- package/dist/services/handlers/mcp-tools.handler.d.ts.map +1 -1
- package/dist/services/handlers/mcp-tools.handler.js +1 -1
- package/dist/services/handlers/mcp-tools.handler.js.map +1 -1
- package/dist/services/mcp-registry.service.d.ts +2 -2
- package/dist/services/mcp-registry.service.d.ts.map +1 -1
- package/dist/services/mcp-registry.service.js +3 -0
- package/dist/services/mcp-registry.service.js.map +1 -1
- package/dist/stdio.js +76070 -0
- package/dist/transport/custom-decorator.spec.d.ts +2 -0
- package/dist/transport/custom-decorator.spec.d.ts.map +1 -0
- package/dist/transport/custom-decorator.spec.js +34 -0
- package/dist/transport/custom-decorator.spec.js.map +1 -0
- package/dist/transport/sse.controller.factory.d.ts +23 -0
- package/dist/transport/sse.controller.factory.d.ts.map +1 -0
- package/dist/transport/sse.controller.factory.js +107 -0
- package/dist/transport/sse.controller.factory.js.map +1 -0
- package/dist/transport/stdio.service.d.ts +11 -0
- package/dist/transport/stdio.service.d.ts.map +1 -0
- package/dist/transport/stdio.service.js +56 -0
- package/dist/transport/stdio.service.js.map +1 -0
- package/dist/transport/streamable-http.controller.factory.d.ts +34 -0
- package/dist/transport/streamable-http.controller.factory.d.ts.map +1 -0
- package/dist/transport/streamable-http.controller.factory.js +282 -0
- package/dist/transport/streamable-http.controller.factory.js.map +1 -0
- package/package.json +7 -3
- package/playground/README.md +11 -3
- package/playground/clients/http-sse.ts +82 -0
- package/playground/{http-streamable-client.ts → clients/http-streamable-client.ts} +9 -6
- package/playground/clients/stdio-client.ts +95 -0
- package/playground/{greeting.prompt.ts → resources/greeting.prompt.ts} +1 -1
- package/playground/{greeting.resource.ts → resources/greeting.resource.ts} +1 -1
- package/playground/{greeting.tool.ts → resources/greeting.tool.ts} +2 -2
- package/playground/servers/server-stateful.ts +32 -0
- package/playground/{server.ts → servers/server-stateless.ts} +5 -8
- package/playground/servers/stdio.ts +27 -0
- package/tests/mcp-prompt.e2e.spec.ts +4 -4
- package/tests/mcp-resource.e2e.spec.ts +5 -5
- package/tests/mcp-tool-auth.e2e.spec.ts +4 -4
- package/tests/mcp-tool.e2e.spec.ts +23 -8
- package/tests/mcp.version.e2e.spec.ts +2 -2
- package/tests/sample/stdio-server.ts +158 -0
- package/tests/utils.ts +38 -2
- 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,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
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`
|
|
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
|
-
- 🚀
|
|
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
|
|
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
|
-
##
|
|
167
|
-
|
|
168
|
-
The
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
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
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
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
|
```
|