@rekog/mcp-nest 1.5.0 → 1.5.2
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/README.md +28 -42
- package/coverage/clover.xml +324 -325
- package/coverage/coverage-final.json +20 -20
- 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 +4 -4
- package/coverage/lcov-report/decorators/resource.decorator.ts.html +4 -4
- package/coverage/lcov-report/decorators/tool.decorator.ts.html +5 -5
- package/coverage/lcov-report/index.html +37 -37
- package/coverage/lcov-report/services/index.html +9 -39
- package/coverage/lcov-report/services/mcp-registry.service.ts.html +6 -6
- package/coverage/lcov-report/tests/index.html +21 -21
- package/coverage/lcov-report/tests/utils.ts.html +45 -45
- package/coverage/lcov.info +446 -449
- package/dist/interfaces/mcp-tool.interface.d.ts +7 -1
- package/dist/interfaces/mcp-tool.interface.d.ts.map +1 -1
- package/dist/services/handlers/mcp-handler.base.d.ts +3 -5
- package/dist/services/handlers/mcp-handler.base.d.ts.map +1 -1
- package/dist/services/handlers/mcp-handler.base.js +6 -2
- package/dist/services/handlers/mcp-handler.base.js.map +1 -1
- package/dist/transport/streamable-http.controller.factory.js +2 -2
- package/dist/transport/streamable-http.controller.factory.js.map +1 -1
- package/package.json +5 -3
- package/playground/resources/greeting.tool.ts +4 -3
- package/tests/mcp-tool.e2e.spec.ts +74 -10
- package/tsconfig.build.tsbuildinfo +1 -1
- package/coverage/lcov-report/services/handlers/index.html +0 -161
- package/coverage/lcov-report/services/handlers/mcp-handler.base.ts.html +0 -421
- package/coverage/lcov-report/services/handlers/mcp-prompts.handler.ts.html +0 -385
- package/coverage/lcov-report/services/handlers/mcp-resources.handler.ts.html +0 -361
- package/coverage/lcov-report/services/handlers/mcp-tools.handler.ts.html +0 -355
- package/coverage/lcov-report/services/mcp-executor.service.ts.html +0 -199
- package/coverage/lcov-report/services/sse-ping.service.ts.html +0 -499
- package/coverage/lcov-report/transport/index.html +0 -131
- package/coverage/lcov-report/transport/sse.controller.factory.ts.html +0 -532
- package/coverage/lcov-report/transport/streamable-http.controller.factory.ts.html +0 -1258
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
name:
|
|
1
|
+
name: Tests
|
|
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
|
package/README.md
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
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
|
-
|
|
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
|
|
|
@@ -24,6 +25,7 @@ with `@rekog/mcp-nest` you define tools, resources, and prompts in a way that's
|
|
|
24
25
|
- 💯 Zod-based tool call validation
|
|
25
26
|
- 📊 Progress notifications
|
|
26
27
|
- 🔒 Guard-based authentication
|
|
28
|
+
- 🌐 Access to HTTP Request information within MCP Resources (Tools, Resources, Prompts)
|
|
27
29
|
|
|
28
30
|
## Installation
|
|
29
31
|
|
|
@@ -57,6 +59,7 @@ export class AppModule {}
|
|
|
57
59
|
|
|
58
60
|
```typescript
|
|
59
61
|
// greeting.tool.ts
|
|
62
|
+
import type { Request } from 'express';
|
|
60
63
|
import { Injectable } from '@nestjs/common';
|
|
61
64
|
import { Tool, Resource, Context } from '@rekog/mcp-nest';
|
|
62
65
|
import { z } from 'zod';
|
|
@@ -74,12 +77,12 @@ export class GreetingTool {
|
|
|
74
77
|
name: z.string().default('World'),
|
|
75
78
|
}),
|
|
76
79
|
})
|
|
77
|
-
async sayHello({ name }, context: Context) {
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
+
async sayHello({ name }, context: Context, request: Request) {
|
|
81
|
+
const userAgent = request.get('user-agent') || 'Unknown';
|
|
82
|
+
const greeting = `Hello, ${name}! Your user agent is: ${userAgent}`;
|
|
80
83
|
const totalSteps = 5;
|
|
81
84
|
for (let i = 0; i < totalSteps; i++) {
|
|
82
|
-
await new Promise((resolve) => setTimeout(resolve,
|
|
85
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
83
86
|
|
|
84
87
|
// Send a progress update.
|
|
85
88
|
await context.reportProgress({
|
|
@@ -116,6 +119,9 @@ export class GreetingTool {
|
|
|
116
119
|
|
|
117
120
|
You are done!
|
|
118
121
|
|
|
122
|
+
> [!TIP]
|
|
123
|
+
> The above example shows how HTTP `Request` headers are accessed within MCP Tools. This is useful for identifying users, adding client-specific logic, and many other use cases. For more examples, see the [Authentication Tests](./tests/mcp-tool-auth.spec.ts).
|
|
124
|
+
|
|
119
125
|
## Quick Start for STDIO
|
|
120
126
|
|
|
121
127
|
The main difference is that you need to provide the `transport` option when importing the module.
|
|
@@ -141,7 +147,7 @@ async function bootstrap() {
|
|
|
141
147
|
void bootstrap();
|
|
142
148
|
```
|
|
143
149
|
|
|
144
|
-
Next, you can use the MCP server with an MCP Stdio Client ([see example](playground/clients/stdio-client.ts)), or after building your
|
|
150
|
+
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:
|
|
145
151
|
|
|
146
152
|
```json
|
|
147
153
|
{
|
|
@@ -243,32 +249,12 @@ The `McpModule.forRoot()` method accepts an `McpOptions` object to configure the
|
|
|
243
249
|
| `streamableHttp.sessionIdGenerator` | A function to generate unique session IDs when running in stateful mode. Required if `statelessMode` is `false`. | `undefined` |
|
|
244
250
|
| `streamableHttp.statelessMode` | If `true`, the `STREAMABLE_HTTP` transport operates statelessly (no sessions). If `false`, it operates statefully, requiring a `sessionIdGenerator`. | `true` |
|
|
245
251
|
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
@Module({
|
|
257
|
-
imports: [
|
|
258
|
-
McpModule.forRoot({
|
|
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
|
|
268
|
-
},
|
|
269
|
-
}),
|
|
270
|
-
],
|
|
271
|
-
providers: [GreetingTool, AuthGuard],
|
|
272
|
-
})
|
|
273
|
-
export class AppModule {}
|
|
274
|
-
```
|
|
252
|
+
<!-- Badges -->
|
|
253
|
+
[ci-url]: https://github.com/rekog-labs/MCP-Nest/actions/workflows/pipeline.yml
|
|
254
|
+
[ci-image]: https://github.com/rekog-labs/MCP-Nest/actions/workflows/pipeline.yml/badge.svg
|
|
255
|
+
[npm-url]: https://www.npmjs.com/package/@rekog/mcp-nest
|
|
256
|
+
[npm-version-image]: https://img.shields.io/npm/v/@rekog/mcp-nest
|
|
257
|
+
[npm-downloads-image]: https://img.shields.io/npm/dm/@rekog/mcp-nest
|
|
258
|
+
[npm-license-image]: https://img.shields.io/npm/l/@rekog/mcp-nest
|
|
259
|
+
[code-coverage-url]: https://codecov.io/gh/rekog-labs/mcp-nest
|
|
260
|
+
[code-coverage-image]: https://codecov.io/gh/rekog-labs/mcp-nest/branch/main/graph/badge.svg
|