hono-mcp 1.4.1 → 1.4.2
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/commands/math.js +36 -28
- package/dist/tools/decorator-tools.js +5 -8
- package/package.json +1 -1
package/dist/commands/math.js
CHANGED
|
@@ -7,99 +7,107 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
|
-
import { z } from
|
|
11
|
-
import { Command, Param } from
|
|
10
|
+
import { z } from "zod";
|
|
11
|
+
import { Command, Param } from "../decorators/command.js";
|
|
12
12
|
let AddCommand = class AddCommand {
|
|
13
13
|
a;
|
|
14
14
|
b;
|
|
15
|
-
async execute() {
|
|
16
|
-
const result =
|
|
15
|
+
async execute(params) {
|
|
16
|
+
const result = params.a + params.b;
|
|
17
17
|
return {
|
|
18
|
-
content: [
|
|
18
|
+
content: [
|
|
19
|
+
{ type: "text", text: `${params.a} + ${params.b} = ${result}` },
|
|
20
|
+
],
|
|
19
21
|
};
|
|
20
22
|
}
|
|
21
23
|
};
|
|
22
24
|
__decorate([
|
|
23
|
-
Param(z.number().describe(
|
|
25
|
+
Param(z.number().describe("First number")),
|
|
24
26
|
__metadata("design:type", Number)
|
|
25
27
|
], AddCommand.prototype, "a", void 0);
|
|
26
28
|
__decorate([
|
|
27
|
-
Param(z.number().describe(
|
|
29
|
+
Param(z.number().describe("Second number")),
|
|
28
30
|
__metadata("design:type", Number)
|
|
29
31
|
], AddCommand.prototype, "b", void 0);
|
|
30
32
|
AddCommand = __decorate([
|
|
31
|
-
Command(
|
|
33
|
+
Command("math.add", "Add two numbers")
|
|
32
34
|
], AddCommand);
|
|
33
35
|
export { AddCommand };
|
|
34
36
|
let SubtractCommand = class SubtractCommand {
|
|
35
37
|
a;
|
|
36
38
|
b;
|
|
37
|
-
async execute() {
|
|
38
|
-
const result =
|
|
39
|
+
async execute(params) {
|
|
40
|
+
const result = params.a - params.b;
|
|
39
41
|
return {
|
|
40
|
-
content: [
|
|
42
|
+
content: [
|
|
43
|
+
{ type: "text", text: `${params.a} - ${params.b} = ${result}` },
|
|
44
|
+
],
|
|
41
45
|
};
|
|
42
46
|
}
|
|
43
47
|
};
|
|
44
48
|
__decorate([
|
|
45
|
-
Param(z.number().describe(
|
|
49
|
+
Param(z.number().describe("First number")),
|
|
46
50
|
__metadata("design:type", Number)
|
|
47
51
|
], SubtractCommand.prototype, "a", void 0);
|
|
48
52
|
__decorate([
|
|
49
|
-
Param(z.number().describe(
|
|
53
|
+
Param(z.number().describe("Second number")),
|
|
50
54
|
__metadata("design:type", Number)
|
|
51
55
|
], SubtractCommand.prototype, "b", void 0);
|
|
52
56
|
SubtractCommand = __decorate([
|
|
53
|
-
Command(
|
|
57
|
+
Command("math.subtract", "Subtract two numbers")
|
|
54
58
|
], SubtractCommand);
|
|
55
59
|
export { SubtractCommand };
|
|
56
60
|
let MultiplyCommand = class MultiplyCommand {
|
|
57
61
|
a;
|
|
58
62
|
b;
|
|
59
|
-
async execute() {
|
|
60
|
-
const result =
|
|
63
|
+
async execute(params) {
|
|
64
|
+
const result = params.a * params.b;
|
|
61
65
|
return {
|
|
62
|
-
content: [
|
|
66
|
+
content: [
|
|
67
|
+
{ type: "text", text: `${params.a} × ${params.b} = ${result}` },
|
|
68
|
+
],
|
|
63
69
|
};
|
|
64
70
|
}
|
|
65
71
|
};
|
|
66
72
|
__decorate([
|
|
67
|
-
Param(z.number().describe(
|
|
73
|
+
Param(z.number().describe("First number")),
|
|
68
74
|
__metadata("design:type", Number)
|
|
69
75
|
], MultiplyCommand.prototype, "a", void 0);
|
|
70
76
|
__decorate([
|
|
71
|
-
Param(z.number().describe(
|
|
77
|
+
Param(z.number().describe("Second number")),
|
|
72
78
|
__metadata("design:type", Number)
|
|
73
79
|
], MultiplyCommand.prototype, "b", void 0);
|
|
74
80
|
MultiplyCommand = __decorate([
|
|
75
|
-
Command(
|
|
81
|
+
Command("math.multiply", "Multiply two numbers")
|
|
76
82
|
], MultiplyCommand);
|
|
77
83
|
export { MultiplyCommand };
|
|
78
84
|
let DivideCommand = class DivideCommand {
|
|
79
85
|
a;
|
|
80
86
|
b;
|
|
81
|
-
async execute() {
|
|
82
|
-
if (
|
|
87
|
+
async execute(params) {
|
|
88
|
+
if (params.b === 0) {
|
|
83
89
|
return {
|
|
84
|
-
content: [{ type:
|
|
90
|
+
content: [{ type: "text", text: "Error: Division by zero" }],
|
|
85
91
|
isError: true,
|
|
86
92
|
};
|
|
87
93
|
}
|
|
88
|
-
const result =
|
|
94
|
+
const result = params.a / params.b;
|
|
89
95
|
return {
|
|
90
|
-
content: [
|
|
96
|
+
content: [
|
|
97
|
+
{ type: "text", text: `${params.a} ÷ ${params.b} = ${result}` },
|
|
98
|
+
],
|
|
91
99
|
};
|
|
92
100
|
}
|
|
93
101
|
};
|
|
94
102
|
__decorate([
|
|
95
|
-
Param(z.number().describe(
|
|
103
|
+
Param(z.number().describe("First number")),
|
|
96
104
|
__metadata("design:type", Number)
|
|
97
105
|
], DivideCommand.prototype, "a", void 0);
|
|
98
106
|
__decorate([
|
|
99
|
-
Param(z.number().describe(
|
|
107
|
+
Param(z.number().describe("Second number")),
|
|
100
108
|
__metadata("design:type", Number)
|
|
101
109
|
], DivideCommand.prototype, "b", void 0);
|
|
102
110
|
DivideCommand = __decorate([
|
|
103
|
-
Command(
|
|
111
|
+
Command("math.divide", "Divide two numbers")
|
|
104
112
|
], DivideCommand);
|
|
105
113
|
export { DivideCommand };
|
|
@@ -2,15 +2,12 @@ import { z } from "zod";
|
|
|
2
2
|
import { getCommandRegistry } from "../decorators/command.js";
|
|
3
3
|
export const executeCommandTool = (server) => {
|
|
4
4
|
server.tool("executeCommand", "Execute any command by specifying its type and parameters", {
|
|
5
|
-
type:
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
params: {
|
|
10
|
-
type: "object",
|
|
11
|
-
description: "Command parameters",
|
|
12
|
-
},
|
|
5
|
+
type: z
|
|
6
|
+
.string()
|
|
7
|
+
.describe("Command type (e.g., math.add, math.subtract, math.multiply, math.divide)"),
|
|
8
|
+
params: z.record(z.any()).describe("Command parameters"),
|
|
13
9
|
}, async ({ type, params }) => {
|
|
10
|
+
console.log("executeCommand called with:", { type, params });
|
|
14
11
|
const command = getCommandRegistry().get(type);
|
|
15
12
|
if (!command) {
|
|
16
13
|
return {
|