easy-mcp-nest 0.2.1 → 0.4.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/README.md +342 -8
- package/dist/EasyMCP.js +0 -3
- package/dist/EasyMCP.js.map +1 -1
- package/dist/adapters/express/express-adapter.d.ts +3 -0
- package/dist/adapters/express/express-adapter.js +135 -0
- package/dist/adapters/express/express-adapter.js.map +1 -0
- package/dist/adapters/express/http-gateway.service.d.ts +13 -0
- package/dist/adapters/express/http-gateway.service.js +102 -0
- package/dist/adapters/express/http-gateway.service.js.map +1 -0
- package/dist/adapters/express/index.d.ts +3 -0
- package/dist/adapters/express/index.js +8 -0
- package/dist/adapters/express/index.js.map +1 -0
- package/dist/adapters/express/types.d.ts +15 -0
- package/dist/adapters/express/types.js +3 -0
- package/dist/adapters/express/types.js.map +1 -0
- package/dist/app.module.js +2 -0
- package/dist/app.module.js.map +1 -1
- package/dist/auth/oauth/index.d.ts +3 -0
- package/dist/auth/oauth/index.js +8 -0
- package/dist/auth/oauth/index.js.map +1 -0
- package/dist/auth/oauth/oauth-config.interface.d.ts +12 -0
- package/dist/auth/oauth/oauth-config.interface.js +3 -0
- package/dist/auth/oauth/oauth-config.interface.js.map +1 -0
- package/dist/auth/oauth/oauth-middleware.d.ts +3 -0
- package/dist/auth/oauth/oauth-middleware.js +54 -0
- package/dist/auth/oauth/oauth-middleware.js.map +1 -0
- package/dist/auth/oauth/oauth-provider.service.d.ts +8 -0
- package/dist/auth/oauth/oauth-provider.service.js +63 -0
- package/dist/auth/oauth/oauth-provider.service.js.map +1 -0
- package/dist/config/mcp-config.interface.d.ts +1 -1
- package/dist/core/batch/batch-executor.service.d.ts +21 -0
- package/dist/core/batch/batch-executor.service.js +101 -0
- package/dist/core/batch/batch-executor.service.js.map +1 -0
- package/dist/core/context/context-provider.service.d.ts +8 -0
- package/dist/core/context/context-provider.service.js +55 -0
- package/dist/core/context/context-provider.service.js.map +1 -0
- package/dist/core/context/mcp-context.interface.d.ts +12 -0
- package/dist/core/context/mcp-context.interface.js +3 -0
- package/dist/core/context/mcp-context.interface.js.map +1 -0
- package/dist/core/documentation/openapi-generator.service.d.ts +13 -0
- package/dist/core/documentation/openapi-generator.service.js +116 -0
- package/dist/core/documentation/openapi-generator.service.js.map +1 -0
- package/dist/core/errors/error-handler.interface.d.ts +11 -0
- package/dist/core/errors/error-handler.interface.js +3 -0
- package/dist/core/errors/error-handler.interface.js.map +1 -0
- package/dist/core/health/health-check.service.d.ts +33 -0
- package/dist/core/health/health-check.service.js +71 -0
- package/dist/core/health/health-check.service.js.map +1 -0
- package/dist/core/mcp-server/mcp-server.service.d.ts +16 -1
- package/dist/core/mcp-server/mcp-server.service.js +201 -3
- package/dist/core/mcp-server/mcp-server.service.js.map +1 -1
- package/dist/core/middleware/middleware-executor.service.d.ts +8 -0
- package/dist/core/middleware/middleware-executor.service.js +46 -0
- package/dist/core/middleware/middleware-executor.service.js.map +1 -0
- package/dist/core/middleware/middleware.interface.d.ts +6 -0
- package/dist/core/middleware/middleware.interface.js +3 -0
- package/dist/core/middleware/middleware.interface.js.map +1 -0
- package/dist/core/observability/metrics.service.d.ts +29 -0
- package/dist/core/observability/metrics.service.js +124 -0
- package/dist/core/observability/metrics.service.js.map +1 -0
- package/dist/core/observability/tracing.service.d.ts +12 -0
- package/dist/core/observability/tracing.service.js +88 -0
- package/dist/core/observability/tracing.service.js.map +1 -0
- package/dist/core/progress/progress-notifier.service.d.ts +16 -0
- package/dist/core/progress/progress-notifier.service.js +96 -0
- package/dist/core/progress/progress-notifier.service.js.map +1 -0
- package/dist/core/rate-limiting/rate-limit.interface.d.ts +11 -0
- package/dist/core/rate-limiting/rate-limit.interface.js +3 -0
- package/dist/core/rate-limiting/rate-limit.interface.js.map +1 -0
- package/dist/core/rate-limiting/rate-limiter.service.d.ts +13 -0
- package/dist/core/rate-limiting/rate-limiter.service.js +147 -0
- package/dist/core/rate-limiting/rate-limiter.service.js.map +1 -0
- package/dist/core/resilience/circuit-breaker.interface.d.ts +15 -0
- package/dist/core/resilience/circuit-breaker.interface.js +3 -0
- package/dist/core/resilience/circuit-breaker.interface.js.map +1 -0
- package/dist/core/resilience/circuit-breaker.service.d.ts +11 -0
- package/dist/core/resilience/circuit-breaker.service.js +117 -0
- package/dist/core/resilience/circuit-breaker.service.js.map +1 -0
- package/dist/core/resilience/retry.service.d.ts +6 -0
- package/dist/core/resilience/retry.service.js +66 -0
- package/dist/core/resilience/retry.service.js.map +1 -0
- package/dist/core/utils/decorator-scanner.d.ts +4 -0
- package/dist/core/utils/decorator-scanner.js +112 -0
- package/dist/core/utils/decorator-scanner.js.map +1 -0
- package/dist/core/utils/sanitize.util.d.ts +2 -0
- package/dist/core/utils/sanitize.util.js +48 -0
- package/dist/core/utils/sanitize.util.js.map +1 -1
- package/dist/decorators/factory-provider.d.ts +2 -0
- package/dist/decorators/factory-provider.js +20 -0
- package/dist/decorators/factory-provider.js.map +1 -0
- package/dist/decorators/index.d.ts +7 -0
- package/dist/decorators/index.js +28 -0
- package/dist/decorators/index.js.map +1 -0
- package/dist/decorators/mcp-context.decorator.d.ts +3 -0
- package/dist/decorators/mcp-context.decorator.js +20 -0
- package/dist/decorators/mcp-context.decorator.js.map +1 -0
- package/dist/decorators/mcp-error-handler.decorator.d.ts +4 -0
- package/dist/decorators/mcp-error-handler.decorator.js +15 -0
- package/dist/decorators/mcp-error-handler.decorator.js.map +1 -0
- package/dist/decorators/mcp-middleware.decorator.d.ts +4 -0
- package/dist/decorators/mcp-middleware.decorator.js +17 -0
- package/dist/decorators/mcp-middleware.decorator.js.map +1 -0
- package/dist/decorators/mcp-param.decorator.d.ts +10 -0
- package/dist/decorators/mcp-param.decorator.js +41 -0
- package/dist/decorators/mcp-param.decorator.js.map +1 -0
- package/dist/decorators/mcp-service.decorator.d.ts +6 -0
- package/dist/decorators/mcp-service.decorator.js +27 -0
- package/dist/decorators/mcp-service.decorator.js.map +1 -0
- package/dist/decorators/mcp-tool.decorator.d.ts +28 -0
- package/dist/decorators/mcp-tool.decorator.js +36 -0
- package/dist/decorators/mcp-tool.decorator.js.map +1 -0
- package/dist/index.d.ts +12 -1
- package/dist/index.js +30 -1
- package/dist/index.js.map +1 -1
- package/dist/interface/interface.interface.d.ts +2 -0
- package/dist/interface/jsonrpc.interface.d.ts +8 -0
- package/dist/interface/jsonrpc.interface.js.map +1 -1
- package/dist/interface/mcp-protocol.interface.d.ts +14 -0
- package/dist/interface/mcp-protocol.interface.js.map +1 -1
- package/dist/standalone/core-services.d.ts +29 -0
- package/dist/standalone/core-services.js +94 -0
- package/dist/standalone/core-services.js.map +1 -0
- package/dist/standalone/index.d.ts +3 -0
- package/dist/standalone/index.js +11 -0
- package/dist/standalone/index.js.map +1 -0
- package/dist/standalone/standalone-server.d.ts +23 -0
- package/dist/standalone/standalone-server.js +366 -0
- package/dist/standalone/standalone-server.js.map +1 -0
- package/dist/standalone/types.d.ts +14 -0
- package/dist/standalone/types.js +3 -0
- package/dist/standalone/types.js.map +1 -0
- package/dist/testing/index.d.ts +3 -0
- package/dist/testing/index.js +14 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/testing/mock-context.d.ts +2 -0
- package/dist/testing/mock-context.js +17 -0
- package/dist/testing/mock-context.js.map +1 -0
- package/dist/testing/test-app.factory.d.ts +15 -0
- package/dist/testing/test-app.factory.js +37 -0
- package/dist/testing/test-app.factory.js.map +1 -0
- package/dist/testing/test-helpers.d.ts +10 -0
- package/dist/testing/test-helpers.js +46 -0
- package/dist/testing/test-helpers.js.map +1 -0
- package/dist/tooling/tool-registry/tool-registry.service.d.ts +7 -1
- package/dist/tooling/tool-registry/tool-registry.service.js +40 -3
- package/dist/tooling/tool-registry/tool-registry.service.js.map +1 -1
- package/dist/tooling/tool.interface.d.ts +9 -2
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/validation/index.d.ts +1 -0
- package/dist/validation/index.js +8 -0
- package/dist/validation/index.js.map +1 -0
- package/dist/validation/zod-integration.d.ts +11 -0
- package/dist/validation/zod-integration.js +148 -0
- package/dist/validation/zod-integration.js.map +1 -0
- package/package.json +4 -2
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.OpenApiGeneratorService = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const tool_registry_service_1 = require("../../tooling/tool-registry/tool-registry.service");
|
|
15
|
+
let OpenApiGeneratorService = class OpenApiGeneratorService {
|
|
16
|
+
toolRegistry;
|
|
17
|
+
constructor(toolRegistry) {
|
|
18
|
+
this.toolRegistry = toolRegistry;
|
|
19
|
+
}
|
|
20
|
+
generateOpenApiSpec(info) {
|
|
21
|
+
const tools = this.toolRegistry.getToolSchemasForLLM();
|
|
22
|
+
const spec = {
|
|
23
|
+
openapi: "3.0.0",
|
|
24
|
+
info: {
|
|
25
|
+
title: info.title,
|
|
26
|
+
version: info.version,
|
|
27
|
+
description: "MCP Server API - Auto-generated from tool definitions",
|
|
28
|
+
},
|
|
29
|
+
paths: {},
|
|
30
|
+
components: {
|
|
31
|
+
schemas: {},
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
for (const tool of tools) {
|
|
35
|
+
const path = `/tools/${encodeURIComponent(tool.function.name)}`;
|
|
36
|
+
spec.paths[path] = {
|
|
37
|
+
post: {
|
|
38
|
+
summary: tool.function.description,
|
|
39
|
+
operationId: tool.function.name,
|
|
40
|
+
requestBody: {
|
|
41
|
+
required: true,
|
|
42
|
+
content: {
|
|
43
|
+
"application/json": {
|
|
44
|
+
schema: tool.function.parameters,
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
responses: {
|
|
49
|
+
"200": {
|
|
50
|
+
description: "Tool execution result",
|
|
51
|
+
content: {
|
|
52
|
+
"application/json": {
|
|
53
|
+
schema: {
|
|
54
|
+
type: "object",
|
|
55
|
+
properties: {
|
|
56
|
+
content: {
|
|
57
|
+
type: "array",
|
|
58
|
+
items: {
|
|
59
|
+
type: "object",
|
|
60
|
+
properties: {
|
|
61
|
+
type: { type: "string" },
|
|
62
|
+
text: { type: "string" },
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
"400": {
|
|
72
|
+
description: "Invalid request",
|
|
73
|
+
},
|
|
74
|
+
"500": {
|
|
75
|
+
description: "Tool execution error",
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
return spec;
|
|
82
|
+
}
|
|
83
|
+
generateMarkdownDocs(info) {
|
|
84
|
+
const tools = this.toolRegistry.getToolSchemasForLLM();
|
|
85
|
+
const escapeMarkdown = (text) => {
|
|
86
|
+
if (!text)
|
|
87
|
+
return "";
|
|
88
|
+
return text.replace(/([\\`*_{}[\]()#+-.!])/g, "\\$1");
|
|
89
|
+
};
|
|
90
|
+
let markdown = `# ${escapeMarkdown(info.title)} API Documentation\n\n`;
|
|
91
|
+
markdown += `Version: ${escapeMarkdown(info.version)}\n\n`;
|
|
92
|
+
markdown += `## Tools\n\n`;
|
|
93
|
+
for (const tool of tools) {
|
|
94
|
+
markdown += `### ${escapeMarkdown(tool.function.name)}\n\n`;
|
|
95
|
+
markdown += `${escapeMarkdown(tool.function.description)}\n\n`;
|
|
96
|
+
if (tool.function.parameters.properties) {
|
|
97
|
+
markdown += `#### Parameters\n\n`;
|
|
98
|
+
for (const [paramName, paramDef] of Object.entries(tool.function.parameters.properties)) {
|
|
99
|
+
markdown += `- **${escapeMarkdown(paramName)}** (${escapeMarkdown(String(paramDef.type || "any"))})`;
|
|
100
|
+
if (paramDef.description) {
|
|
101
|
+
markdown += `: ${escapeMarkdown(paramDef.description)}`;
|
|
102
|
+
}
|
|
103
|
+
markdown += `\n`;
|
|
104
|
+
}
|
|
105
|
+
markdown += `\n`;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return markdown;
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
exports.OpenApiGeneratorService = OpenApiGeneratorService;
|
|
112
|
+
exports.OpenApiGeneratorService = OpenApiGeneratorService = __decorate([
|
|
113
|
+
(0, common_1.Injectable)(),
|
|
114
|
+
__metadata("design:paramtypes", [tool_registry_service_1.ToolRegistryService])
|
|
115
|
+
], OpenApiGeneratorService);
|
|
116
|
+
//# sourceMappingURL=openapi-generator.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openapi-generator.service.js","sourceRoot":"","sources":["../../../src/core/documentation/openapi-generator.service.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { McpContext } from "../context/mcp-context.interface";
|
|
2
|
+
import { JsonRpcError } from "../../interface/jsonrpc.interface";
|
|
3
|
+
export type ErrorHandler = (error: Error, context: {
|
|
4
|
+
toolName?: string;
|
|
5
|
+
requestId?: string | number | null;
|
|
6
|
+
mcpContext?: McpContext;
|
|
7
|
+
}) => JsonRpcError | Error | null;
|
|
8
|
+
export interface ErrorHandlerConfig {
|
|
9
|
+
handler?: ErrorHandler;
|
|
10
|
+
logErrors?: boolean;
|
|
11
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-handler.interface.js","sourceRoot":"","sources":["../../../src/core/errors/error-handler.interface.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { ToolRegistryService } from "../../tooling/tool-registry/tool-registry.service";
|
|
2
|
+
import { MetricsService } from "../observability/metrics.service";
|
|
3
|
+
export interface HealthCheckResult {
|
|
4
|
+
status: "healthy" | "unhealthy" | "degraded";
|
|
5
|
+
checks: {
|
|
6
|
+
server: {
|
|
7
|
+
status: string;
|
|
8
|
+
uptime: number;
|
|
9
|
+
};
|
|
10
|
+
tools: {
|
|
11
|
+
status: string;
|
|
12
|
+
count: number;
|
|
13
|
+
};
|
|
14
|
+
metrics?: {
|
|
15
|
+
status: string;
|
|
16
|
+
activeRequests: number;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
timestamp: string;
|
|
20
|
+
}
|
|
21
|
+
export declare class HealthCheckService {
|
|
22
|
+
private readonly toolRegistry;
|
|
23
|
+
private readonly metricsService?;
|
|
24
|
+
constructor(toolRegistry: ToolRegistryService, metricsService?: MetricsService | undefined);
|
|
25
|
+
checkHealth(): Promise<HealthCheckResult>;
|
|
26
|
+
checkReadiness(): Promise<{
|
|
27
|
+
ready: boolean;
|
|
28
|
+
reason?: string;
|
|
29
|
+
}>;
|
|
30
|
+
checkLiveness(): Promise<{
|
|
31
|
+
alive: boolean;
|
|
32
|
+
}>;
|
|
33
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.HealthCheckService = void 0;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
17
|
+
const tool_registry_service_1 = require("../../tooling/tool-registry/tool-registry.service");
|
|
18
|
+
const metrics_service_1 = require("../observability/metrics.service");
|
|
19
|
+
let HealthCheckService = class HealthCheckService {
|
|
20
|
+
toolRegistry;
|
|
21
|
+
metricsService;
|
|
22
|
+
constructor(toolRegistry, metricsService) {
|
|
23
|
+
this.toolRegistry = toolRegistry;
|
|
24
|
+
this.metricsService = metricsService;
|
|
25
|
+
}
|
|
26
|
+
async checkHealth() {
|
|
27
|
+
const tools = this.toolRegistry.getToolSchemasForLLM();
|
|
28
|
+
const toolCount = tools.length;
|
|
29
|
+
const checks = {
|
|
30
|
+
server: {
|
|
31
|
+
status: "healthy",
|
|
32
|
+
uptime: process.uptime(),
|
|
33
|
+
},
|
|
34
|
+
tools: {
|
|
35
|
+
status: toolCount > 0 ? "healthy" : "unhealthy",
|
|
36
|
+
count: toolCount,
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
if (this.metricsService) {
|
|
40
|
+
const serverMetrics = this.metricsService.getServerMetrics();
|
|
41
|
+
checks.metrics = {
|
|
42
|
+
status: serverMetrics.activeRequests < 100 ? "healthy" : "degraded",
|
|
43
|
+
activeRequests: serverMetrics.activeRequests,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
const allHealthy = Object.values(checks).every((check) => check.status === "healthy" || check.status === "degraded");
|
|
47
|
+
return {
|
|
48
|
+
status: allHealthy ? "healthy" : "unhealthy",
|
|
49
|
+
checks,
|
|
50
|
+
timestamp: new Date().toISOString(),
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
async checkReadiness() {
|
|
54
|
+
const tools = this.toolRegistry.getToolSchemasForLLM();
|
|
55
|
+
if (tools.length === 0) {
|
|
56
|
+
return { ready: false, reason: "No tools registered" };
|
|
57
|
+
}
|
|
58
|
+
return { ready: true };
|
|
59
|
+
}
|
|
60
|
+
async checkLiveness() {
|
|
61
|
+
return { alive: true };
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
exports.HealthCheckService = HealthCheckService;
|
|
65
|
+
exports.HealthCheckService = HealthCheckService = __decorate([
|
|
66
|
+
(0, common_1.Injectable)(),
|
|
67
|
+
__param(1, (0, common_1.Optional)()),
|
|
68
|
+
__metadata("design:paramtypes", [tool_registry_service_1.ToolRegistryService,
|
|
69
|
+
metrics_service_1.MetricsService])
|
|
70
|
+
], HealthCheckService);
|
|
71
|
+
//# sourceMappingURL=health-check.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"health-check.service.js","sourceRoot":"","sources":["../../../src/core/health/health-check.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA8D;AAC9D,6FAAwF;AACxF,sEAAkE;AAmB3D,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IAEV;IACY;IAF/B,YACmB,YAAiC,EACrB,cAA+B;QAD3C,iBAAY,GAAZ,YAAY,CAAqB;QACrB,mBAAc,GAAd,cAAc,CAAiB;IAC3D,CAAC;IAKJ,KAAK,CAAC,WAAW;QACf,MAAM,KAAK,GAAG,IAAI,CAAC,YAAY,CAAC,oBAAoB,EAAE,CAAC;QACvD,MAAM,SAAS,GAAG,KAAK,CAAC,MAAM,CAAC;QAE/B,MAAM,MAAM,GAAgC;YAC1C,MAAM,EAAE;gBACN,MAAM,EAAE,SAAS;gBACjB,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE;aACzB;YACD,KAAK,EAAE;gBACL,MAAM,EAAE,SAAS,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW;gBAC/C,KAAK,EAAE,SAAS;aACjB;SACF,CAAC;QAEF,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;YACxB,MAAM,aAAa,GAAG,IAAI,CAAC,cAAc,CAAC,gBAAgB,EAAE,CAAC;YAC7D,MAAM,CAAC,OAAO,GAAG;gBACf,MAAM,EAAE,aAAa,CAAC,cAAc,GAAG,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,UAAU;gBACnE,cAAc,EAAE,aAAa,CAAC,cAAc;aAC7C,CAAC;QACJ,CAAC;QAED,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,CAC5C,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,KAAK,SAAS,IAAI,KAAK,CAAC,MAAM,KAAK,UAAU,CACrE,CAAC;QAEF,OAAO;YACL,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW;YAC5C,MAAM;YACN,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;SACpC,CAAC;IACJ,CAAC;IAKD,KAAK,CAAC,cAAc;QAClB,MAAM,KAAK,GAAG,IAAI,CAAC,YAAY,CAAC,oBAAoB,EAAE,CAAC;QACvD,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACvB,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,qBAAqB,EAAE,CAAC;QACzD,CAAC;QACD,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;IACzB,CAAC;IAKD,KAAK,CAAC,aAAa;QACjB,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;IACzB,CAAC;CACF,CAAA;AA5DY,gDAAkB;6BAAlB,kBAAkB;IAD9B,IAAA,mBAAU,GAAE;IAIR,WAAA,IAAA,iBAAQ,GAAE,CAAA;qCADoB,2CAAmB;QACJ,gCAAc;GAHnD,kBAAkB,CA4D9B"}
|
|
@@ -6,6 +6,13 @@ import { JsonRpcRequest, JsonRpcResponse } from "../../interface/jsonrpc.interfa
|
|
|
6
6
|
import { ResourceRegistryService } from "../../resources/resource-registry.service";
|
|
7
7
|
import { PromptRegistryService } from "../../prompts/prompt-registry.service";
|
|
8
8
|
import { ConfigHolderService } from "../../config/config-holder.service";
|
|
9
|
+
import { ContextProviderService } from "../context/context-provider.service";
|
|
10
|
+
import { ProgressNotifierService } from "../progress/progress-notifier.service";
|
|
11
|
+
import { MetricsService } from "../observability/metrics.service";
|
|
12
|
+
import { RateLimiterService } from "../rate-limiting/rate-limiter.service";
|
|
13
|
+
import { RetryService } from "../resilience/retry.service";
|
|
14
|
+
import { CircuitBreakerService } from "../resilience/circuit-breaker.service";
|
|
15
|
+
import { BatchExecutorService } from "../batch/batch-executor.service";
|
|
9
16
|
export declare class McpServerService implements OnModuleInit {
|
|
10
17
|
private readonly toolRegistry;
|
|
11
18
|
private readonly resourceRegistry;
|
|
@@ -13,9 +20,16 @@ export declare class McpServerService implements OnModuleInit {
|
|
|
13
20
|
private readonly interfaceLayer;
|
|
14
21
|
private readonly stdioGatewayService;
|
|
15
22
|
private readonly configHolder;
|
|
23
|
+
private readonly contextProvider;
|
|
24
|
+
private readonly progressNotifier?;
|
|
25
|
+
private readonly metricsService?;
|
|
26
|
+
private readonly rateLimiter?;
|
|
27
|
+
private readonly retryService?;
|
|
28
|
+
private readonly circuitBreaker?;
|
|
29
|
+
private readonly batchExecutor?;
|
|
16
30
|
private clientIdentifier;
|
|
17
31
|
private readonly cancellationTokens;
|
|
18
|
-
constructor(toolRegistry: ToolRegistryService, resourceRegistry: ResourceRegistryService, promptRegistry: PromptRegistryService, interfaceLayer: IInterfaceLayer, stdioGatewayService: StdioGatewayService, configHolder: ConfigHolderService);
|
|
32
|
+
constructor(toolRegistry: ToolRegistryService, resourceRegistry: ResourceRegistryService, promptRegistry: PromptRegistryService, interfaceLayer: IInterfaceLayer, stdioGatewayService: StdioGatewayService, configHolder: ConfigHolderService, contextProvider: ContextProviderService, progressNotifier?: ProgressNotifierService | undefined, metricsService?: MetricsService | undefined, rateLimiter?: RateLimiterService | undefined, retryService?: RetryService | undefined, circuitBreaker?: CircuitBreakerService | undefined, batchExecutor?: BatchExecutorService | undefined);
|
|
19
33
|
private getServerInfo;
|
|
20
34
|
private getActorIdentifier;
|
|
21
35
|
onModuleInit(): void;
|
|
@@ -24,6 +38,7 @@ export declare class McpServerService implements OnModuleInit {
|
|
|
24
38
|
private handleInitialize;
|
|
25
39
|
private handleListTools;
|
|
26
40
|
private handleCallTool;
|
|
41
|
+
private handleBatchTools;
|
|
27
42
|
private handleCancelRequest;
|
|
28
43
|
private handleListResources;
|
|
29
44
|
private handleReadResource;
|
|
@@ -29,6 +29,14 @@ const schema_validator_1 = require("../utils/schema-validator");
|
|
|
29
29
|
const logger_util_1 = require("../utils/logger.util");
|
|
30
30
|
const sanitize_util_1 = require("../utils/sanitize.util");
|
|
31
31
|
const constants_3 = require("../../config/constants");
|
|
32
|
+
const context_provider_service_1 = require("../context/context-provider.service");
|
|
33
|
+
const progress_notifier_service_1 = require("../progress/progress-notifier.service");
|
|
34
|
+
const metrics_service_1 = require("../observability/metrics.service");
|
|
35
|
+
const rate_limiter_service_1 = require("../rate-limiting/rate-limiter.service");
|
|
36
|
+
const retry_service_1 = require("../resilience/retry.service");
|
|
37
|
+
const circuit_breaker_service_1 = require("../resilience/circuit-breaker.service");
|
|
38
|
+
const batch_executor_service_1 = require("../batch/batch-executor.service");
|
|
39
|
+
const common_2 = require("@nestjs/common");
|
|
32
40
|
let McpServerService = class McpServerService {
|
|
33
41
|
toolRegistry;
|
|
34
42
|
resourceRegistry;
|
|
@@ -36,15 +44,29 @@ let McpServerService = class McpServerService {
|
|
|
36
44
|
interfaceLayer;
|
|
37
45
|
stdioGatewayService;
|
|
38
46
|
configHolder;
|
|
47
|
+
contextProvider;
|
|
48
|
+
progressNotifier;
|
|
49
|
+
metricsService;
|
|
50
|
+
rateLimiter;
|
|
51
|
+
retryService;
|
|
52
|
+
circuitBreaker;
|
|
53
|
+
batchExecutor;
|
|
39
54
|
clientIdentifier = "stdio-client";
|
|
40
55
|
cancellationTokens = new Map();
|
|
41
|
-
constructor(toolRegistry, resourceRegistry, promptRegistry, interfaceLayer, stdioGatewayService, configHolder) {
|
|
56
|
+
constructor(toolRegistry, resourceRegistry, promptRegistry, interfaceLayer, stdioGatewayService, configHolder, contextProvider, progressNotifier, metricsService, rateLimiter, retryService, circuitBreaker, batchExecutor) {
|
|
42
57
|
this.toolRegistry = toolRegistry;
|
|
43
58
|
this.resourceRegistry = resourceRegistry;
|
|
44
59
|
this.promptRegistry = promptRegistry;
|
|
45
60
|
this.interfaceLayer = interfaceLayer;
|
|
46
61
|
this.stdioGatewayService = stdioGatewayService;
|
|
47
62
|
this.configHolder = configHolder;
|
|
63
|
+
this.contextProvider = contextProvider;
|
|
64
|
+
this.progressNotifier = progressNotifier;
|
|
65
|
+
this.metricsService = metricsService;
|
|
66
|
+
this.rateLimiter = rateLimiter;
|
|
67
|
+
this.retryService = retryService;
|
|
68
|
+
this.circuitBreaker = circuitBreaker;
|
|
69
|
+
this.batchExecutor = batchExecutor;
|
|
48
70
|
}
|
|
49
71
|
getServerInfo() {
|
|
50
72
|
const config = this.configHolder.getConfig();
|
|
@@ -117,6 +139,10 @@ let McpServerService = class McpServerService {
|
|
|
117
139
|
case "tools/call":
|
|
118
140
|
response = await this.handleCallTool(request);
|
|
119
141
|
return response;
|
|
142
|
+
case "tools/batch":
|
|
143
|
+
response = await this.handleBatchTools(request);
|
|
144
|
+
logger_util_1.logger.audit("McpServerService", "tools/batch", response.error ? "failure" : "success", { method: request.method }, request.id, this.getActorIdentifier(request));
|
|
145
|
+
return response;
|
|
120
146
|
case "resources/list":
|
|
121
147
|
response = this.handleListResources(request);
|
|
122
148
|
logger_util_1.logger.audit("McpServerService", "resources/list", response.error ? "failure" : "success", { method: request.method }, request.id, this.getActorIdentifier(request));
|
|
@@ -315,8 +341,41 @@ let McpServerService = class McpServerService {
|
|
|
315
341
|
}
|
|
316
342
|
this.cancellationTokens.set(request.id, cancellationToken);
|
|
317
343
|
}
|
|
344
|
+
const context = this.contextProvider.extractContext(request);
|
|
345
|
+
if (this.circuitBreaker?.isOpen(toolName)) {
|
|
346
|
+
logger_util_1.logger.audit("McpServerService", "tools/call", "failure", {
|
|
347
|
+
reason: "Circuit breaker open",
|
|
348
|
+
toolName: (0, sanitize_util_1.sanitizeName)(toolName),
|
|
349
|
+
method: request.method,
|
|
350
|
+
}, request.id, actorId);
|
|
351
|
+
return (0, jsonrpc_interface_1.createJsonRpcError)(request.id, mcp_protocol_interface_1.McpErrorCode.ToolExecutionError, "Service temporarily unavailable");
|
|
352
|
+
}
|
|
353
|
+
if (tool.rateLimit && this.rateLimiter) {
|
|
354
|
+
const rawIdentifier = context?.userId || context?.sessionId || context?.metadata?.ip || "anonymous";
|
|
355
|
+
const identifier = (0, sanitize_util_1.hashRateLimitIdentifier)(rawIdentifier);
|
|
356
|
+
const rateLimitResult = this.rateLimiter.checkRateLimit(toolName, identifier, tool.rateLimit);
|
|
357
|
+
if (!rateLimitResult.allowed) {
|
|
358
|
+
logger_util_1.logger.audit("McpServerService", "tools/call", "failure", {
|
|
359
|
+
reason: "Rate limit exceeded",
|
|
360
|
+
toolName: (0, sanitize_util_1.sanitizeName)(toolName),
|
|
361
|
+
method: request.method,
|
|
362
|
+
}, request.id, actorId);
|
|
363
|
+
return (0, jsonrpc_interface_1.createJsonRpcError)(request.id, jsonrpc_interface_1.JsonRpcErrorCode.InvalidRequest, `Rate limit exceeded. Try again after ${new Date(rateLimitResult.resetTime).toISOString()}`);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
const progressCallback = this.progressNotifier?.createProgressCallback(request.id);
|
|
367
|
+
const executeTool = async () => {
|
|
368
|
+
return await this.toolRegistry.executeTool(toolName, args, cancellationToken, context, progressCallback);
|
|
369
|
+
};
|
|
318
370
|
try {
|
|
319
|
-
|
|
371
|
+
let toolResult;
|
|
372
|
+
if (tool.retry && this.retryService) {
|
|
373
|
+
toolResult = await this.retryService.executeWithRetry(executeTool, tool.retry);
|
|
374
|
+
}
|
|
375
|
+
else {
|
|
376
|
+
toolResult = await executeTool();
|
|
377
|
+
}
|
|
378
|
+
this.circuitBreaker?.recordSuccess(toolName);
|
|
320
379
|
if (cancellationToken.isCancelled) {
|
|
321
380
|
return (0, jsonrpc_interface_1.createJsonRpcError)(request.id, mcp_protocol_interface_1.McpErrorCode.RequestCancelled, "Request was cancelled");
|
|
322
381
|
}
|
|
@@ -338,6 +397,7 @@ let McpServerService = class McpServerService {
|
|
|
338
397
|
return (0, jsonrpc_interface_1.createJsonRpcSuccess)(request.id, result);
|
|
339
398
|
}
|
|
340
399
|
catch (error) {
|
|
400
|
+
this.circuitBreaker?.recordFailure(toolName);
|
|
341
401
|
if (error instanceof easy_mcp_error_1.ToolNotFoundError) {
|
|
342
402
|
logger_util_1.logger.audit("McpServerService", "tools/call", "failure", {
|
|
343
403
|
reason: "ToolNotFoundError",
|
|
@@ -370,7 +430,132 @@ let McpServerService = class McpServerService {
|
|
|
370
430
|
finally {
|
|
371
431
|
if (request.id !== null && request.id !== undefined) {
|
|
372
432
|
this.cancellationTokens.delete(request.id);
|
|
433
|
+
this.progressNotifier?.cleanup(request.id);
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
async handleBatchTools(request) {
|
|
438
|
+
const params = request.params;
|
|
439
|
+
const actorId = this.getActorIdentifier(request);
|
|
440
|
+
if (!params || !Array.isArray(params.tools)) {
|
|
441
|
+
return (0, jsonrpc_interface_1.createJsonRpcError)(request.id, jsonrpc_interface_1.JsonRpcErrorCode.InvalidParams, "Missing or invalid tools array");
|
|
442
|
+
}
|
|
443
|
+
if (params.tools.length > 100) {
|
|
444
|
+
return (0, jsonrpc_interface_1.createJsonRpcError)(request.id, jsonrpc_interface_1.JsonRpcErrorCode.InvalidParams, "Batch size exceeds maximum limit of 100 tools");
|
|
445
|
+
}
|
|
446
|
+
if (!this.batchExecutor) {
|
|
447
|
+
return (0, jsonrpc_interface_1.createJsonRpcError)(request.id, jsonrpc_interface_1.JsonRpcErrorCode.MethodNotFound, "Batch execution not available");
|
|
448
|
+
}
|
|
449
|
+
const context = this.contextProvider.extractContext(request);
|
|
450
|
+
const cancellationToken = {
|
|
451
|
+
isCancelled: false,
|
|
452
|
+
onCancel: () => { },
|
|
453
|
+
cancel: () => {
|
|
454
|
+
cancellationToken.isCancelled = true;
|
|
455
|
+
},
|
|
456
|
+
};
|
|
457
|
+
if (request.id != null) {
|
|
458
|
+
this.cancellationTokens.set(request.id, cancellationToken);
|
|
459
|
+
}
|
|
460
|
+
const progressCallback = this.progressNotifier?.createProgressCallback(request.id);
|
|
461
|
+
try {
|
|
462
|
+
const batchRequests = [];
|
|
463
|
+
const validationErrors = [];
|
|
464
|
+
for (const toolRequest of params.tools) {
|
|
465
|
+
if (!toolRequest.name || typeof toolRequest.name !== "string") {
|
|
466
|
+
validationErrors.push({
|
|
467
|
+
tool: String(toolRequest.name || "[unknown]"),
|
|
468
|
+
error: "Invalid tool name",
|
|
469
|
+
});
|
|
470
|
+
continue;
|
|
471
|
+
}
|
|
472
|
+
const toolName = toolRequest.name.trim();
|
|
473
|
+
if (toolName.length === 0) {
|
|
474
|
+
validationErrors.push({
|
|
475
|
+
tool: toolName,
|
|
476
|
+
error: "Tool name cannot be empty",
|
|
477
|
+
});
|
|
478
|
+
continue;
|
|
479
|
+
}
|
|
480
|
+
let args = {};
|
|
481
|
+
if (toolRequest.arguments !== undefined && toolRequest.arguments !== null) {
|
|
482
|
+
if (typeof toolRequest.arguments !== "object" || Array.isArray(toolRequest.arguments)) {
|
|
483
|
+
validationErrors.push({
|
|
484
|
+
tool: toolName,
|
|
485
|
+
error: "Arguments must be a plain object",
|
|
486
|
+
});
|
|
487
|
+
continue;
|
|
488
|
+
}
|
|
489
|
+
args = toolRequest.arguments;
|
|
490
|
+
}
|
|
491
|
+
const tool = this.toolRegistry.getTool(toolName);
|
|
492
|
+
if (!tool) {
|
|
493
|
+
validationErrors.push({
|
|
494
|
+
tool: toolName,
|
|
495
|
+
error: "Tool not found",
|
|
496
|
+
});
|
|
497
|
+
continue;
|
|
498
|
+
}
|
|
499
|
+
const validationError = (0, schema_validator_1.validateToolArguments)(args, tool.inputSchema);
|
|
500
|
+
if (validationError) {
|
|
501
|
+
validationErrors.push({
|
|
502
|
+
tool: toolName,
|
|
503
|
+
error: validationError,
|
|
504
|
+
});
|
|
505
|
+
continue;
|
|
506
|
+
}
|
|
507
|
+
batchRequests.push({
|
|
508
|
+
tool: toolName,
|
|
509
|
+
args,
|
|
510
|
+
});
|
|
511
|
+
}
|
|
512
|
+
if (validationErrors.length > 0) {
|
|
513
|
+
logger_util_1.logger.audit("McpServerService", "tools/batch", "failure", {
|
|
514
|
+
method: request.method,
|
|
515
|
+
validationErrors: validationErrors.length,
|
|
516
|
+
}, request.id, actorId);
|
|
517
|
+
return (0, jsonrpc_interface_1.createJsonRpcError)(request.id, jsonrpc_interface_1.JsonRpcErrorCode.InvalidParams, `Batch validation failed: ${validationErrors.length} tool(s) have invalid parameters`);
|
|
518
|
+
}
|
|
519
|
+
const batchResults = await this.batchExecutor.executeBatch(batchRequests, cancellationToken, context, progressCallback);
|
|
520
|
+
for (const result of batchResults) {
|
|
521
|
+
logger_util_1.logger.audit("McpServerService", "tools/batch/tool", result.success ? "success" : "failure", {
|
|
522
|
+
method: request.method,
|
|
523
|
+
toolName: (0, sanitize_util_1.sanitizeName)(result.tool),
|
|
524
|
+
batchRequestId: request.id,
|
|
525
|
+
}, request.id, actorId);
|
|
526
|
+
}
|
|
527
|
+
const result = {
|
|
528
|
+
results: batchResults.map((br) => ({
|
|
529
|
+
tool: br.tool,
|
|
530
|
+
success: br.success,
|
|
531
|
+
result: br.success
|
|
532
|
+
? {
|
|
533
|
+
content: [
|
|
534
|
+
{
|
|
535
|
+
type: "text",
|
|
536
|
+
text: (0, sanitize_util_1.sanitizeToolResult)(br.result),
|
|
537
|
+
},
|
|
538
|
+
],
|
|
539
|
+
isError: false,
|
|
540
|
+
}
|
|
541
|
+
: undefined,
|
|
542
|
+
error: br.success ? undefined : br.error,
|
|
543
|
+
})),
|
|
544
|
+
};
|
|
545
|
+
return (0, jsonrpc_interface_1.createJsonRpcSuccess)(request.id, result);
|
|
546
|
+
}
|
|
547
|
+
catch (error) {
|
|
548
|
+
logger_util_1.logger.error("McpServerService", "Batch tool execution failed", {
|
|
549
|
+
component: "Layer 3",
|
|
550
|
+
error: (0, sanitize_util_1.sanitizeErrorMessage)(error),
|
|
551
|
+
});
|
|
552
|
+
return (0, jsonrpc_interface_1.createJsonRpcError)(request.id, mcp_protocol_interface_1.McpErrorCode.ToolExecutionError, "Batch execution failed");
|
|
553
|
+
}
|
|
554
|
+
finally {
|
|
555
|
+
if (request.id != null) {
|
|
556
|
+
this.cancellationTokens.delete(request.id);
|
|
373
557
|
}
|
|
558
|
+
this.progressNotifier?.cleanup(request.id);
|
|
374
559
|
}
|
|
375
560
|
}
|
|
376
561
|
handleCancelRequest(request) {
|
|
@@ -566,9 +751,22 @@ exports.McpServerService = McpServerService = __decorate([
|
|
|
566
751
|
(0, common_1.Injectable)(),
|
|
567
752
|
__param(3, (0, common_1.Inject)(constants_1.INTERFACE_LAYER_TOKEN)),
|
|
568
753
|
__param(5, (0, common_1.Inject)(constants_2.CONFIG_TOKEN)),
|
|
754
|
+
__param(7, (0, common_2.Optional)()),
|
|
755
|
+
__param(8, (0, common_2.Optional)()),
|
|
756
|
+
__param(9, (0, common_2.Optional)()),
|
|
757
|
+
__param(10, (0, common_2.Optional)()),
|
|
758
|
+
__param(11, (0, common_2.Optional)()),
|
|
759
|
+
__param(12, (0, common_2.Optional)()),
|
|
569
760
|
__metadata("design:paramtypes", [tool_registry_service_1.ToolRegistryService,
|
|
570
761
|
resource_registry_service_1.ResourceRegistryService,
|
|
571
762
|
prompt_registry_service_1.PromptRegistryService, Object, stdio_gateway_service_1.StdioGatewayService,
|
|
572
|
-
config_holder_service_1.ConfigHolderService
|
|
763
|
+
config_holder_service_1.ConfigHolderService,
|
|
764
|
+
context_provider_service_1.ContextProviderService,
|
|
765
|
+
progress_notifier_service_1.ProgressNotifierService,
|
|
766
|
+
metrics_service_1.MetricsService,
|
|
767
|
+
rate_limiter_service_1.RateLimiterService,
|
|
768
|
+
retry_service_1.RetryService,
|
|
769
|
+
circuit_breaker_service_1.CircuitBreakerService,
|
|
770
|
+
batch_executor_service_1.BatchExecutorService])
|
|
573
771
|
], McpServerService);
|
|
574
772
|
//# sourceMappingURL=mcp-server.service.js.map
|