@leanmcp/cli 0.2.0 → 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/dist/index.js +21 -7
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -143,27 +143,38 @@ class CalculateInput {
|
|
|
143
143
|
operation?: string;
|
|
144
144
|
}
|
|
145
145
|
|
|
146
|
+
class EchoInput {
|
|
147
|
+
@SchemaConstraint({
|
|
148
|
+
description: "Message to echo back",
|
|
149
|
+
minLength: 1
|
|
150
|
+
})
|
|
151
|
+
message!: string;
|
|
152
|
+
}
|
|
153
|
+
|
|
146
154
|
export class ExampleService {
|
|
147
155
|
@Tool({
|
|
148
156
|
description: "Perform arithmetic operations with automatic schema validation",
|
|
149
157
|
inputClass: CalculateInput
|
|
150
158
|
})
|
|
151
159
|
async calculate(input: CalculateInput) {
|
|
160
|
+
// Ensure numerical operations by explicitly converting to numbers
|
|
161
|
+
const a = Number(input.a);
|
|
162
|
+
const b = Number(input.b);
|
|
152
163
|
let result: number;
|
|
153
164
|
|
|
154
165
|
switch (input.operation || "add") {
|
|
155
166
|
case "add":
|
|
156
|
-
result =
|
|
167
|
+
result = a + b;
|
|
157
168
|
break;
|
|
158
169
|
case "subtract":
|
|
159
|
-
result =
|
|
170
|
+
result = a - b;
|
|
160
171
|
break;
|
|
161
172
|
case "multiply":
|
|
162
|
-
result =
|
|
173
|
+
result = a * b;
|
|
163
174
|
break;
|
|
164
175
|
case "divide":
|
|
165
|
-
if (
|
|
166
|
-
result =
|
|
176
|
+
if (b === 0) throw new Error("Cannot divide by zero");
|
|
177
|
+
result = a / b;
|
|
167
178
|
break;
|
|
168
179
|
default:
|
|
169
180
|
throw new Error("Invalid operation");
|
|
@@ -181,8 +192,11 @@ export class ExampleService {
|
|
|
181
192
|
};
|
|
182
193
|
}
|
|
183
194
|
|
|
184
|
-
@Tool({
|
|
185
|
-
|
|
195
|
+
@Tool({
|
|
196
|
+
description: "Echo a message back",
|
|
197
|
+
inputClass: EchoInput
|
|
198
|
+
})
|
|
199
|
+
async echo(input: EchoInput) {
|
|
186
200
|
return {
|
|
187
201
|
content: [{
|
|
188
202
|
type: "text" as const,
|