@decaf-ts/decorator-validation 1.10.3 → 1.10.4

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 (35) hide show
  1. package/lib/esm/index.d.ts +1 -1
  2. package/lib/esm/index.js +1 -1
  3. package/lib/index.cjs +1 -1
  4. package/lib/index.d.ts +1 -1
  5. package/package.json +4 -11
  6. package/lib/esm/mcp/ModelContextProtocol.d.ts +0 -123
  7. package/lib/esm/mcp/ModelContextProtocol.js +0 -179
  8. package/lib/esm/mcp/ModelContextProtocol.js.map +0 -1
  9. package/lib/esm/mcp/mcp1.d.ts +0 -0
  10. package/lib/esm/mcp/mcp1.js +0 -405
  11. package/lib/esm/mcp/mcp1.js.map +0 -1
  12. package/lib/esm/mcp/tools/createModel.tool.d.ts +0 -0
  13. package/lib/esm/mcp/tools/createModel.tool.js +0 -67
  14. package/lib/esm/mcp/tools/createModel.tool.js.map +0 -1
  15. package/lib/esm/mcp/tools/validateModel.tool.d.ts +0 -0
  16. package/lib/esm/mcp/tools/validateModel.tool.js +0 -2
  17. package/lib/esm/mcp/tools/validateModel.tool.js.map +0 -1
  18. package/lib/esm/mcp/types.d.ts +0 -3
  19. package/lib/esm/mcp/types.js +0 -2
  20. package/lib/esm/mcp/types.js.map +0 -1
  21. package/lib/mcp/ModelContextProtocol.cjs +0 -183
  22. package/lib/mcp/ModelContextProtocol.d.ts +0 -123
  23. package/lib/mcp/ModelContextProtocol.js.map +0 -1
  24. package/lib/mcp/mcp1.cjs +0 -405
  25. package/lib/mcp/mcp1.d.ts +0 -0
  26. package/lib/mcp/mcp1.js.map +0 -1
  27. package/lib/mcp/tools/createModel.tool.cjs +0 -67
  28. package/lib/mcp/tools/createModel.tool.d.ts +0 -0
  29. package/lib/mcp/tools/createModel.tool.js.map +0 -1
  30. package/lib/mcp/tools/validateModel.tool.cjs +0 -2
  31. package/lib/mcp/tools/validateModel.tool.d.ts +0 -0
  32. package/lib/mcp/tools/validateModel.tool.js.map +0 -1
  33. package/lib/mcp/types.cjs +0 -3
  34. package/lib/mcp/types.d.ts +0 -3
  35. package/lib/mcp/types.js.map +0 -1
@@ -1,183 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ModelContextProtocol = void 0;
4
- const fastmcp_1 = require("fastmcp");
5
- const logging_1 = require("@decaf-ts/logging");
6
- /**
7
- * @description Validates and normalizes a semantic version string.
8
- * @summary Ensures the provided version follows semantic versioning (major.minor.patch) and returns a tuple-like template string typed as `${number}.${number}.${number}`.
9
- * @template
10
- * @param {string} version The version string to validate, expected in the form MAJOR.MINOR.PATCH.
11
- * @return {string} The normalized version string if valid.
12
- * @function validateVersion
13
- * @memberOf module:decorator-validation
14
- */
15
- function validateVersion(version) {
16
- const regexp = /(\d+)\.(\d+)\.(\d+)/g;
17
- const match = regexp.exec(version);
18
- if (!match)
19
- throw new Error(`Invalid version string. should obey semantic versioning: ${version}`);
20
- return `${match[1]}.${match[2]}.${match[3]}`;
21
- }
22
- /**
23
- * @description Fluent builder for creating a configured ModelContextProtocol instance.
24
- * @summary Collects MCP configuration including a semantic version, a name, and a registry of tools, offering chainable methods and a final build step to produce a ready-to-use ModelContextProtocol.
25
- * @param {string} [name] The name of the MCP instance to build.
26
- * @param {string} [version] The semantic version of the MCP instance.
27
- * @param {Record<string, Tool<any, any>>} [tools] A map of tool configurations indexed by tool name.
28
- * @class
29
- * @example
30
- * // Build a new MCP with a single tool
31
- * const mcp = ModelContextProtocol.builder
32
- * .setName("Example")
33
- * .setVersion("1.0.0")
34
- * .addTool({ name: "do", description: "", parameters: z.any(), execute: async () => "ok" })
35
- * .build();
36
- * @mermaid
37
- * sequenceDiagram
38
- * participant Dev as Developer
39
- * participant B as Builder
40
- * participant MCP as ModelContextProtocol
41
- * Dev->>B: setName("Example")
42
- * B-->>Dev: Builder
43
- * Dev->>B: setVersion("1.0.0")
44
- * B-->>Dev: Builder
45
- * Dev->>B: addTool(tool)
46
- * B-->>Dev: Builder
47
- * Dev->>B: build()
48
- * B->>MCP: new ModelContextProtocol(FastMCP)
49
- * B-->>Dev: ModelContextProtocol
50
- */
51
- class Builder {
52
- constructor() {
53
- this.tools = {};
54
- this.log = logging_1.Logging.for("MCP Builder");
55
- }
56
- /**
57
- * @description Sets the MCP instance name.
58
- * @summary Assigns a human-readable identifier to the builder configuration and enables method chaining.
59
- * @param {string} value The name to assign to the MCP instance.
60
- * @return {this} The current builder instance for chaining.
61
- */
62
- setName(value) {
63
- this.name = value;
64
- this.log.debug(`name set to ${value}`);
65
- return this;
66
- }
67
- /**
68
- * @description Sets and validates the semantic version for the MCP instance.
69
- * @summary Parses the provided value against semantic versioning and stores the normalized version; enables method chaining.
70
- * @param {string} value The semantic version string (e.g., "1.2.3").
71
- * @return {this} The current builder instance for chaining.
72
- */
73
- setVersion(value) {
74
- this.version = validateVersion(value);
75
- this.log.debug(`version set to ${value}`);
76
- return this;
77
- }
78
- /**
79
- * @description Registers a new tool in the builder.
80
- * @summary Adds a tool configuration by its unique name to the internal registry, throwing if a tool with the same name already exists.
81
- * @template Auth extends FastMCPSessionAuth
82
- * @param {Tool<Auth, any>} config The tool configuration object, including a unique name and an execute handler.
83
- * @return {this} The current builder instance for chaining.
84
- */
85
- addTool(config) {
86
- const { name } = config;
87
- if (name in this.tools)
88
- throw new Error(`tool ${name} already registered`);
89
- this.tools[name] = config;
90
- this.log.debug(`tool ${name} added`);
91
- return this;
92
- }
93
- /**
94
- * @description Finalizes the configuration and produces a ModelContextProtocol instance.
95
- * @summary Validates required fields (name and version), constructs a FastMCP instance, registers all configured tools, and returns a ModelContextProtocol wrapping the MCP.
96
- * @template Auth extends FastMCPSessionAuth
97
- * @return {ModelContextProtocol<Auth>} A fully initialized ModelContextProtocol instance.
98
- */
99
- build() {
100
- if (!this.name)
101
- throw new Error("name is required");
102
- if (!this.version)
103
- throw new Error("version is required");
104
- const mcp = new fastmcp_1.FastMCP({
105
- name: this.name,
106
- version: this.version,
107
- });
108
- Object.values(this.tools).forEach((tool) => {
109
- try {
110
- mcp.addTool(tool);
111
- }
112
- catch (e) {
113
- throw new Error(`Failed to add tool ${tool.name}: ${e}`);
114
- }
115
- });
116
- this.log.info(`${this.name} MCP built`);
117
- this.log.debug(`${this.name} MCP - available tools: ${Object.keys(this.tools).join(", ")}`);
118
- return new ModelContextProtocol(mcp);
119
- }
120
- }
121
- /**
122
- * @description A thin wrapper around FastMCP providing a typed interface for model-centric protocols.
123
- * @summary Encapsulates a configured FastMCP instance and exposes factory utilities via a static Builder for constructing MCPs with tools, versioning, and naming semantics.
124
- * @template Auth extends FastMCPSessionAuth Authentication payload type stored in the MCP session, or undefined for no auth.
125
- * @param {FastMCP<Auth>} mcp The underlying FastMCP instance used to register and run tools.
126
- * @class
127
- * @example
128
- * // Using the builder
129
- * const protocol = ModelContextProtocol.builder
130
- * .setName("Validator")
131
- * .setVersion("1.2.3")
132
- * .addTool({ name: "ping", description: "", parameters: z.any(), execute: async () => "pong" })
133
- * .build();
134
- * @mermaid
135
- * sequenceDiagram
136
- * participant Dev as Developer
137
- * participant B as ModelContextProtocol.Builder
138
- * participant MCP as FastMCP
139
- * participant Proto as ModelContextProtocol
140
- * Dev->>B: setName()/setVersion()/addTool()
141
- * Dev->>B: build()
142
- * B->>MCP: new FastMCP({ name, version })
143
- * B->>MCP: addTool(tool...)
144
- * B->>Proto: new ModelContextProtocol(MCP)
145
- * B-->>Dev: ModelContextProtocol
146
- */
147
- class ModelContextProtocol {
148
- /**
149
- * @description Lazily obtains a logger instance for this protocol wrapper.
150
- * @summary Uses the Logging facility to create a context-aware Logger bound to this instance.
151
- * @return {Logger} A logger instance for this class.
152
- */
153
- get log() {
154
- return logging_1.Logging.for(this);
155
- }
156
- constructor(mcp) {
157
- this.mcp = mcp;
158
- }
159
- /**
160
- * @description Alias to the inner Builder class for external access.
161
- * @summary Exposes the builder type to consumers to enable typed construction of ModelContextProtocol instances.
162
- */
163
- static { this.Builder = Builder; }
164
- /**
165
- * @description Factory accessor for a new Builder instance.
166
- * @summary Creates a new builder to fluently configure and construct a ModelContextProtocol.
167
- * @return {Builder} A new builder instance.
168
- */
169
- static get builder() {
170
- return new ModelContextProtocol.Builder();
171
- }
172
- /**
173
- * @description Validates a semantic version string.
174
- * @summary Utility wrapper around the module-level validateVersion to keep a typed validator close to the class API.
175
- * @param {string} version The version string to validate.
176
- * @return {string} The normalized semantic version string.
177
- */
178
- static validateVersion(version) {
179
- return validateVersion(version);
180
- }
181
- }
182
- exports.ModelContextProtocol = ModelContextProtocol;
183
- //# sourceMappingURL=ModelContextProtocol.js.map
@@ -1,123 +0,0 @@
1
- import { FastMCP, Tool } from "fastmcp";
2
- import { Logger } from "@decaf-ts/logging";
3
- import { FastMCPSessionAuth } from "./types";
4
- /**
5
- * @description Fluent builder for creating a configured ModelContextProtocol instance.
6
- * @summary Collects MCP configuration including a semantic version, a name, and a registry of tools, offering chainable methods and a final build step to produce a ready-to-use ModelContextProtocol.
7
- * @param {string} [name] The name of the MCP instance to build.
8
- * @param {string} [version] The semantic version of the MCP instance.
9
- * @param {Record<string, Tool<any, any>>} [tools] A map of tool configurations indexed by tool name.
10
- * @class
11
- * @example
12
- * // Build a new MCP with a single tool
13
- * const mcp = ModelContextProtocol.builder
14
- * .setName("Example")
15
- * .setVersion("1.0.0")
16
- * .addTool({ name: "do", description: "", parameters: z.any(), execute: async () => "ok" })
17
- * .build();
18
- * @mermaid
19
- * sequenceDiagram
20
- * participant Dev as Developer
21
- * participant B as Builder
22
- * participant MCP as ModelContextProtocol
23
- * Dev->>B: setName("Example")
24
- * B-->>Dev: Builder
25
- * Dev->>B: setVersion("1.0.0")
26
- * B-->>Dev: Builder
27
- * Dev->>B: addTool(tool)
28
- * B-->>Dev: Builder
29
- * Dev->>B: build()
30
- * B->>MCP: new ModelContextProtocol(FastMCP)
31
- * B-->>Dev: ModelContextProtocol
32
- */
33
- declare class Builder {
34
- name: string;
35
- version: `${number}.${number}.${number}`;
36
- tools: Record<string, Tool<any, any>>;
37
- log: Logger;
38
- constructor();
39
- /**
40
- * @description Sets the MCP instance name.
41
- * @summary Assigns a human-readable identifier to the builder configuration and enables method chaining.
42
- * @param {string} value The name to assign to the MCP instance.
43
- * @return {this} The current builder instance for chaining.
44
- */
45
- setName(value: string): this;
46
- /**
47
- * @description Sets and validates the semantic version for the MCP instance.
48
- * @summary Parses the provided value against semantic versioning and stores the normalized version; enables method chaining.
49
- * @param {string} value The semantic version string (e.g., "1.2.3").
50
- * @return {this} The current builder instance for chaining.
51
- */
52
- setVersion(value: string): this;
53
- /**
54
- * @description Registers a new tool in the builder.
55
- * @summary Adds a tool configuration by its unique name to the internal registry, throwing if a tool with the same name already exists.
56
- * @template Auth extends FastMCPSessionAuth
57
- * @param {Tool<Auth, any>} config The tool configuration object, including a unique name and an execute handler.
58
- * @return {this} The current builder instance for chaining.
59
- */
60
- addTool<Auth extends FastMCPSessionAuth = undefined>(config: Tool<Auth, any>): this;
61
- /**
62
- * @description Finalizes the configuration and produces a ModelContextProtocol instance.
63
- * @summary Validates required fields (name and version), constructs a FastMCP instance, registers all configured tools, and returns a ModelContextProtocol wrapping the MCP.
64
- * @template Auth extends FastMCPSessionAuth
65
- * @return {ModelContextProtocol<Auth>} A fully initialized ModelContextProtocol instance.
66
- */
67
- build<Auth extends FastMCPSessionAuth = undefined>(): ModelContextProtocol<Auth>;
68
- }
69
- /**
70
- * @description A thin wrapper around FastMCP providing a typed interface for model-centric protocols.
71
- * @summary Encapsulates a configured FastMCP instance and exposes factory utilities via a static Builder for constructing MCPs with tools, versioning, and naming semantics.
72
- * @template Auth extends FastMCPSessionAuth Authentication payload type stored in the MCP session, or undefined for no auth.
73
- * @param {FastMCP<Auth>} mcp The underlying FastMCP instance used to register and run tools.
74
- * @class
75
- * @example
76
- * // Using the builder
77
- * const protocol = ModelContextProtocol.builder
78
- * .setName("Validator")
79
- * .setVersion("1.2.3")
80
- * .addTool({ name: "ping", description: "", parameters: z.any(), execute: async () => "pong" })
81
- * .build();
82
- * @mermaid
83
- * sequenceDiagram
84
- * participant Dev as Developer
85
- * participant B as ModelContextProtocol.Builder
86
- * participant MCP as FastMCP
87
- * participant Proto as ModelContextProtocol
88
- * Dev->>B: setName()/setVersion()/addTool()
89
- * Dev->>B: build()
90
- * B->>MCP: new FastMCP({ name, version })
91
- * B->>MCP: addTool(tool...)
92
- * B->>Proto: new ModelContextProtocol(MCP)
93
- * B-->>Dev: ModelContextProtocol
94
- */
95
- export declare class ModelContextProtocol<Auth extends FastMCPSessionAuth = undefined> {
96
- protected readonly mcp: FastMCP<Auth>;
97
- /**
98
- * @description Lazily obtains a logger instance for this protocol wrapper.
99
- * @summary Uses the Logging facility to create a context-aware Logger bound to this instance.
100
- * @return {Logger} A logger instance for this class.
101
- */
102
- protected get log(): Logger;
103
- constructor(mcp: FastMCP<Auth>);
104
- /**
105
- * @description Alias to the inner Builder class for external access.
106
- * @summary Exposes the builder type to consumers to enable typed construction of ModelContextProtocol instances.
107
- */
108
- static readonly Builder: typeof Builder;
109
- /**
110
- * @description Factory accessor for a new Builder instance.
111
- * @summary Creates a new builder to fluently configure and construct a ModelContextProtocol.
112
- * @return {Builder} A new builder instance.
113
- */
114
- static get builder(): Builder;
115
- /**
116
- * @description Validates a semantic version string.
117
- * @summary Utility wrapper around the module-level validateVersion to keep a typed validator close to the class API.
118
- * @param {string} version The version string to validate.
119
- * @return {string} The normalized semantic version string.
120
- */
121
- private static validateVersion;
122
- }
123
- export {};
@@ -1 +0,0 @@
1
- {"version":3,"file":"ModelContextProtocol.js","sourceRoot":"","sources":["../../src/mcp/ModelContextProtocol.ts"],"names":[],"mappings":";;;AAAA,qCAAwC;AACxC,+CAAoD;AAGpD;;;;;;;;GAQG;AACH,SAAS,eAAe,CAAC,OAAe;IACtC,MAAM,MAAM,GAAG,sBAAsB,CAAC;IACtC,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACnC,IAAI,CAAC,KAAK;QACR,MAA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