hono-mcp 1.3.0 → 1.4.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hono-mcp",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
4
4
  "description": "MCP server built with Hono - supports both Vercel deployment and npx CLI usage",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -12,10 +12,14 @@
12
12
  "README.md"
13
13
  ],
14
14
  "scripts": {
15
- "build": "tsc",
15
+ "build": "webpack && node scripts/copy-assets.js",
16
+ "build:clean": "tsc",
16
17
  "start": "node dist/cli.js",
17
18
  "dev": "tsx src/cli.ts",
18
- "dev:vercel": "tsx src/index.ts"
19
+ "dev:vercel": "tsx src/index.ts",
20
+ "build:linux": "bun build src/cli.ts --compile --target=bun-linux-x64 --outfile=dist/hono-mcp-linux",
21
+ "build:windows": "bun build src/cli.ts --compile --target=bun-windows-x64 --outfile=dist/hono-mcp.exe",
22
+ "build:all": "bun run build:linux && bun run build:windows"
19
23
  },
20
24
  "keywords": [
21
25
  "mcp",
@@ -43,7 +47,11 @@
43
47
  },
44
48
  "devDependencies": {
45
49
  "@types/node": "^20.11.17",
50
+ "terser-webpack-plugin": "^5.3.16",
51
+ "ts-loader": "^9.5.4",
46
52
  "tsx": "^4.7.0",
47
- "typescript": "^5.9.3"
53
+ "typescript": "^5.9.3",
54
+ "webpack": "^5.104.1",
55
+ "webpack-cli": "^6.0.1"
48
56
  }
49
57
  }
@@ -1,105 +0,0 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- 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;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- var __metadata = (this && this.__metadata) || function (k, v) {
8
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
- };
10
- import { z } from 'zod';
11
- import { Command, Param } from '../decorators/command.js';
12
- let AddCommand = class AddCommand {
13
- a;
14
- b;
15
- async execute() {
16
- const result = this.a + this.b;
17
- return {
18
- content: [{ type: 'text', text: `${this.a} + ${this.b} = ${result}` }],
19
- };
20
- }
21
- };
22
- __decorate([
23
- Param(z.number().describe('First number')),
24
- __metadata("design:type", Number)
25
- ], AddCommand.prototype, "a", void 0);
26
- __decorate([
27
- Param(z.number().describe('Second number')),
28
- __metadata("design:type", Number)
29
- ], AddCommand.prototype, "b", void 0);
30
- AddCommand = __decorate([
31
- Command('math.add', 'Add two numbers')
32
- ], AddCommand);
33
- export { AddCommand };
34
- let SubtractCommand = class SubtractCommand {
35
- a;
36
- b;
37
- async execute() {
38
- const result = this.a - this.b;
39
- return {
40
- content: [{ type: 'text', text: `${this.a} - ${this.b} = ${result}` }],
41
- };
42
- }
43
- };
44
- __decorate([
45
- Param(z.number().describe('First number')),
46
- __metadata("design:type", Number)
47
- ], SubtractCommand.prototype, "a", void 0);
48
- __decorate([
49
- Param(z.number().describe('Second number')),
50
- __metadata("design:type", Number)
51
- ], SubtractCommand.prototype, "b", void 0);
52
- SubtractCommand = __decorate([
53
- Command('math.subtract', 'Subtract two numbers')
54
- ], SubtractCommand);
55
- export { SubtractCommand };
56
- let MultiplyCommand = class MultiplyCommand {
57
- a;
58
- b;
59
- async execute() {
60
- const result = this.a * this.b;
61
- return {
62
- content: [{ type: 'text', text: `${this.a} × ${this.b} = ${result}` }],
63
- };
64
- }
65
- };
66
- __decorate([
67
- Param(z.number().describe('First number')),
68
- __metadata("design:type", Number)
69
- ], MultiplyCommand.prototype, "a", void 0);
70
- __decorate([
71
- Param(z.number().describe('Second number')),
72
- __metadata("design:type", Number)
73
- ], MultiplyCommand.prototype, "b", void 0);
74
- MultiplyCommand = __decorate([
75
- Command('math.multiply', 'Multiply two numbers')
76
- ], MultiplyCommand);
77
- export { MultiplyCommand };
78
- let DivideCommand = class DivideCommand {
79
- a;
80
- b;
81
- async execute() {
82
- if (this.b === 0) {
83
- return {
84
- content: [{ type: 'text', text: 'Error: Division by zero' }],
85
- isError: true,
86
- };
87
- }
88
- const result = this.a / this.b;
89
- return {
90
- content: [{ type: 'text', text: `${this.a} ÷ ${this.b} = ${result}` }],
91
- };
92
- }
93
- };
94
- __decorate([
95
- Param(z.number().describe('First number')),
96
- __metadata("design:type", Number)
97
- ], DivideCommand.prototype, "a", void 0);
98
- __decorate([
99
- Param(z.number().describe('Second number')),
100
- __metadata("design:type", Number)
101
- ], DivideCommand.prototype, "b", void 0);
102
- DivideCommand = __decorate([
103
- Command('math.divide', 'Divide two numbers')
104
- ], DivideCommand);
105
- export { DivideCommand };
@@ -1,37 +0,0 @@
1
- import "reflect-metadata";
2
- const PARAM_METADATA_KEY = "command:params";
3
- const commandRegistry = new Map();
4
- export function Command(type, description) {
5
- return function (constructor) {
6
- const instance = new constructor();
7
- const params = new Map();
8
- const paramMetadata = Reflect.getMetadata(PARAM_METADATA_KEY, constructor) || {};
9
- Object.entries(paramMetadata).forEach(([key, schema]) => {
10
- params.set(key, schema);
11
- });
12
- commandRegistry.set(type, {
13
- type,
14
- description,
15
- params,
16
- handler: instance.execute.bind(instance),
17
- });
18
- return constructor;
19
- };
20
- }
21
- export function Param(schema) {
22
- return function (target, propertyKey) {
23
- const constructor = target.constructor;
24
- const existingParams = Reflect.getMetadata(PARAM_METADATA_KEY, constructor) || {};
25
- existingParams[propertyKey] = schema;
26
- Reflect.defineMetadata(PARAM_METADATA_KEY, existingParams, constructor);
27
- };
28
- }
29
- export function getCommandRegistry() {
30
- return commandRegistry;
31
- }
32
- export function getCommand(type) {
33
- return commandRegistry.get(type);
34
- }
35
- export function getAllCommands() {
36
- return Array.from(commandRegistry.values());
37
- }
@@ -1,93 +0,0 @@
1
- import { z } from "zod";
2
- import { getCommandRegistry } from "../decorators/command.js";
3
- export const executeCommandTool = (server) => {
4
- server.tool("executeCommand", "Execute any command by specifying its type and parameters", {
5
- type: {
6
- type: "string",
7
- description: "Command type (e.g., math.add, math.subtract, math.multiply, math.divide)",
8
- },
9
- params: {
10
- type: "object",
11
- description: "Command parameters",
12
- },
13
- }, async ({ type, params }) => {
14
- const command = getCommandRegistry().get(type);
15
- if (!command) {
16
- return {
17
- content: [
18
- {
19
- type: "text",
20
- text: `Unknown command type: ${type}\n\nAvailable commands:\n${Array.from(getCommandRegistry().keys())
21
- .map((t) => `- ${t}`)
22
- .join("\n")}`,
23
- },
24
- ],
25
- isError: true,
26
- };
27
- }
28
- const schema = z.object(Object.fromEntries(Array.from(command.params.entries()).map(([key, val]) => [key, val])));
29
- const validationResult = schema.safeParse(params);
30
- if (!validationResult.success) {
31
- return {
32
- content: [
33
- {
34
- type: "text",
35
- text: `Invalid parameters: ${validationResult.error.message}`,
36
- },
37
- ],
38
- isError: true,
39
- };
40
- }
41
- return await command.handler(validationResult.data);
42
- });
43
- };
44
- export const helpTool = (server) => {
45
- server.tool("help", "Get help information about available commands", {
46
- type: {
47
- type: "string",
48
- description: "Command type to get help for (optional)",
49
- },
50
- }, async ({ type }) => {
51
- if (type) {
52
- const command = getCommandRegistry().get(type);
53
- if (!command) {
54
- return {
55
- content: [
56
- {
57
- type: "text",
58
- text: `Unknown command type: ${type}\n\nAvailable commands:\n${Array.from(getCommandRegistry().keys())
59
- .map((t) => `- ${t}`)
60
- .join("\n")}`,
61
- },
62
- ],
63
- isError: true,
64
- };
65
- }
66
- const paramsInfo = Array.from(command.params.entries())
67
- .map(([key, schema]) => {
68
- const description = schema.description || "No description";
69
- return `- ${key}: ${description}`;
70
- })
71
- .join("\n");
72
- return {
73
- content: [
74
- {
75
- type: "text",
76
- text: `Command: ${command.type}\nDescription: ${command.description}\n\nParameters:\n${paramsInfo}`,
77
- },
78
- ],
79
- };
80
- }
81
- const commandList = Array.from(getCommandRegistry().values())
82
- .map((cmd) => `- ${cmd.type}: ${cmd.description}`)
83
- .join("\n");
84
- return {
85
- content: [
86
- {
87
- type: "text",
88
- text: `Available commands:\n${commandList}\n\nUse help with a specific command type for details.`,
89
- },
90
- ],
91
- };
92
- });
93
- };