easy-mcp-nest 0.1.3 → 0.2.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/README.md +57 -27
- package/dist/EasyMCP.js +53 -1
- package/dist/EasyMCP.js.map +1 -1
- package/dist/app.module.js +3 -1
- package/dist/app.module.js.map +1 -1
- package/dist/config/config-validator.js +92 -20
- package/dist/config/config-validator.js.map +1 -1
- package/dist/config/constants.d.ts +3 -0
- package/dist/config/constants.js +4 -1
- package/dist/config/constants.js.map +1 -1
- package/dist/config/mcp-config.interface.d.ts +51 -5
- package/dist/core/core.module.js +3 -1
- package/dist/core/core.module.js.map +1 -1
- package/dist/core/mcp-server/mcp-server.service.d.ts +15 -1
- package/dist/core/mcp-server/mcp-server.service.js +324 -35
- package/dist/core/mcp-server/mcp-server.service.js.map +1 -1
- package/dist/core/utils/sanitize.util.d.ts +3 -0
- package/dist/core/utils/sanitize.util.js +51 -0
- package/dist/core/utils/sanitize.util.js.map +1 -1
- package/dist/core/utils/schema-validator.d.ts +6 -1
- package/dist/core/utils/schema-validator.js +15 -6
- package/dist/core/utils/schema-validator.js.map +1 -1
- package/dist/core/utils/tool-naming-validator.d.ts +4 -0
- package/dist/core/utils/tool-naming-validator.js +68 -0
- package/dist/core/utils/tool-naming-validator.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/interface/mcp-protocol.interface.d.ts +136 -2
- package/dist/interface/mcp-protocol.interface.js +6 -0
- package/dist/interface/mcp-protocol.interface.js.map +1 -1
- package/dist/prompts/prompt-registry.service.d.ts +28 -0
- package/dist/prompts/prompt-registry.service.js +55 -0
- package/dist/prompts/prompt-registry.service.js.map +1 -0
- package/dist/prompts/prompt.interface.d.ts +30 -0
- package/dist/prompts/prompt.interface.js +3 -0
- package/dist/prompts/prompt.interface.js.map +1 -0
- package/dist/prompts/prompt.module.d.ts +2 -0
- package/dist/prompts/prompt.module.js +21 -0
- package/dist/prompts/prompt.module.js.map +1 -0
- package/dist/resources/resource-registry.service.d.ts +18 -0
- package/dist/resources/resource-registry.service.js +56 -0
- package/dist/resources/resource-registry.service.js.map +1 -0
- package/dist/resources/resource.interface.d.ts +19 -0
- package/dist/resources/resource.interface.js +3 -0
- package/dist/resources/resource.interface.js.map +1 -0
- package/dist/resources/resource.module.d.ts +2 -0
- package/dist/resources/resource.module.js +21 -0
- package/dist/resources/resource.module.js.map +1 -0
- package/dist/tooling/tool-registry/tool-registry.service.d.ts +5 -3
- package/dist/tooling/tool-registry/tool-registry.service.js +82 -49
- package/dist/tooling/tool-registry/tool-registry.service.js.map +1 -1
- package/dist/tooling/tool.interface.d.ts +27 -7
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sanitize.util.js","sourceRoot":"","sources":["../../../src/core/utils/sanitize.util.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"sanitize.util.js","sourceRoot":"","sources":["../../../src/core/utils/sanitize.util.ts"],"names":[],"mappings":";;AAeA,0CAKC;AASD,sCA2BC;AAQD,wCAiCC;AAOD,4CAEC;AAOD,gDA4BC;AAOD,oDAeC;AAQD,4CAqBC;AAQD,kCAiCC;AAQD,oCAoBC;AA9PD,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC,CAAC,WAAW,EAAE,aAAa,EAAE,WAAW,CAAC,CAAC,CAAC;AAQ1E,SAAgB,eAAe,CAAC,GAAW;IACzC,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;QAC5B,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,CAAC,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAClC,CAAC;AASD,SAAgB,aAAa,CAAC,KAAU,EAAE,YAAoB,EAAE;IAC9D,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QAC1C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,CAAC;YAEnG,IAAI,IAAI,GAAG,CAAC,CAAC;YACb,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;gBAC1C,MAAM,IAAI,GAAG,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;gBACrC,IAAI,GAAG,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC;gBACnC,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;YACrB,CAAC;YACD,OAAO,QAAQ,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,GAAG,CAAC;QAChD,CAAC;QAGD,OAAO,SAAS,CAAC;IACnB,CAAC;IAAC,MAAM,CAAC;QAEP,OAAO,OAAO,CAAC;IACjB,CAAC;AACH,CAAC;AAQD,SAAgB,YAAY,CAAC,IAAY;IACvC,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QACtC,OAAO,gBAAgB,CAAC;IAC1B,CAAC;IAED,IAAI,CAAC;QAEH,IAAI,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,2BAA2B,EAAE,EAAE,CAAC,CAAC;QAG9D,MAAM,qBAAqB,GAAG,GAAG,CAAC;QAClC,IAAI,SAAS,CAAC,MAAM,GAAG,qBAAqB,EAAE,CAAC;YAC7C,SAAS,GAAG,SAAS,CAAC,SAAS,CAAC,CAAC,EAAE,qBAAqB,CAAC,CAAC;QAC5D,CAAC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;IAAC,MAAM,CAAC;QAEP,OAAO,QAAQ,CAAC;IAClB,CAAC;AACH,CAAC"}
|
|
@@ -1,2 +1,7 @@
|
|
|
1
1
|
import { ToolParameter } from "../../tooling/tool.interface";
|
|
2
|
-
export declare function validateToolArguments(args: Record<string, any>,
|
|
2
|
+
export declare function validateToolArguments(args: Record<string, any>, inputSchema: {
|
|
3
|
+
type: "object";
|
|
4
|
+
properties?: Record<string, ToolParameter>;
|
|
5
|
+
required?: string[];
|
|
6
|
+
additionalProperties?: boolean | Record<string, any>;
|
|
7
|
+
}): string | null;
|
|
@@ -1,20 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.validateToolArguments = validateToolArguments;
|
|
4
|
-
function validateToolArguments(args,
|
|
4
|
+
function validateToolArguments(args, inputSchema) {
|
|
5
|
+
const required = inputSchema.required || [];
|
|
5
6
|
for (const paramName of required) {
|
|
6
7
|
if (!(paramName in args) || args[paramName] === undefined || args[paramName] === null) {
|
|
7
8
|
return `Missing required parameter: ${paramName}`;
|
|
8
9
|
}
|
|
9
10
|
}
|
|
11
|
+
const properties = inputSchema.properties || {};
|
|
12
|
+
const additional = inputSchema.additionalProperties;
|
|
13
|
+
const allowUnknown = additional === undefined || additional === true || typeof additional === "object";
|
|
10
14
|
for (const [paramName, paramValue] of Object.entries(args)) {
|
|
11
|
-
const paramDef =
|
|
15
|
+
const paramDef = properties[paramName];
|
|
12
16
|
if (!paramDef) {
|
|
13
|
-
|
|
17
|
+
if (!allowUnknown) {
|
|
18
|
+
return `Unknown parameter: ${paramName}`;
|
|
19
|
+
}
|
|
20
|
+
continue;
|
|
14
21
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
22
|
+
if (paramDef.type !== undefined) {
|
|
23
|
+
const validationError = validateParameterType(paramName, paramValue, paramDef);
|
|
24
|
+
if (validationError) {
|
|
25
|
+
return validationError;
|
|
26
|
+
}
|
|
18
27
|
}
|
|
19
28
|
if (paramDef.enum && !paramDef.enum.includes(paramValue)) {
|
|
20
29
|
return `Parameter '${paramName}' must be one of: ${paramDef.enum.join(", ")}`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema-validator.js","sourceRoot":"","sources":["../../../src/core/utils/schema-validator.ts"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ACxE,OAAO,cAAc,SAAS,qBAAqB,CAAC;YACtD,CAAC;YACD,MAAM;QACR;YACE,OAAO,cAAc,SAAS,2BAA2B,QAAQ,CAAC,IAAI,EAAE,CAAC;IAC7E,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ToolNamingValidator = void 0;
|
|
4
|
+
class ToolNamingValidator {
|
|
5
|
+
static validate(name) {
|
|
6
|
+
if (!name || typeof name !== "string") {
|
|
7
|
+
return "Tool name must be a non-empty string";
|
|
8
|
+
}
|
|
9
|
+
if (name.length === 0) {
|
|
10
|
+
return "Tool name cannot be empty";
|
|
11
|
+
}
|
|
12
|
+
if (name.length > 100) {
|
|
13
|
+
return "Tool name must be 100 characters or less";
|
|
14
|
+
}
|
|
15
|
+
const validPattern = /^[a-z][a-z0-9_-]*$/;
|
|
16
|
+
if (!validPattern.test(name)) {
|
|
17
|
+
return "Tool name must start with a lowercase letter and contain only lowercase letters, numbers, underscores, and hyphens";
|
|
18
|
+
}
|
|
19
|
+
const reservedPatterns = [
|
|
20
|
+
/^_/,
|
|
21
|
+
/__/,
|
|
22
|
+
/-$/,
|
|
23
|
+
/^system/,
|
|
24
|
+
/^internal/,
|
|
25
|
+
];
|
|
26
|
+
for (const pattern of reservedPatterns) {
|
|
27
|
+
if (pattern.test(name)) {
|
|
28
|
+
return `Tool name '${name}' matches a reserved pattern`;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
static suggest(name) {
|
|
34
|
+
if (!name) {
|
|
35
|
+
return "tool_name";
|
|
36
|
+
}
|
|
37
|
+
let suggested = name.toLowerCase();
|
|
38
|
+
suggested = suggested.replace(/[\s.]+/g, "_");
|
|
39
|
+
suggested = suggested.replace(/[^a-z0-9_-]/g, "");
|
|
40
|
+
if (!/^[a-z]/.test(suggested)) {
|
|
41
|
+
suggested = "tool_" + suggested;
|
|
42
|
+
}
|
|
43
|
+
suggested = suggested.replace(/_+/g, "_");
|
|
44
|
+
suggested = suggested.replace(/^_+|_+$/g, "");
|
|
45
|
+
const reservedPatterns = [
|
|
46
|
+
/^system/,
|
|
47
|
+
/^internal/,
|
|
48
|
+
];
|
|
49
|
+
for (const pattern of reservedPatterns) {
|
|
50
|
+
if (pattern.test(suggested)) {
|
|
51
|
+
suggested = "skill_" + suggested;
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (/^_/.test(suggested)) {
|
|
56
|
+
suggested = "tool" + suggested;
|
|
57
|
+
}
|
|
58
|
+
if (/-$/.test(suggested)) {
|
|
59
|
+
suggested = suggested.slice(0, -1) + "_tool";
|
|
60
|
+
}
|
|
61
|
+
if (suggested.length === 0) {
|
|
62
|
+
suggested = "tool_name";
|
|
63
|
+
}
|
|
64
|
+
return suggested;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.ToolNamingValidator = ToolNamingValidator;
|
|
68
|
+
//# sourceMappingURL=tool-naming-validator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-naming-validator.js","sourceRoot":"","sources":["../../../src/core/utils/tool-naming-validator.ts"],"names":[],"mappings":";;;AASA,MAAa,mBAAmB;IAM9B,MAAM,CAAC,QAAQ,CAAC,IAAY;QAC1B,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;YACtC,OAAO,sCAAsC,CAAC;QAChD,CAAC;QAGD,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACtB,OAAO,2BAA2B,CAAC;QACrC,CAAC;QAED,IAAI,IAAI,CAAC,MAAM,GAAG,GAAG,EAAE,CAAC;YACtB,OAAO,0CAA0C,CAAC;QACpD,CAAC;QAID,MAAM,YAAY,GAAG,oBAAoB,CAAC;QAC1C,IAAI,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QAGD,IAAI,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;YACzB,SAAS,GAAG,MAAM,GAAG,SAAS,CAAC;QACjC,CAAC;QAGD,IAAI,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;YACzB,SAAS,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC;QAC/C,CAAC;QAGD,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC3B,SAAS,GAAG,WAAW,CAAC;QAC1B,CAAC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;CACF;AAzGD,kDAyGC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -7,5 +7,6 @@ export type { InitializeParams, InitializeResult, ListToolsResult, McpTool, Call
|
|
|
7
7
|
export { McpErrorCode } from './interface/mcp-protocol.interface';
|
|
8
8
|
export type { ToolDefinition, ToolParameter, ToolFunction, } from './tooling/tool.interface';
|
|
9
9
|
export { EasyMcpError, ConfigurationError, ToolExecutionError, ToolNotFoundError, } from './core/errors/easy-mcp-error';
|
|
10
|
+
export { ToolNamingValidator } from './core/utils/tool-naming-validator';
|
|
10
11
|
export { INTERFACE_LAYER_TOKEN } from './config/constants';
|
|
11
12
|
export { VERSION, PACKAGE_NAME, getVersion, getPackageName } from './config/version';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getPackageName = exports.getVersion = exports.PACKAGE_NAME = exports.VERSION = exports.INTERFACE_LAYER_TOKEN = exports.ToolNotFoundError = exports.ToolExecutionError = exports.ConfigurationError = exports.EasyMcpError = exports.McpErrorCode = exports.JsonRpcErrorCode = exports.EasyMCP = void 0;
|
|
3
|
+
exports.getPackageName = exports.getVersion = exports.PACKAGE_NAME = exports.VERSION = exports.INTERFACE_LAYER_TOKEN = exports.ToolNamingValidator = exports.ToolNotFoundError = exports.ToolExecutionError = exports.ConfigurationError = exports.EasyMcpError = exports.McpErrorCode = exports.JsonRpcErrorCode = exports.EasyMCP = void 0;
|
|
4
4
|
var EasyMCP_1 = require("./EasyMCP");
|
|
5
5
|
Object.defineProperty(exports, "EasyMCP", { enumerable: true, get: function () { return EasyMCP_1.EasyMCP; } });
|
|
6
6
|
var jsonrpc_interface_1 = require("./interface/jsonrpc.interface");
|
|
@@ -12,6 +12,8 @@ Object.defineProperty(exports, "EasyMcpError", { enumerable: true, get: function
|
|
|
12
12
|
Object.defineProperty(exports, "ConfigurationError", { enumerable: true, get: function () { return easy_mcp_error_1.ConfigurationError; } });
|
|
13
13
|
Object.defineProperty(exports, "ToolExecutionError", { enumerable: true, get: function () { return easy_mcp_error_1.ToolExecutionError; } });
|
|
14
14
|
Object.defineProperty(exports, "ToolNotFoundError", { enumerable: true, get: function () { return easy_mcp_error_1.ToolNotFoundError; } });
|
|
15
|
+
var tool_naming_validator_1 = require("./core/utils/tool-naming-validator");
|
|
16
|
+
Object.defineProperty(exports, "ToolNamingValidator", { enumerable: true, get: function () { return tool_naming_validator_1.ToolNamingValidator; } });
|
|
15
17
|
var constants_1 = require("./config/constants");
|
|
16
18
|
Object.defineProperty(exports, "INTERFACE_LAYER_TOKEN", { enumerable: true, get: function () { return constants_1.INTERFACE_LAYER_TOKEN; } });
|
|
17
19
|
var version_1 = require("./config/version");
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AACA,qCAAoC;AAA3B,kGAAA,OAAO,OAAA;AAmBhB,mEAAiE;AAAxD,qHAAA,gBAAgB,OAAA;AAYzB,6EAAkE;AAAzD,sHAAA,YAAY,OAAA;AAUrB,+DAKsC;AAJpC,8GAAA,YAAY,OAAA;AACZ,oHAAA,kBAAkB,OAAA;AAClB,oHAAA,kBAAkB,OAAA;AAClB,mHAAA,iBAAiB,OAAA;AAInB,gDAA2D;AAAlD,kHAAA,qBAAqB,OAAA;AAG9B,4CAAqF;AAA5E,kGAAA,OAAO,OAAA;AAAE,uGAAA,YAAY,OAAA;AAAE,qGAAA,UAAU,OAAA;AAAE,yGAAA,cAAc,OAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AACA,qCAAoC;AAA3B,kGAAA,OAAO,OAAA;AAmBhB,mEAAiE;AAAxD,qHAAA,gBAAgB,OAAA;AAYzB,6EAAkE;AAAzD,sHAAA,YAAY,OAAA;AAUrB,+DAKsC;AAJpC,8GAAA,YAAY,OAAA;AACZ,oHAAA,kBAAkB,OAAA;AAClB,oHAAA,kBAAkB,OAAA;AAClB,mHAAA,iBAAiB,OAAA;AAInB,4EAAyE;AAAhE,4HAAA,mBAAmB,OAAA;AAG5B,gDAA2D;AAAlD,kHAAA,qBAAqB,OAAA;AAG9B,4CAAqF;AAA5E,kGAAA,OAAO,OAAA;AAAE,uGAAA,YAAY,OAAA;AAAE,qGAAA,UAAU,OAAA;AAAE,yGAAA,cAAc,OAAA"}
|
|
@@ -4,6 +4,9 @@ export interface InitializeParams {
|
|
|
4
4
|
tools?: {};
|
|
5
5
|
resources?: {};
|
|
6
6
|
prompts?: {};
|
|
7
|
+
sampling?: {};
|
|
8
|
+
roots?: {};
|
|
9
|
+
elicitation?: {};
|
|
7
10
|
};
|
|
8
11
|
clientInfo?: {
|
|
9
12
|
name: string;
|
|
@@ -27,9 +30,11 @@ export interface McpTool {
|
|
|
27
30
|
description: string;
|
|
28
31
|
inputSchema: {
|
|
29
32
|
type: "object";
|
|
30
|
-
properties
|
|
33
|
+
properties?: Record<string, any>;
|
|
31
34
|
required?: string[];
|
|
35
|
+
[key: string]: any;
|
|
32
36
|
};
|
|
37
|
+
icon?: string;
|
|
33
38
|
}
|
|
34
39
|
export interface ListToolsResult {
|
|
35
40
|
tools: McpTool[];
|
|
@@ -48,11 +53,140 @@ export interface CallToolResult {
|
|
|
48
53
|
}>;
|
|
49
54
|
isError?: boolean;
|
|
50
55
|
}
|
|
56
|
+
export interface McpResource {
|
|
57
|
+
uri: string;
|
|
58
|
+
name: string;
|
|
59
|
+
description?: string;
|
|
60
|
+
mimeType?: string;
|
|
61
|
+
icon?: string;
|
|
62
|
+
}
|
|
63
|
+
export interface ListResourcesResult {
|
|
64
|
+
resources: McpResource[];
|
|
65
|
+
}
|
|
66
|
+
export interface ReadResourceParams {
|
|
67
|
+
uri: string;
|
|
68
|
+
}
|
|
69
|
+
export interface ReadResourceResult {
|
|
70
|
+
contents: Array<{
|
|
71
|
+
uri: string;
|
|
72
|
+
mimeType?: string;
|
|
73
|
+
text?: string;
|
|
74
|
+
blob?: string;
|
|
75
|
+
}>;
|
|
76
|
+
}
|
|
77
|
+
export interface McpPrompt {
|
|
78
|
+
name: string;
|
|
79
|
+
description?: string;
|
|
80
|
+
arguments?: Array<{
|
|
81
|
+
name: string;
|
|
82
|
+
description?: string;
|
|
83
|
+
required?: boolean;
|
|
84
|
+
}>;
|
|
85
|
+
icon?: string;
|
|
86
|
+
}
|
|
87
|
+
export interface ListPromptsResult {
|
|
88
|
+
prompts: McpPrompt[];
|
|
89
|
+
}
|
|
90
|
+
export interface GetPromptParams {
|
|
91
|
+
name: string;
|
|
92
|
+
arguments?: Record<string, any>;
|
|
93
|
+
}
|
|
94
|
+
export interface GetPromptResult {
|
|
95
|
+
messages: Array<{
|
|
96
|
+
role: "user" | "assistant";
|
|
97
|
+
content: Array<{
|
|
98
|
+
type: "text" | "image" | "resource";
|
|
99
|
+
text?: string;
|
|
100
|
+
data?: string;
|
|
101
|
+
mimeType?: string;
|
|
102
|
+
uri?: string;
|
|
103
|
+
}>;
|
|
104
|
+
}>;
|
|
105
|
+
}
|
|
106
|
+
export interface SamplingRequestParams {
|
|
107
|
+
messages: Array<{
|
|
108
|
+
role: "user" | "assistant";
|
|
109
|
+
content: Array<{
|
|
110
|
+
type: "text" | "image" | "resource";
|
|
111
|
+
text?: string;
|
|
112
|
+
data?: string;
|
|
113
|
+
mimeType?: string;
|
|
114
|
+
uri?: string;
|
|
115
|
+
}>;
|
|
116
|
+
}>;
|
|
117
|
+
model?: string;
|
|
118
|
+
temperature?: number;
|
|
119
|
+
maxTokens?: number;
|
|
120
|
+
stopSequences?: string[];
|
|
121
|
+
}
|
|
122
|
+
export interface SamplingResult {
|
|
123
|
+
content: Array<{
|
|
124
|
+
type: "text";
|
|
125
|
+
text: string;
|
|
126
|
+
}>;
|
|
127
|
+
model: string;
|
|
128
|
+
stopReason: "end_turn" | "stop_sequence" | "max_tokens" | "cancelled" | "error";
|
|
129
|
+
}
|
|
130
|
+
export interface ListRootsResult {
|
|
131
|
+
roots: Array<{
|
|
132
|
+
uri: string;
|
|
133
|
+
name?: string;
|
|
134
|
+
}>;
|
|
135
|
+
}
|
|
136
|
+
export interface ReadRootParams {
|
|
137
|
+
uri: string;
|
|
138
|
+
}
|
|
139
|
+
export interface ReadRootResult {
|
|
140
|
+
contents: Array<{
|
|
141
|
+
uri: string;
|
|
142
|
+
mimeType?: string;
|
|
143
|
+
text?: string;
|
|
144
|
+
blob?: string;
|
|
145
|
+
}>;
|
|
146
|
+
}
|
|
147
|
+
export interface ElicitParams {
|
|
148
|
+
message?: string;
|
|
149
|
+
schema: {
|
|
150
|
+
type: "string" | "number" | "boolean" | "enum";
|
|
151
|
+
description?: string;
|
|
152
|
+
enum?: Array<{
|
|
153
|
+
value: string | number | boolean;
|
|
154
|
+
title?: string;
|
|
155
|
+
}>;
|
|
156
|
+
default?: string | number | boolean;
|
|
157
|
+
mode?: "single" | "multiple";
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
export interface ElicitResult {
|
|
161
|
+
value: string | number | boolean | (string | number | boolean)[];
|
|
162
|
+
}
|
|
163
|
+
export interface ProgressNotification {
|
|
164
|
+
jsonrpc: "2.0";
|
|
165
|
+
method: "notifications/progress";
|
|
166
|
+
params: {
|
|
167
|
+
progressToken: string;
|
|
168
|
+
progress: number;
|
|
169
|
+
total?: number;
|
|
170
|
+
message?: string;
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
export interface CancelRequestParams {
|
|
174
|
+
requestId: string | number;
|
|
175
|
+
}
|
|
176
|
+
export interface CancelResult {
|
|
177
|
+
cancelled: boolean;
|
|
178
|
+
}
|
|
51
179
|
export declare enum McpErrorCode {
|
|
52
180
|
InvalidRequest = -32600,
|
|
53
181
|
MethodNotFound = -32601,
|
|
54
182
|
InvalidParams = -32602,
|
|
55
183
|
InternalError = -32603,
|
|
56
184
|
ToolNotFound = -32001,
|
|
57
|
-
ToolExecutionError = -32002
|
|
185
|
+
ToolExecutionError = -32002,
|
|
186
|
+
ResourceNotFound = -32003,
|
|
187
|
+
PromptNotFound = -32004,
|
|
188
|
+
SamplingNotSupported = -32005,
|
|
189
|
+
RootsNotSupported = -32006,
|
|
190
|
+
ElicitationNotSupported = -32007,
|
|
191
|
+
RequestCancelled = -32008
|
|
58
192
|
}
|
|
@@ -9,5 +9,11 @@ var McpErrorCode;
|
|
|
9
9
|
McpErrorCode[McpErrorCode["InternalError"] = -32603] = "InternalError";
|
|
10
10
|
McpErrorCode[McpErrorCode["ToolNotFound"] = -32001] = "ToolNotFound";
|
|
11
11
|
McpErrorCode[McpErrorCode["ToolExecutionError"] = -32002] = "ToolExecutionError";
|
|
12
|
+
McpErrorCode[McpErrorCode["ResourceNotFound"] = -32003] = "ResourceNotFound";
|
|
13
|
+
McpErrorCode[McpErrorCode["PromptNotFound"] = -32004] = "PromptNotFound";
|
|
14
|
+
McpErrorCode[McpErrorCode["SamplingNotSupported"] = -32005] = "SamplingNotSupported";
|
|
15
|
+
McpErrorCode[McpErrorCode["RootsNotSupported"] = -32006] = "RootsNotSupported";
|
|
16
|
+
McpErrorCode[McpErrorCode["ElicitationNotSupported"] = -32007] = "ElicitationNotSupported";
|
|
17
|
+
McpErrorCode[McpErrorCode["RequestCancelled"] = -32008] = "RequestCancelled";
|
|
12
18
|
})(McpErrorCode || (exports.McpErrorCode = McpErrorCode = {}));
|
|
13
19
|
//# sourceMappingURL=mcp-protocol.interface.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-protocol.interface.js","sourceRoot":"","sources":["../../src/interface/mcp-protocol.interface.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"mcp-protocol.interface.js","sourceRoot":"","sources":["../../src/interface/mcp-protocol.interface.ts"],"names":[],"mappings":";;;AA0RA,IAAY,YAaX;AAbD,WAAY,YAAY;IACtB,wEAAuB,CAAA;IACvB,wEAAuB,CAAA;IACvB,sEAAsB,CAAA;IACtB,sEAAsB,CAAA;IACtB,oEAAqB,CAAA;IACrB,gFAA2B,CAAA;IAC3B,4EAAyB,CAAA;IACzB,wEAAuB,CAAA;IACvB,oFAA6B,CAAA;IAC7B,8EAA0B,CAAA;IAC1B,0FAAgC,CAAA;IAChC,4EAAyB,CAAA;AAC3B,CAAC,EAbW,YAAY,4BAAZ,YAAY,QAavB"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { PromptDefinition, PromptRegistrationInput } from "./prompt.interface";
|
|
2
|
+
export declare class PromptRegistryService {
|
|
3
|
+
private readonly registry;
|
|
4
|
+
private readonly promptProviders;
|
|
5
|
+
registerPrompt(definition: PromptDefinition, getPrompt: (args: Record<string, any>) => Promise<Array<{
|
|
6
|
+
role: "user" | "assistant";
|
|
7
|
+
content: Array<{
|
|
8
|
+
type: "text" | "image" | "resource";
|
|
9
|
+
text?: string;
|
|
10
|
+
data?: string;
|
|
11
|
+
mimeType?: string;
|
|
12
|
+
uri?: string;
|
|
13
|
+
}>;
|
|
14
|
+
}>>): void;
|
|
15
|
+
registerPromptFromConfig(promptInput: PromptRegistrationInput): void;
|
|
16
|
+
getAllPrompts(): PromptDefinition[];
|
|
17
|
+
getPrompt(name: string): PromptDefinition | undefined;
|
|
18
|
+
getPromptContent(name: string, args: Record<string, any>): Promise<Array<{
|
|
19
|
+
role: "user" | "assistant";
|
|
20
|
+
content: Array<{
|
|
21
|
+
type: "text" | "image" | "resource";
|
|
22
|
+
text?: string;
|
|
23
|
+
data?: string;
|
|
24
|
+
mimeType?: string;
|
|
25
|
+
uri?: string;
|
|
26
|
+
}>;
|
|
27
|
+
}>>;
|
|
28
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.PromptRegistryService = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
const logger_util_1 = require("../core/utils/logger.util");
|
|
12
|
+
const sanitize_util_1 = require("../core/utils/sanitize.util");
|
|
13
|
+
let PromptRegistryService = class PromptRegistryService {
|
|
14
|
+
registry = new Map();
|
|
15
|
+
promptProviders = new Map();
|
|
16
|
+
registerPrompt(definition, getPrompt) {
|
|
17
|
+
if (this.registry.has(definition.name)) {
|
|
18
|
+
throw new Error(`Prompt with name '${definition.name}' already registered.`);
|
|
19
|
+
}
|
|
20
|
+
this.registry.set(definition.name, definition);
|
|
21
|
+
this.promptProviders.set(definition.name, getPrompt);
|
|
22
|
+
const sanitizedPromptName = (0, sanitize_util_1.sanitizeName)(definition.name);
|
|
23
|
+
logger_util_1.logger.info("PromptRegistryService", `Prompt registered: ${sanitizedPromptName}`, {
|
|
24
|
+
component: "PromptRegistry",
|
|
25
|
+
promptName: sanitizedPromptName,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
registerPromptFromConfig(promptInput) {
|
|
29
|
+
const definition = {
|
|
30
|
+
name: promptInput.name,
|
|
31
|
+
description: promptInput.description,
|
|
32
|
+
arguments: promptInput.arguments,
|
|
33
|
+
icon: promptInput.icon,
|
|
34
|
+
};
|
|
35
|
+
this.registerPrompt(definition, promptInput.getPrompt);
|
|
36
|
+
}
|
|
37
|
+
getAllPrompts() {
|
|
38
|
+
return Array.from(this.registry.values());
|
|
39
|
+
}
|
|
40
|
+
getPrompt(name) {
|
|
41
|
+
return this.registry.get(name);
|
|
42
|
+
}
|
|
43
|
+
async getPromptContent(name, args) {
|
|
44
|
+
const getPrompt = this.promptProviders.get(name);
|
|
45
|
+
if (!getPrompt) {
|
|
46
|
+
throw new Error(`Prompt not found: ${name}`);
|
|
47
|
+
}
|
|
48
|
+
return await getPrompt(args);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
exports.PromptRegistryService = PromptRegistryService;
|
|
52
|
+
exports.PromptRegistryService = PromptRegistryService = __decorate([
|
|
53
|
+
(0, common_1.Injectable)()
|
|
54
|
+
], PromptRegistryService);
|
|
55
|
+
//# sourceMappingURL=prompt-registry.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt-registry.service.js","sourceRoot":"","sources":["../../src/prompts/prompt-registry.service.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA4C;AAE5C,2DAAmD;AACnD,+DAA2D;AAGpD,IAAM,qBAAqB,GAA3B,MAAM,qBAAqB;IACf,QAAQ,GAAG,IAAI,GAAG,EAA4B,CAAC;IAC/C,eAAe,GAAG,IAAI,GAAG,EASpC,CAAC;IAOA,cAAc,CACnB,UAA4B,EAC5B,SASG;QAEH,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,EA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AC,CAAC;QAC/C,CAAC;QACD,OAAO,MAAM,SAAS,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC;CACF,CAAA;AAnGY,sDAAqB;gCAArB,qBAAqB;IADjC,IAAA,mBAAU,GAAE;GACA,qBAAqB,CAmGjC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export interface PromptDefinition {
|
|
2
|
+
name: string;
|
|
3
|
+
description?: string;
|
|
4
|
+
arguments?: Array<{
|
|
5
|
+
name: string;
|
|
6
|
+
description?: string;
|
|
7
|
+
required?: boolean;
|
|
8
|
+
}>;
|
|
9
|
+
icon?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface PromptRegistrationInput {
|
|
12
|
+
name: string;
|
|
13
|
+
description?: string;
|
|
14
|
+
arguments?: Array<{
|
|
15
|
+
name: string;
|
|
16
|
+
description?: string;
|
|
17
|
+
required?: boolean;
|
|
18
|
+
}>;
|
|
19
|
+
icon?: string;
|
|
20
|
+
getPrompt: (args: Record<string, any>) => Promise<Array<{
|
|
21
|
+
role: "user" | "assistant";
|
|
22
|
+
content: Array<{
|
|
23
|
+
type: "text" | "image" | "resource";
|
|
24
|
+
text?: string;
|
|
25
|
+
data?: string;
|
|
26
|
+
mimeType?: string;
|
|
27
|
+
uri?: string;
|
|
28
|
+
}>;
|
|
29
|
+
}>>;
|
|
30
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt.interface.js","sourceRoot":"","sources":["../../src/prompts/prompt.interface.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.PromptModule = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
const prompt_registry_service_1 = require("./prompt-registry.service");
|
|
12
|
+
let PromptModule = class PromptModule {
|
|
13
|
+
};
|
|
14
|
+
exports.PromptModule = PromptModule;
|
|
15
|
+
exports.PromptModule = PromptModule = __decorate([
|
|
16
|
+
(0, common_1.Module)({
|
|
17
|
+
providers: [prompt_registry_service_1.PromptRegistryService],
|
|
18
|
+
exports: [prompt_registry_service_1.PromptRegistryService],
|
|
19
|
+
})
|
|
20
|
+
], PromptModule);
|
|
21
|
+
//# sourceMappingURL=prompt.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt.module.js","sourceRoot":"","sources":["../../src/prompts/prompt.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,uEAAkE;AAM3D,IAAM,YAAY,GAAlB,MAAM,YAAY;CAAG,CAAA;AAAf,oCAAY;uBAAZ,YAAY;IAJxB,IAAA,eAAM,EAAC;QACN,SAAS,EAAE,CAAC,+CAAqB,CAAC;QAClC,OAAO,EAAE,CAAC,+CAAqB,CAAC;KACjC,CAAC;GACW,YAAY,CAAG"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ResourceDefinition, ResourceRegistrationInput } from "./resource.interface";
|
|
2
|
+
export declare class ResourceRegistryService {
|
|
3
|
+
private readonly registry;
|
|
4
|
+
private readonly contentProviders;
|
|
5
|
+
registerResource(definition: ResourceDefinition, getContent: () => Promise<string | {
|
|
6
|
+
type: string;
|
|
7
|
+
data: string;
|
|
8
|
+
mimeType?: string;
|
|
9
|
+
}>): void;
|
|
10
|
+
registerResourceFromConfig(resourceInput: ResourceRegistrationInput): void;
|
|
11
|
+
getAllResources(): ResourceDefinition[];
|
|
12
|
+
getResource(uri: string): ResourceDefinition | undefined;
|
|
13
|
+
getResourceContent(uri: string): Promise<string | {
|
|
14
|
+
type: string;
|
|
15
|
+
data: string;
|
|
16
|
+
mimeType?: string;
|
|
17
|
+
}>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.ResourceRegistryService = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
const logger_util_1 = require("../core/utils/logger.util");
|
|
12
|
+
const sanitize_util_1 = require("../core/utils/sanitize.util");
|
|
13
|
+
let ResourceRegistryService = class ResourceRegistryService {
|
|
14
|
+
registry = new Map();
|
|
15
|
+
contentProviders = new Map();
|
|
16
|
+
registerResource(definition, getContent) {
|
|
17
|
+
if (this.registry.has(definition.uri)) {
|
|
18
|
+
throw new Error(`Resource with URI '${definition.uri}' already registered.`);
|
|
19
|
+
}
|
|
20
|
+
this.registry.set(definition.uri, definition);
|
|
21
|
+
this.contentProviders.set(definition.uri, getContent);
|
|
22
|
+
const sanitizedUri = (0, sanitize_util_1.sanitizeUri)(definition.uri);
|
|
23
|
+
logger_util_1.logger.info("ResourceRegistryService", `Resource registered: ${sanitizedUri}`, {
|
|
24
|
+
component: "ResourceRegistry",
|
|
25
|
+
resourceUri: sanitizedUri,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
registerResourceFromConfig(resourceInput) {
|
|
29
|
+
const definition = {
|
|
30
|
+
uri: resourceInput.uri,
|
|
31
|
+
name: resourceInput.name,
|
|
32
|
+
description: resourceInput.description,
|
|
33
|
+
mimeType: resourceInput.mimeType,
|
|
34
|
+
icon: resourceInput.icon,
|
|
35
|
+
};
|
|
36
|
+
this.registerResource(definition, resourceInput.getContent);
|
|
37
|
+
}
|
|
38
|
+
getAllResources() {
|
|
39
|
+
return Array.from(this.registry.values());
|
|
40
|
+
}
|
|
41
|
+
getResource(uri) {
|
|
42
|
+
return this.registry.get(uri);
|
|
43
|
+
}
|
|
44
|
+
async getResourceContent(uri) {
|
|
45
|
+
const getContent = this.contentProviders.get(uri);
|
|
46
|
+
if (!getContent) {
|
|
47
|
+
throw new Error(`Resource not found: ${uri}`);
|
|
48
|
+
}
|
|
49
|
+
return await getContent();
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
exports.ResourceRegistryService = ResourceRegistryService;
|
|
53
|
+
exports.ResourceRegistryService = ResourceRegistryService = __decorate([
|
|
54
|
+
(0, common_1.Injectable)()
|
|
55
|
+
], ResourceRegistryService);
|
|
56
|
+
//# sourceMappingURL=resource-registry.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resource-registry.service.js","sourceRoot":"","sources":["../../src/resources/resource-registry.service.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA4C;AAE5C,2DAAmD;AACnD,+DAA0D;AAGnD,IAAM,uBAAuB,GAA7B,MAAM,uBAAuB;IACjB,QAAQ,GAAG,IAAI,GAAG,EAA8B,CAAC;IACjD,gBAAgB,GAAG,IAAI,GAAG,EAAqF,CAAC;IAO1H,gBAAgB,CACrB,UAA8B,EAC9B,UAAqF;QAErF,IAAI,IAAI,CAAC,QAAQ,CA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AU,EAAE,CAAC;YAChB,MAAM,IAAI,KAAK,CAAC,uBAAuB,GAAG,EAAE,CAAC,CAAC;QAChD,CAAC;QACD,OAAO,MAAM,UAAU,EAAE,CAAC;IAC5B,CAAC;CACF,CAAA;AArEY,0DAAuB;kCAAvB,uBAAuB;IADnC,IAAA,mBAAU,GAAE;GACA,uBAAuB,CAqEnC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export interface ResourceDefinition {
|
|
2
|
+
uri: string;
|
|
3
|
+
name: string;
|
|
4
|
+
description?: string;
|
|
5
|
+
mimeType?: string;
|
|
6
|
+
icon?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface ResourceRegistrationInput {
|
|
9
|
+
uri: string;
|
|
10
|
+
name: string;
|
|
11
|
+
description?: string;
|
|
12
|
+
mimeType?: string;
|
|
13
|
+
icon?: string;
|
|
14
|
+
getContent: () => Promise<string | {
|
|
15
|
+
type: string;
|
|
16
|
+
data: string;
|
|
17
|
+
mimeType?: string;
|
|
18
|
+
}>;
|
|
19
|
+
}
|