easy-mcp-nest 0.1.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 (82) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +417 -0
  3. package/dist/EasyMCP.d.ts +8 -0
  4. package/dist/EasyMCP.js +105 -0
  5. package/dist/EasyMCP.js.map +1 -0
  6. package/dist/app.controller.d.ts +6 -0
  7. package/dist/app.controller.js +35 -0
  8. package/dist/app.controller.js.map +1 -0
  9. package/dist/app.module.d.ts +2 -0
  10. package/dist/app.module.js +34 -0
  11. package/dist/app.module.js.map +1 -0
  12. package/dist/app.service.d.ts +3 -0
  13. package/dist/app.service.js +20 -0
  14. package/dist/app.service.js.map +1 -0
  15. package/dist/config/config-holder.service.d.ts +6 -0
  16. package/dist/config/config-holder.service.js +32 -0
  17. package/dist/config/config-holder.service.js.map +1 -0
  18. package/dist/config/config-validator.d.ts +5 -0
  19. package/dist/config/config-validator.js +78 -0
  20. package/dist/config/config-validator.js.map +1 -0
  21. package/dist/config/constants.d.ts +4 -0
  22. package/dist/config/constants.js +8 -0
  23. package/dist/config/constants.js.map +1 -0
  24. package/dist/config/mcp-config.interface.d.ts +18 -0
  25. package/dist/config/mcp-config.interface.js +3 -0
  26. package/dist/config/mcp-config.interface.js.map +1 -0
  27. package/dist/config/version.d.ts +4 -0
  28. package/dist/config/version.js +41 -0
  29. package/dist/config/version.js.map +1 -0
  30. package/dist/core/core.module.d.ts +2 -0
  31. package/dist/core/core.module.js +24 -0
  32. package/dist/core/core.module.js.map +1 -0
  33. package/dist/core/errors/easy-mcp-error.d.ts +14 -0
  34. package/dist/core/errors/easy-mcp-error.js +39 -0
  35. package/dist/core/errors/easy-mcp-error.js.map +1 -0
  36. package/dist/core/mcp-server/mcp-server.service.d.ts +22 -0
  37. package/dist/core/mcp-server/mcp-server.service.js +285 -0
  38. package/dist/core/mcp-server/mcp-server.service.js.map +1 -0
  39. package/dist/core/utils/logger.util.d.ts +26 -0
  40. package/dist/core/utils/logger.util.js +44 -0
  41. package/dist/core/utils/logger.util.js.map +1 -0
  42. package/dist/core/utils/nestjs-stderr-logger.d.ts +9 -0
  43. package/dist/core/utils/nestjs-stderr-logger.js +123 -0
  44. package/dist/core/utils/nestjs-stderr-logger.js.map +1 -0
  45. package/dist/core/utils/sanitize.util.d.ts +6 -0
  46. package/dist/core/utils/sanitize.util.js +111 -0
  47. package/dist/core/utils/sanitize.util.js.map +1 -0
  48. package/dist/core/utils/schema-validator.d.ts +2 -0
  49. package/dist/core/utils/schema-validator.js +62 -0
  50. package/dist/core/utils/schema-validator.js.map +1 -0
  51. package/dist/index.d.ts +11 -0
  52. package/dist/index.js +22 -0
  53. package/dist/index.js.map +1 -0
  54. package/dist/interface/interface.interface.d.ts +4 -0
  55. package/dist/interface/interface.interface.js +3 -0
  56. package/dist/interface/interface.interface.js.map +1 -0
  57. package/dist/interface/interface.module.d.ts +2 -0
  58. package/dist/interface/interface.module.js +29 -0
  59. package/dist/interface/interface.module.js.map +1 -0
  60. package/dist/interface/jsonrpc.interface.d.ts +27 -0
  61. package/dist/interface/jsonrpc.interface.js +42 -0
  62. package/dist/interface/jsonrpc.interface.js.map +1 -0
  63. package/dist/interface/mcp-protocol.interface.d.ts +58 -0
  64. package/dist/interface/mcp-protocol.interface.js +13 -0
  65. package/dist/interface/mcp-protocol.interface.js.map +1 -0
  66. package/dist/interface/mcp.interface.d.ts +44 -0
  67. package/dist/interface/mcp.interface.js +3 -0
  68. package/dist/interface/mcp.interface.js.map +1 -0
  69. package/dist/interface/stdio-gateway.service.d.ts +20 -0
  70. package/dist/interface/stdio-gateway.service.js +373 -0
  71. package/dist/interface/stdio-gateway.service.js.map +1 -0
  72. package/dist/main.d.ts +1 -0
  73. package/dist/main.js +17 -0
  74. package/dist/main.js.map +1 -0
  75. package/dist/tooling/tool-registry/tool-registry.service.d.ts +23 -0
  76. package/dist/tooling/tool-registry/tool-registry.service.js +122 -0
  77. package/dist/tooling/tool-registry/tool-registry.service.js.map +1 -0
  78. package/dist/tooling/tool.interface.d.ts +13 -0
  79. package/dist/tooling/tool.interface.js +3 -0
  80. package/dist/tooling/tool.interface.js.map +1 -0
  81. package/dist/tsconfig.build.tsbuildinfo +1 -0
  82. package/package.json +104 -0
@@ -0,0 +1,58 @@
1
+ export interface InitializeParams {
2
+ protocolVersion: string;
3
+ capabilities?: {
4
+ tools?: {};
5
+ resources?: {};
6
+ prompts?: {};
7
+ };
8
+ clientInfo?: {
9
+ name: string;
10
+ version: string;
11
+ };
12
+ }
13
+ export interface InitializeResult {
14
+ protocolVersion: string;
15
+ capabilities: {
16
+ tools?: {};
17
+ resources?: {};
18
+ prompts?: {};
19
+ };
20
+ serverInfo: {
21
+ name: string;
22
+ version: string;
23
+ };
24
+ }
25
+ export interface McpTool {
26
+ name: string;
27
+ description: string;
28
+ inputSchema: {
29
+ type: "object";
30
+ properties: Record<string, any>;
31
+ required?: string[];
32
+ };
33
+ }
34
+ export interface ListToolsResult {
35
+ tools: McpTool[];
36
+ }
37
+ export interface CallToolParams {
38
+ name: string;
39
+ arguments?: Record<string, any>;
40
+ }
41
+ export interface CallToolResult {
42
+ content: Array<{
43
+ type: "text" | "image" | "resource";
44
+ text?: string;
45
+ data?: string;
46
+ mimeType?: string;
47
+ uri?: string;
48
+ }>;
49
+ isError?: boolean;
50
+ }
51
+ export declare enum McpErrorCode {
52
+ InvalidRequest = -32600,
53
+ MethodNotFound = -32601,
54
+ InvalidParams = -32602,
55
+ InternalError = -32603,
56
+ ToolNotFound = -32001,
57
+ ToolExecutionError = -32002
58
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.McpErrorCode = void 0;
4
+ var McpErrorCode;
5
+ (function (McpErrorCode) {
6
+ McpErrorCode[McpErrorCode["InvalidRequest"] = -32600] = "InvalidRequest";
7
+ McpErrorCode[McpErrorCode["MethodNotFound"] = -32601] = "MethodNotFound";
8
+ McpErrorCode[McpErrorCode["InvalidParams"] = -32602] = "InvalidParams";
9
+ McpErrorCode[McpErrorCode["InternalError"] = -32603] = "InternalError";
10
+ McpErrorCode[McpErrorCode["ToolNotFound"] = -32001] = "ToolNotFound";
11
+ McpErrorCode[McpErrorCode["ToolExecutionError"] = -32002] = "ToolExecutionError";
12
+ })(McpErrorCode || (exports.McpErrorCode = McpErrorCode = {}));
13
+ //# sourceMappingURL=mcp-protocol.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-protocol.interface.js","sourceRoot":"","sources":["../../src/interface/mcp-protocol.interface.ts"],"names":[],"mappings":";;;AAkFA,IAAY,YAOX;AAPD,WAAY,YAAY;IACtB,wEAAuB,CAAA;IACvB,wEAAuB,CAAA;IACvB,sEAAsB,CAAA;IACtB,sEAAsB,CAAA;IACtB,oEAAqB,CAAA;IACrB,gFAA2B,CAAA;AAC7B,CAAC,EAPW,YAAY,4BAAZ,YAAY,QAOvB"}
@@ -0,0 +1,44 @@
1
+ export interface McpInput {
2
+ sessionId: string;
3
+ query: string;
4
+ modelName?: string;
5
+ metadata?: Record<string, any>;
6
+ }
7
+ export interface McpOutput {
8
+ response: string;
9
+ modelUsed: string;
10
+ tokenUsage: {
11
+ promptTokens: number;
12
+ completionTokens: number;
13
+ totalTokens: number;
14
+ };
15
+ toolCall?: {
16
+ functionName: string;
17
+ arguments: Record<string, any>;
18
+ };
19
+ }
20
+ export interface McpMessageInput {
21
+ sessionId: string;
22
+ text: string;
23
+ metadata?: Record<string, any>;
24
+ toolResult?: {
25
+ name: string;
26
+ result: Record<string, any> | string;
27
+ };
28
+ }
29
+ export interface McpMessageOutput {
30
+ sessionId: string;
31
+ response: string;
32
+ action?: {
33
+ name: string;
34
+ args: Record<string, any>;
35
+ };
36
+ metadata?: {
37
+ modelUsed: string;
38
+ tokenUsage: {
39
+ promptTokens: number;
40
+ completionTokens: number;
41
+ totalTokens: number;
42
+ };
43
+ };
44
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=mcp.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp.interface.js","sourceRoot":"","sources":["../../src/interface/mcp.interface.ts"],"names":[],"mappings":""}
@@ -0,0 +1,20 @@
1
+ import { IInterfaceLayer } from "./interface.interface";
2
+ import { McpServerService } from "../core/mcp-server/mcp-server.service";
3
+ export declare class StdioGatewayService implements IInterfaceLayer {
4
+ private mcpServerService;
5
+ private rl;
6
+ private isRunning;
7
+ private pendingContentLength;
8
+ private messageBuffer;
9
+ private signalHandlers;
10
+ private contentLengthTimeout;
11
+ constructor();
12
+ setMcpServerService(service: McpServerService): void;
13
+ start(): Promise<void>;
14
+ private handleLine;
15
+ private processRequest;
16
+ sendMessage(sessionId: string, _output: unknown): Promise<void>;
17
+ private handleRequest;
18
+ private sendResponse;
19
+ private shutdown;
20
+ }
@@ -0,0 +1,373 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
19
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
20
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
21
+ 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;
22
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
23
+ };
24
+ var __importStar = (this && this.__importStar) || (function () {
25
+ var ownKeys = function(o) {
26
+ ownKeys = Object.getOwnPropertyNames || function (o) {
27
+ var ar = [];
28
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
29
+ return ar;
30
+ };
31
+ return ownKeys(o);
32
+ };
33
+ return function (mod) {
34
+ if (mod && mod.__esModule) return mod;
35
+ var result = {};
36
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
37
+ __setModuleDefault(result, mod);
38
+ return result;
39
+ };
40
+ })();
41
+ var __metadata = (this && this.__metadata) || function (k, v) {
42
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
43
+ };
44
+ Object.defineProperty(exports, "__esModule", { value: true });
45
+ exports.StdioGatewayService = void 0;
46
+ const common_1 = require("@nestjs/common");
47
+ const jsonrpc_interface_1 = require("./jsonrpc.interface");
48
+ const constants_1 = require("../config/constants");
49
+ const logger_util_1 = require("../core/utils/logger.util");
50
+ const sanitize_util_1 = require("../core/utils/sanitize.util");
51
+ const readline = __importStar(require("readline"));
52
+ let StdioGatewayService = class StdioGatewayService {
53
+ mcpServerService;
54
+ rl;
55
+ isRunning = false;
56
+ pendingContentLength = null;
57
+ messageBuffer = Buffer.alloc(0);
58
+ signalHandlers = [];
59
+ contentLengthTimeout = null;
60
+ constructor() {
61
+ logger_util_1.logger.info("StdioGatewayService", "StdioGatewayService initialized", {
62
+ component: "Layer 1: Interface",
63
+ });
64
+ }
65
+ setMcpServerService(service) {
66
+ this.mcpServerService = service;
67
+ }
68
+ async start() {
69
+ if (this.isRunning) {
70
+ logger_util_1.logger.warn("StdioGatewayService", "StdioGatewayService is already running", {
71
+ component: "Layer 1",
72
+ });
73
+ return;
74
+ }
75
+ logger_util_1.logger.info("StdioGatewayService", "Starting stdio JSON-RPC server", {
76
+ component: "Layer 1",
77
+ });
78
+ logger_util_1.logger.info("StdioGatewayService", "Server is running and listening for JSON-RPC requests", {
79
+ component: "Layer 1",
80
+ });
81
+ this.isRunning = true;
82
+ this.pendingContentLength = null;
83
+ this.messageBuffer = Buffer.alloc(0);
84
+ this.rl = readline.createInterface({
85
+ input: process.stdin,
86
+ output: process.stdout,
87
+ terminal: false,
88
+ });
89
+ this.rl.on("line", (line) => {
90
+ this.handleLine(line).catch((error) => {
91
+ logger_util_1.logger.error("StdioGatewayService", "Error handling line", {
92
+ component: "Layer 1",
93
+ error: (0, sanitize_util_1.sanitizeErrorMessage)(error),
94
+ });
95
+ });
96
+ });
97
+ this.rl.on("close", () => {
98
+ logger_util_1.logger.info("StdioGatewayService", "stdin closed, shutting down", {
99
+ component: "Layer 1",
100
+ });
101
+ this.isRunning = false;
102
+ });
103
+ const sigintHandler = () => {
104
+ this.shutdown();
105
+ };
106
+ const sigtermHandler = () => {
107
+ this.shutdown();
108
+ };
109
+ process.on("SIGINT", sigintHandler);
110
+ process.on("SIGTERM", sigtermHandler);
111
+ this.signalHandlers = [
112
+ { signal: "SIGINT", handler: sigintHandler },
113
+ { signal: "SIGTERM", handler: sigtermHandler },
114
+ ];
115
+ }
116
+ async handleLine(line) {
117
+ if (this.pendingContentLength !== null) {
118
+ const lineBytes = Buffer.from(line + "\n", "utf8");
119
+ this.messageBuffer = Buffer.concat([this.messageBuffer, lineBytes]);
120
+ if (this.messageBuffer.length >= this.pendingContentLength) {
121
+ if (this.contentLengthTimeout) {
122
+ clearTimeout(this.contentLengthTimeout);
123
+ this.contentLengthTimeout = null;
124
+ }
125
+ const messageBytes = this.messageBuffer.subarray(0, this.pendingContentLength);
126
+ const message = messageBytes.toString("utf8");
127
+ this.pendingContentLength = null;
128
+ this.messageBuffer = Buffer.alloc(0);
129
+ await this.processRequest(message);
130
+ }
131
+ return;
132
+ }
133
+ if (!line.trim()) {
134
+ return;
135
+ }
136
+ const trimmedLine = line.trim();
137
+ const contentLengthMatch = trimmedLine.match(/^Content-Length:\s*(\d+)\s*$/i);
138
+ if (contentLengthMatch) {
139
+ if (this.pendingContentLength !== null) {
140
+ logger_util_1.logger.error("StdioGatewayService", "Received Content-Length header while already processing a message", {
141
+ component: "Layer 1",
142
+ existingLength: this.pendingContentLength,
143
+ newLength: contentLengthMatch[1],
144
+ });
145
+ this.pendingContentLength = null;
146
+ this.messageBuffer = Buffer.alloc(0);
147
+ if (this.contentLengthTimeout) {
148
+ clearTimeout(this.contentLengthTimeout);
149
+ this.contentLengthTimeout = null;
150
+ }
151
+ }
152
+ const contentLengthStr = contentLengthMatch[1];
153
+ const contentLength = parseInt(contentLengthStr, 10);
154
+ if (isNaN(contentLength) || contentLength < 0 || !Number.isInteger(contentLength)) {
155
+ logger_util_1.logger.error("StdioGatewayService", "Invalid Content-Length value (must be non-negative integer)", {
156
+ component: "Layer 1",
157
+ receivedValue: contentLengthStr,
158
+ });
159
+ return;
160
+ }
161
+ if (contentLength.toString() !== contentLengthStr) {
162
+ logger_util_1.logger.error("StdioGatewayService", "Content-Length value overflow or invalid format", {
163
+ component: "Layer 1",
164
+ receivedValue: contentLengthStr,
165
+ });
166
+ return;
167
+ }
168
+ if (contentLength > constants_1.MAX_CONTENT_LENGTH) {
169
+ logger_util_1.logger.error("StdioGatewayService", "Content-Length exceeds maximum allowed size", {
170
+ component: "Layer 1",
171
+ contentLength,
172
+ maxAllowed: constants_1.MAX_CONTENT_LENGTH,
173
+ });
174
+ if (this.contentLengthTimeout) {
175
+ clearTimeout(this.contentLengthTimeout);
176
+ this.contentLengthTimeout = null;
177
+ }
178
+ this.pendingContentLength = null;
179
+ this.messageBuffer = Buffer.alloc(0);
180
+ return;
181
+ }
182
+ this.pendingContentLength = contentLength;
183
+ this.messageBuffer = Buffer.alloc(0);
184
+ this.contentLengthTimeout = setTimeout(() => {
185
+ logger_util_1.logger.error("StdioGatewayService", "Content-Length timeout: message body not received within timeout period", {
186
+ component: "Layer 1",
187
+ contentLength,
188
+ timeoutMs: 30000,
189
+ });
190
+ this.pendingContentLength = null;
191
+ this.messageBuffer = Buffer.alloc(0);
192
+ this.contentLengthTimeout = null;
193
+ }, 30000);
194
+ return;
195
+ }
196
+ const lineBytes = Buffer.byteLength(line, "utf8");
197
+ if (lineBytes > constants_1.MAX_MESSAGE_SIZE_BYTES) {
198
+ logger_util_1.logger.error("StdioGatewayService", "Unframed message exceeds maximum size", {
199
+ component: "Layer 1",
200
+ messageSize: lineBytes,
201
+ maxAllowed: constants_1.MAX_MESSAGE_SIZE_BYTES,
202
+ });
203
+ return;
204
+ }
205
+ await this.processRequest(line);
206
+ }
207
+ async processRequest(message) {
208
+ if (!message.trim()) {
209
+ return;
210
+ }
211
+ const messageSize = Buffer.byteLength(message, "utf8");
212
+ if (messageSize > constants_1.MAX_MESSAGE_SIZE_BYTES) {
213
+ logger_util_1.logger.error("StdioGatewayService", "Message exceeds maximum allowed size", {
214
+ component: "Layer 1",
215
+ messageSize,
216
+ maxAllowed: constants_1.MAX_MESSAGE_SIZE_BYTES,
217
+ });
218
+ return;
219
+ }
220
+ let request = null;
221
+ try {
222
+ request = JSON.parse(message);
223
+ }
224
+ catch (error) {
225
+ logger_util_1.logger.error("StdioGatewayService", "JSON Parse Error", {
226
+ component: "Layer 1",
227
+ error: (0, sanitize_util_1.sanitizeErrorMessage)(error),
228
+ });
229
+ return;
230
+ }
231
+ if (!(0, jsonrpc_interface_1.isValidJsonRpcRequest)(request)) {
232
+ const requestId = request && typeof request === 'object' && ('id' in request) ? request.id : null;
233
+ const errorResponse = (0, jsonrpc_interface_1.createJsonRpcError)(requestId, jsonrpc_interface_1.JsonRpcErrorCode.InvalidRequest, "Invalid JSON-RPC request structure");
234
+ if (requestId !== null && requestId !== undefined) {
235
+ this.sendResponse(errorResponse);
236
+ }
237
+ logger_util_1.logger.warn("StdioGatewayService", "Invalid JSON-RPC request structure", {
238
+ component: "Layer 1",
239
+ requestId,
240
+ });
241
+ return;
242
+ }
243
+ try {
244
+ const response = await this.handleRequest(request);
245
+ this.sendResponse(response);
246
+ }
247
+ catch (err) {
248
+ const errorResponse = (0, jsonrpc_interface_1.createJsonRpcError)(request.id, jsonrpc_interface_1.JsonRpcErrorCode.InternalError, "Internal error during request handling");
249
+ this.sendResponse(errorResponse);
250
+ logger_util_1.logger.error("StdioGatewayService", "Internal error during request handling", {
251
+ component: "Layer 1",
252
+ requestId: request.id,
253
+ method: request.method,
254
+ error: (0, sanitize_util_1.sanitizeErrorMessage)(err),
255
+ });
256
+ }
257
+ }
258
+ async sendMessage(sessionId, _output) {
259
+ logger_util_1.logger.warn("StdioGatewayService", "sendMessage() called but stdio mode doesn't use sessions", {
260
+ component: "Layer 1",
261
+ sessionId,
262
+ });
263
+ }
264
+ async handleRequest(request) {
265
+ if (!this.mcpServerService) {
266
+ return (0, jsonrpc_interface_1.createJsonRpcError)(request.id, jsonrpc_interface_1.JsonRpcErrorCode.InternalError, "McpServerService not initialized");
267
+ }
268
+ try {
269
+ return await this.mcpServerService.handleRequest(request);
270
+ }
271
+ catch (err) {
272
+ logger_util_1.logger.error("StdioGatewayService", "Error in handleRequest", {
273
+ component: "Layer 1",
274
+ requestId: request.id,
275
+ error: (0, sanitize_util_1.sanitizeErrorMessage)(err),
276
+ });
277
+ return (0, jsonrpc_interface_1.createJsonRpcError)(request.id, jsonrpc_interface_1.JsonRpcErrorCode.InternalError, "Internal error");
278
+ }
279
+ }
280
+ sendResponse(response) {
281
+ try {
282
+ const json = JSON.stringify(response);
283
+ const useContentLength = process.env.MCP_USE_CONTENT_LENGTH === "1";
284
+ if (useContentLength) {
285
+ const contentLength = Buffer.byteLength(json, "utf8");
286
+ if (contentLength > constants_1.MAX_MESSAGE_SIZE_BYTES) {
287
+ logger_util_1.logger.error("StdioGatewayService", "Response exceeds maximum size for Content-Length framing", {
288
+ component: "Layer 1",
289
+ contentLength,
290
+ maxAllowed: constants_1.MAX_MESSAGE_SIZE_BYTES,
291
+ });
292
+ const errorResponse = (0, jsonrpc_interface_1.createJsonRpcError)(response.id, jsonrpc_interface_1.JsonRpcErrorCode.InternalError, "Response too large");
293
+ const errorJson = JSON.stringify(errorResponse);
294
+ const errorLength = Buffer.byteLength(errorJson, "utf8");
295
+ const errorMessage = `Content-Length: ${errorLength}\r\n\r\n${errorJson}`;
296
+ process.stdout.write(errorMessage);
297
+ return;
298
+ }
299
+ if (!Number.isInteger(contentLength) || contentLength < 0) {
300
+ logger_util_1.logger.error("StdioGatewayService", "Invalid content length calculated", {
301
+ component: "Layer 1",
302
+ contentLength,
303
+ });
304
+ return;
305
+ }
306
+ const message = `Content-Length: ${contentLength}\r\n\r\n${json}`;
307
+ process.stdout.write(message);
308
+ }
309
+ else {
310
+ const messageSize = Buffer.byteLength(json, "utf8");
311
+ if (messageSize > constants_1.MAX_MESSAGE_SIZE_BYTES) {
312
+ logger_util_1.logger.error("StdioGatewayService", "Response exceeds maximum size for newline-delimited JSON", {
313
+ component: "Layer 1",
314
+ messageSize,
315
+ maxAllowed: constants_1.MAX_MESSAGE_SIZE_BYTES,
316
+ });
317
+ const errorResponse = (0, jsonrpc_interface_1.createJsonRpcError)(response.id, jsonrpc_interface_1.JsonRpcErrorCode.InternalError, "Response too large");
318
+ process.stdout.write(JSON.stringify(errorResponse) + "\n");
319
+ return;
320
+ }
321
+ process.stdout.write(json + "\n");
322
+ }
323
+ }
324
+ catch (error) {
325
+ logger_util_1.logger.error("StdioGatewayService", "Failed to send response", {
326
+ component: "Layer 1",
327
+ error: (0, sanitize_util_1.sanitizeErrorMessage)(error),
328
+ });
329
+ try {
330
+ const errorResponse = (0, jsonrpc_interface_1.createJsonRpcError)(response?.id || null, jsonrpc_interface_1.JsonRpcErrorCode.InternalError, "Internal error");
331
+ const errorJson = JSON.stringify(errorResponse);
332
+ const useContentLength = process.env.MCP_USE_CONTENT_LENGTH === "1";
333
+ if (useContentLength) {
334
+ const errorLength = Buffer.byteLength(errorJson, "utf8");
335
+ process.stdout.write(`Content-Length: ${errorLength}\r\n\r\n${errorJson}`);
336
+ }
337
+ else {
338
+ process.stdout.write(errorJson + "\n");
339
+ }
340
+ }
341
+ catch {
342
+ logger_util_1.logger.error("StdioGatewayService", "Failed to send error response", {
343
+ component: "Layer 1",
344
+ });
345
+ }
346
+ }
347
+ }
348
+ shutdown() {
349
+ for (const { signal, handler } of this.signalHandlers) {
350
+ process.removeListener(signal, handler);
351
+ }
352
+ this.signalHandlers = [];
353
+ if (this.contentLengthTimeout) {
354
+ clearTimeout(this.contentLengthTimeout);
355
+ this.contentLengthTimeout = null;
356
+ }
357
+ if (this.rl) {
358
+ this.rl.close();
359
+ }
360
+ this.isRunning = false;
361
+ this.pendingContentLength = null;
362
+ this.messageBuffer = Buffer.alloc(0);
363
+ logger_util_1.logger.info("StdioGatewayService", "StdioGatewayService shut down", {
364
+ component: "Layer 1",
365
+ });
366
+ }
367
+ };
368
+ exports.StdioGatewayService = StdioGatewayService;
369
+ exports.StdioGatewayService = StdioGatewayService = __decorate([
370
+ (0, common_1.Injectable)(),
371
+ __metadata("design:paramtypes", [])
372
+ ], StdioGatewayService);
373
+ //# sourceMappingURL=stdio-gateway.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stdio-gateway.service.js","sourceRoot":"","sources":["../../src/interface/stdio-gateway.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA4C;AAG5C,2DAM6B;AAC7B,mDAAiF;AACjF,2DAAmD;AACnD,+DAAmE;AACnE,mDAAqC;AAG9B,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;IACtB,gBAAgB,CAAmB;IACnC,EAAE,CAAqB;IACvB,SAAS,GAAG,KAAK,CAAC;IAClB,oBAAoB,GAAkB,IAAI,CAAC;IAC3C,aAAa,GAAW,MAAM,CAAC,KAAK,CAA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1 @@
1
+ export {};
package/dist/main.js ADDED
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const EasyMCP_1 = require("./EasyMCP");
4
+ const version_1 = require("./config/version");
5
+ const mockConfig = {
6
+ tools: [],
7
+ serverInfo: {
8
+ name: version_1.PACKAGE_NAME,
9
+ version: version_1.VERSION,
10
+ },
11
+ };
12
+ async function bootstrap() {
13
+ await EasyMCP_1.EasyMCP.initialize(mockConfig);
14
+ void EasyMCP_1.EasyMCP.run();
15
+ }
16
+ void bootstrap();
17
+ //# sourceMappingURL=main.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":";;AAAA,uCAAoC;AAEpC,8CAAyD;AAGzD,MAAM,UAAU,GAAc;IAC5B,KAAK,EAAE,EAAE;IACT,UAAU,EAAE;QACV,IAAI,EAAE,sBAAY;QAClB,OAAO,EAAE,iBAAO;KACjB;CACF,CAAC;AAEF,KAAK,UAAU,SAAS;IACtB,MAAM,iBAAO,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;IAErC,KAAK,iBAAO,CAAC,GAAG,EAAE,CAAC;AACrB,CAAC;AACD,KAAK,SAAS,EAAE,CAAC"}
@@ -0,0 +1,23 @@
1
+ import { ToolDefinition, ToolParameter } from "../tool.interface";
2
+ import { ToolRegistrationInput } from "../../config/mcp-config.interface";
3
+ export interface LlmToolSchema {
4
+ type: "function";
5
+ function: {
6
+ name: string;
7
+ description: string;
8
+ parameters: {
9
+ type: "object";
10
+ properties: Record<string, ToolParameter>;
11
+ required: string[];
12
+ };
13
+ };
14
+ }
15
+ export declare class ToolRegistryService {
16
+ private readonly registry;
17
+ registerTool(definition: ToolDefinition): void;
18
+ getTool(name: string): ToolDefinition | undefined;
19
+ executeTool(name: string, args: Record<string, any>): Promise<any>;
20
+ registerToolFromConfig(toolInput: ToolRegistrationInput): void;
21
+ getToolSchemasForLLM(): LlmToolSchema[];
22
+ getToolsAsRegistrationInput(): ToolRegistrationInput[];
23
+ }