@rekog/mcp-nest 1.5.0-beta.1 → 1.5.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.
- package/.github/workflows/pipeline.yml +11 -1
- 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 +102 -39
- package/coverage/clover.xml +449 -389
- package/coverage/coverage-final.json +20 -19
- package/coverage/lcov-report/decorators/constants.ts.html +1 -1
- package/coverage/lcov-report/decorators/index.html +1 -1
- package/coverage/lcov-report/decorators/index.ts.html +1 -1
- package/coverage/lcov-report/decorators/prompt.decorator.ts.html +15 -3
- package/coverage/lcov-report/decorators/resource.decorator.ts.html +19 -4
- package/coverage/lcov-report/decorators/tool.decorator.ts.html +2 -2
- package/coverage/lcov-report/index.html +58 -58
- package/coverage/lcov-report/services/index.html +17 -17
- package/coverage/lcov-report/services/mcp-registry.service.ts.html +23 -11
- package/coverage/lcov-report/tests/index.html +21 -21
- package/coverage/lcov-report/tests/utils.ts.html +143 -35
- package/coverage/lcov.info +720 -618
- 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/interfaces/mcp-tool.interface.d.ts +7 -1
- package/dist/interfaces/mcp-tool.interface.d.ts.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 +3 -4
- package/dist/services/handlers/mcp-handler.base.d.ts.map +1 -1
- package/dist/services/handlers/mcp-handler.base.js +31 -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 +5 -4
- 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 +95 -16
- 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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
name:
|
|
1
|
+
name: Testing
|
|
2
2
|
|
|
3
3
|
on:
|
|
4
4
|
push:
|
|
@@ -15,12 +15,22 @@ jobs:
|
|
|
15
15
|
|
|
16
16
|
steps:
|
|
17
17
|
- uses: actions/checkout@v4
|
|
18
|
+
|
|
18
19
|
- name: Use Node.js ${{ matrix.node-version }}
|
|
19
20
|
uses: actions/setup-node@v4
|
|
20
21
|
with:
|
|
21
22
|
node-version: ${{ matrix.node-version }}
|
|
22
23
|
cache: 'npm'
|
|
24
|
+
|
|
23
25
|
- name: Install dependencies
|
|
24
26
|
run: npm ci
|
|
27
|
+
|
|
25
28
|
- name: Run tests
|
|
26
29
|
run: npm run test
|
|
30
|
+
|
|
31
|
+
- name: Upload coverage reports to Codecov
|
|
32
|
+
uses: codecov/codecov-action@v5
|
|
33
|
+
if: github.event_name == 'push' && github.ref == 'refs/heads/main' && matrix.node-version == '20.x'
|
|
34
|
+
with:
|
|
35
|
+
token: ${{ secrets.CODECOV_TOKEN }}
|
|
36
|
+
files: ./coverage/lcov.info
|
|
@@ -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
|
@@ -1,27 +1,30 @@
|
|
|
1
1
|
# NestJS MCP Server Module
|
|
2
2
|
|
|
3
|
-
<
|
|
3
|
+
<div align="center">
|
|
4
4
|
<img src="https://raw.githubusercontent.com/rekog-labs/MCP-Nest/main/image.png" height="200">
|
|
5
|
-
</p>
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
[![CI][ci-image]][ci-url]
|
|
7
|
+
[![Code Coverage][code-coverage-image]][code-coverage-url]
|
|
8
|
+
[![NPM Version][npm-version-image]][npm-url]
|
|
9
|
+
[![NPM Downloads][npm-downloads-image]][npm-url]
|
|
10
|
+
[![NPM License][npm-license-image]][npm-url]
|
|
11
|
+
|
|
12
|
+
</div>
|
|
12
13
|
|
|
13
14
|
A NestJS module to effortlessly expose tools, resources, and prompts for AI, from your NestJS applications using the **Model Context Protocol (MCP)**.
|
|
14
15
|
|
|
15
|
-
`@rekog/mcp-nest`
|
|
16
|
+
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
17
|
|
|
17
18
|
## Features
|
|
18
19
|
|
|
19
|
-
- 🚀
|
|
20
|
+
- 🚀 Support for all Transport Types:
|
|
21
|
+
- Streamable HTTP
|
|
22
|
+
- HTTP+SSE
|
|
23
|
+
- STDIO
|
|
20
24
|
- 🔍 Automatic `tool`, `resource`, and `prompt` discovery and registration
|
|
21
|
-
- 💯 Zod-based
|
|
25
|
+
- 💯 Zod-based tool call validation
|
|
22
26
|
- 📊 Progress notifications
|
|
23
27
|
- 🔒 Guard-based authentication
|
|
24
|
-
- ⏱️ Automatic SSE ping to maintain long connections
|
|
25
28
|
|
|
26
29
|
## Installation
|
|
27
30
|
|
|
@@ -114,17 +117,65 @@ export class GreetingTool {
|
|
|
114
117
|
|
|
115
118
|
You are done!
|
|
116
119
|
|
|
120
|
+
## Quick Start for STDIO
|
|
121
|
+
|
|
122
|
+
The main difference is that you need to provide the `transport` option when importing the module.
|
|
123
|
+
|
|
124
|
+
```typescript
|
|
125
|
+
McpModule.forRoot({
|
|
126
|
+
name: 'playground-stdio-server',
|
|
127
|
+
version: '0.0.1',
|
|
128
|
+
transport: McpTransportType.STDIO,
|
|
129
|
+
});
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
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:
|
|
133
|
+
|
|
134
|
+
```typescript
|
|
135
|
+
async function bootstrap() {
|
|
136
|
+
const app = await NestFactory.createApplicationContext(AppModule, {
|
|
137
|
+
logger: false,
|
|
138
|
+
});
|
|
139
|
+
return app.close();
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
void bootstrap();
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
Next, you can use the MCP server with an MCP Stdio Client ([see example](playground/clients/stdio-client.ts)), or after building your project you can use it with the following MCP Client configuration:
|
|
146
|
+
|
|
147
|
+
```json
|
|
148
|
+
{
|
|
149
|
+
"mcpServers": {
|
|
150
|
+
"greeting": {
|
|
151
|
+
"command": "node",
|
|
152
|
+
"args": [
|
|
153
|
+
"<path to dist js file>",
|
|
154
|
+
]
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
```
|
|
159
|
+
|
|
117
160
|
## API Endpoints
|
|
118
161
|
|
|
162
|
+
HTTP+SSE transport exposes two endpoints:
|
|
163
|
+
|
|
119
164
|
- `GET /sse`: SSE connection endpoint (Protected by guards if configured)
|
|
120
165
|
- `POST /messages`: Tool execution endpoint (Protected by guards if configured)
|
|
121
166
|
|
|
167
|
+
Streamable HTTP transport exposes the following endpoints:
|
|
168
|
+
|
|
169
|
+
- `POST /mcp`: Main endpoint for all MCP operations (tool execution, resource access, etc.). In stateful mode, this creates and maintains sessions.
|
|
170
|
+
- `GET /mcp`: Establishes Server-Sent Events (SSE) streams for real-time updates and progress notifications. **Only available in stateful mode.**
|
|
171
|
+
- `DELETE /mcp`: Terminates MCP sessions. **Only available in stateful mode.**
|
|
172
|
+
|
|
122
173
|
### Tips
|
|
123
174
|
|
|
124
175
|
It's possible to use the module with global prefix, but the recommended way is to exclude those endpoints with:
|
|
125
176
|
|
|
126
177
|
```typescript
|
|
127
|
-
app.setGlobalPrefix('/api', { exclude: ['sse', 'messages'] });
|
|
178
|
+
app.setGlobalPrefix('/api', { exclude: ['sse', 'messages', 'mcp'] });
|
|
128
179
|
```
|
|
129
180
|
|
|
130
181
|
## Authentication
|
|
@@ -163,30 +214,42 @@ export class AppModule {}
|
|
|
163
214
|
|
|
164
215
|
That's it! The rest is the same as NestJS Guards.
|
|
165
216
|
|
|
166
|
-
##
|
|
167
|
-
|
|
168
|
-
The
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
@
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
217
|
+
## Playground
|
|
218
|
+
|
|
219
|
+
The `playground` directory contains examples to quickly test MCP and `@rekog/mcp-nest` features.
|
|
220
|
+
Refer to the [`playground/README.md`](playground/README.md) for more details.
|
|
221
|
+
|
|
222
|
+
## Configuration
|
|
223
|
+
|
|
224
|
+
The `McpModule.forRoot()` method accepts an `McpOptions` object to configure the server. Here are the available options:
|
|
225
|
+
|
|
226
|
+
| Option | Description | Default |
|
|
227
|
+
| ------------------ | ----------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------- |
|
|
228
|
+
| `name` | **Required.** The name of your MCP server. | - |
|
|
229
|
+
| `version` | **Required.** The version of your MCP server. | - |
|
|
230
|
+
| `capabilities` | Optional MCP server capabilities to advertise. See [@modelcontextprotocol/sdk](https://www.npmjs.com/package/@modelcontextprotocol/sdk). | `undefined` |
|
|
231
|
+
| `instructions` | Optional instructions for the client on how to interact with the server. | `undefined` |
|
|
232
|
+
| `transport` | Specifies the transport type(s) to enable. | `[McpTransportType.SSE, McpTransportType.STREAMABLE_HTTP, McpTransportType.STDIO]` |
|
|
233
|
+
| `sseEndpoint` | The endpoint path for the SSE connection (used with `SSE` transport). | `'sse'` |
|
|
234
|
+
| `messagesEndpoint` | The endpoint path for sending messages (used with `SSE` transport). | `'messages'` |
|
|
235
|
+
| `mcpEndpoint` | The base endpoint path for MCP operations (used with `STREAMABLE_HTTP` transport). | `'mcp'` |
|
|
236
|
+
| `globalApiPrefix` | A global prefix for all MCP endpoints. Useful if integrating into an existing application. | `''` |
|
|
237
|
+
| `guards` | An array of NestJS Guards to apply to the MCP endpoints for authentication/authorization. | `[]` |
|
|
238
|
+
| `decorators` | An array of NestJS Class Decorators to apply to the generated MCP controllers. | `[]` |
|
|
239
|
+
| `sse` | Configuration specific to the `SSE` transport. | `{ pingEnabled: true, pingIntervalMs: 30000 }` |
|
|
240
|
+
| `sse.pingEnabled` | Whether to enable periodic SSE ping messages to keep the connection alive. | `true` |
|
|
241
|
+
| `sse.pingIntervalMs` | The interval (in milliseconds) for sending SSE ping messages. | `30000` |
|
|
242
|
+
| `streamableHttp` | Configuration specific to the `STREAMABLE_HTTP` transport. | `{ enableJsonResponse: true, sessionIdGenerator: undefined, statelessMode: true }` |
|
|
243
|
+
| `streamableHttp.enableJsonResponse` | If `true`, allows the `/mcp` endpoint to return JSON responses for non-streaming requests (like `listTools`). | `true` |
|
|
244
|
+
| `streamableHttp.sessionIdGenerator` | A function to generate unique session IDs when running in stateful mode. Required if `statelessMode` is `false`. | `undefined` |
|
|
245
|
+
| `streamableHttp.statelessMode` | If `true`, the `STREAMABLE_HTTP` transport operates statelessly (no sessions). If `false`, it operates statefully, requiring a `sessionIdGenerator`. | `true` |
|
|
246
|
+
|
|
247
|
+
<!-- Badges -->
|
|
248
|
+
[ci-url]: https://github.com/rekog-labs/MCP-Nest/actions/workflows/pipeline.yml
|
|
249
|
+
[ci-image]: https://github.com/rekog-labs/MCP-Nest/actions/workflows/pipeline.yml/badge.svg
|
|
250
|
+
[npm-url]: https://www.npmjs.com/package/@rekog/mcp-nest
|
|
251
|
+
[npm-version-image]: https://img.shields.io/npm/v/@rekog/mcp-nest
|
|
252
|
+
[npm-downloads-image]: https://img.shields.io/npm/dm/@rekog/mcp-nest
|
|
253
|
+
[npm-license-image]: https://img.shields.io/npm/l/@rekog/mcp-nest
|
|
254
|
+
[code-coverage-url]: https://codecov.io/gh/rekog-labs/mcp-nest
|
|
255
|
+
[code-coverage-image]: https://codecov.io/gh/rekog-labs/mcp-nest/branch/main/graph/badge.svg
|