hono-mcp 1.3.0 → 1.4.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 CHANGED
@@ -1,249 +1,51 @@
1
1
  # Hono MCP Server
2
2
 
3
- 一个基于 [Hono](https://hono.dev/) 构建的 Model Context Protocol (MCP) 服务器,支持多种部署方式。
3
+ 基于 Hono Model Context Protocol (MCP) 服务器,支持装饰器模式定义工具,支持 stdio 和 HTTP 两种模式。
4
4
 
5
- ## ✨ 特性
6
-
7
- - 🎯 **装饰器模式**:使用 TypeScript 装饰器优雅地定义 MCP 工具
8
- - 🚀 **多种部署方式**:支持 Vercel 部署和本地 CLI 运行
9
- - 🔧 **统一命令接口**:通过 `executeCommand` 和 `help` 两个工具管理所有命令
10
- - 📦 **即插即用**:通过 `npx` 快速启动,无需复杂配置
11
- - 🛡️ **类型安全**:使用 TypeScript 和 Zod 进行类型检查和验证
12
- - 🎨 **易于扩展**:添加新命令只需创建新的装饰器类
13
-
14
- ## 📦 安装
15
-
16
- ### 通过 npx 直接运行(推荐)
5
+ ## 安装
17
6
 
18
7
  ```bash
19
8
  npx hono-mcp
20
9
  ```
21
10
 
22
- ### 全局安装
11
+ ## 使用
23
12
 
24
- ```bash
25
- npm install -g hono-mcp
26
- hono-mcp
27
- ```
28
-
29
- ### 作为项目依赖安装
13
+ ### CLI 模式
30
14
 
31
15
  ```bash
32
- npm install hono-mcp
33
- npx hono-mcp
34
- ```
35
-
36
- ## 🚀 使用方法
37
-
38
- ### 命令行使用
39
-
40
- ```bash
41
- # 使用默认配置(端口 3000)
42
- npx hono-mcp
16
+ # HTTP 模式(默认)
17
+ npx hono-mcp --mode http --port 3000
43
18
 
44
- # 指定端口
45
- npx hono-mcp --port 8080
46
-
47
- # 指定主机
48
- npx hono-mcp --host localhost
49
-
50
- # 指定环境
51
- npx hono-mcp --env development
52
-
53
- # 组合使用
54
- npx hono-mcp --port 8080 --host localhost --env development
55
-
56
- # 查看帮助
57
- npx hono-mcp --help
19
+ # stdio 模式
20
+ npx hono-mcp --mode stdio
58
21
  ```
59
22
 
60
- ### 环境变量
61
-
62
- ```bash
63
- # 设置端口
64
- export PORT=8080
65
- npx hono-mcp
66
-
67
- # 设置主机
68
- export HOST=localhost
69
- npx hono-mcp
70
-
71
- # 设置环境
72
- export NODE_ENV=development
73
- npx hono-mcp
74
- ```
75
-
76
- ## 🌐 部署方式
77
-
78
- ### 方式 1:Vercel 部署
79
-
80
- 1. **克隆项目**
23
+ ### Vercel 部署
81
24
 
82
25
  ```bash
83
26
  git clone https://github.com/Fromsko/hono-mcp-remote-server.git
84
27
  cd hono-mcp-remote-server
85
- ```
86
-
87
- 2. **安装依赖**
88
-
89
- ```bash
90
28
  bun install
91
- ```
92
-
93
- 3. **本地开发**
94
-
95
- ```bash
96
- bun run dev:vercel
97
- ```
98
-
99
- 4. **部署到 Vercel**
100
-
101
- ```bash
102
29
  vc deploy
103
30
  ```
104
31
 
105
- 或者通过 Vercel Dashboard 连接 GitHub 仓库进行自动部署。
106
-
107
- ### 方式 2:本地服务器
108
-
109
- 1. **克隆项目**
110
-
111
- ```bash
112
- git clone https://github.com/Fromsko/hono-mcp-remote-server.git
113
- cd hono-mcp-remote-server
114
- ```
115
-
116
- 2. **安装依赖**
117
-
118
- ```bash
119
- bun install
120
- ```
121
-
122
- 3. **构建项目**
32
+ ## 功能
123
33
 
124
- ```bash
125
- bun run build
126
- ```
34
+ - **装饰器模式**:使用 TypeScript 装饰器优雅定义 MCP 工具
35
+ - **双模式支持**:stdio 和 HTTP 两种传输方式
36
+ - **即插即用**:npx 直接运行,无需配置
37
+ - **类型安全**:TypeScript + Zod 验证
127
38
 
128
- 4. **启动服务器**
39
+ ## 可用命令
129
40
 
130
- ```bash
131
- bun run start
132
- ```
41
+ - `executeCommand` - 执行任意命令
42
+ - `help` - 查看帮助信息
133
43
 
134
- 或者使用 npx:
44
+ ## 开发
135
45
 
136
46
  ```bash
137
- npx hono-mcp --port 3000
138
- ```
139
-
140
- ## 📡 API 端点
141
-
142
- - **GET `/`** - 服务器信息和可用工具列表
143
- - **POST `/mcp/*`** - MCP 协议端点,用于工具执行
144
- - **GET `/help`** - 查看所有可用命令的帮助信息
145
- - **GET `/vscode`** - VS Code 设置示例
146
-
147
- ## 🔧 开发
148
-
149
- ### 本地开发
150
-
151
- ```bash
152
- # 安装依赖
153
47
  bun install
154
-
155
- # 开发模式(CLI)
156
- bun run dev
157
-
158
- # 开发模式(Vercel)
159
- bun run dev:vercel
160
-
161
- # 构建
162
- bun run build
163
-
164
- # 启动生产服务器
165
- bun run start
166
- ```
167
-
168
- ### 添加新命令
169
-
170
- 使用装饰器模式创建新命令非常简单:
171
-
172
- ```typescript
173
- import { Command, Param } from '../decorators/command.js'
174
- import { z } from 'zod'
175
- import type { CommandHandler } from '../decorators/command.js'
176
-
177
- @Command('math.square', 'Calculate the square of a number')
178
- export class SquareCommand implements CommandHandler {
179
- @Param(z.number().describe('The number to square'))
180
- number!: number
181
-
182
- async execute() {
183
- const result = this.number * this.number
184
- return {
185
- content: [{ type: 'text', text: `${this.number}² = ${result}` }],
186
- }
187
- }
188
- }
48
+ bun run dev # CLI 开发
49
+ bun run dev:vercel # Vercel 开发
50
+ bun run build # 构建
189
51
  ```
190
-
191
- 然后在 `src/index.ts` 中导入该命令:
192
-
193
- ```typescript
194
- import './commands/math.js'
195
- import './commands/your-new-command.js'
196
- ```
197
-
198
- ## 📖 使用 MCP 服务器
199
-
200
- ### 通过 executeCommand 工具
201
-
202
- ```json
203
- {
204
- "type": "math.add",
205
- "params": {
206
- "a": 5,
207
- "b": 3
208
- }
209
- }
210
- ```
211
-
212
- ### 通过 help 工具
213
-
214
- 查看所有可用命令及其描述。
215
-
216
- ## 🎯 可用命令
217
-
218
- 当前支持以下数学运算命令:
219
-
220
- - `math.add` - 加法运算
221
- - `math.subtract` - 减法运算
222
- - `math.multiply` - 乘法运算
223
- - `math.divide` - 除法运算
224
-
225
- ## 📚 设计文档
226
-
227
- 详细的设计文档请参考:[MCP 装饰器模式设计文档](./docs/MCP-装饰器模式设计文档.md)
228
-
229
- ## 🤝 贡献
230
-
231
- 欢迎提交 Issue 和 Pull Request!
232
-
233
- ## 📄 许可证
234
-
235
- MIT License
236
-
237
- ## 🔗 相关链接
238
-
239
- - [Hono 文档](https://hono.dev/)
240
- - [MCP 协议规范](https://modelcontextprotocol.io/)
241
- - [mcp-handler](https://github.com/modelcontextprotocol/typescript-sdk)
242
-
243
- ## 📞 联系方式
244
-
245
- 作者: fromsko
246
-
247
- ---
248
-
249
- **提示**: 使用 `npx hono-mcp --help` 查看完整的命令行选项。
package/dist/cli.js CHANGED
@@ -1,21 +1,25 @@
1
1
  #!/usr/bin/env node
2
- import { serve } from '@hono/node-server';
3
- import app from './index.js';
2
+ import { serve } from "@hono/node-server";
3
+ import app from "./index.js";
4
+ import { runStdioServer } from "./stdio.js";
4
5
  function parseArgs() {
5
6
  const args = process.argv.slice(2);
6
7
  const options = {};
7
8
  for (let i = 0; i < args.length; i++) {
8
9
  const arg = args[i];
9
- if (arg === '--port' || arg === '-p') {
10
+ if (arg === "--port" || arg === "-p") {
10
11
  options.port = parseInt(args[++i], 10);
11
12
  }
12
- else if (arg === '--host' || arg === '-h') {
13
+ else if (arg === "--host" || arg === "-h") {
13
14
  options.host = args[++i];
14
15
  }
15
- else if (arg === '--env') {
16
+ else if (arg === "--env") {
16
17
  options.env = args[++i];
17
18
  }
18
- else if (arg === '--help' || arg === '-help') {
19
+ else if (arg === "--mode") {
20
+ options.mode = args[++i];
21
+ }
22
+ else if (arg === "--help" || arg === "-help") {
19
23
  console.log(`
20
24
  Usage: hono-mcp [options]
21
25
 
@@ -23,13 +27,37 @@ Options:
23
27
  --port, -p <port> Port to listen on (default: 3000)
24
28
  --host, -h <host> Host to bind to (default: 0.0.0.0)
25
29
  --env <environment> Environment: development or production (default: production)
30
+ --mode <mode> Mode: stdio or http (default: http)
26
31
  --help, -help Show this help message
27
32
 
28
33
  Examples:
29
- hono-mcp # Start server on default port 3000
30
- hono-mcp --port 8080 # Start server on port 8080
31
- hono-mcp --port 8080 --host localhost # Start on localhost:8080
34
+ hono-mcp # Start HTTP server on default port 3000
35
+ hono-mcp --mode stdio # Start in stdio mode (for MCP clients)
36
+ hono-mcp --port 8080 # Start HTTP server on port 8080
37
+ hono-mcp --port 8080 --host localhost # Start HTTP on localhost:8080
32
38
  hono-mcp --env development # Start in development mode
39
+
40
+ MCP Configuration (Claude Desktop):
41
+
42
+ HTTP Mode:
43
+ {
44
+ "mcpServers": {
45
+ "hono-mcp": {
46
+ "command": "bunx",
47
+ "args": ["-y", "hono-mcp@latest"]
48
+ }
49
+ }
50
+ }
51
+
52
+ Stdio Mode (default):
53
+ {
54
+ "mcpServers": {
55
+ "hono-mcp": {
56
+ "command": "bunx",
57
+ "args": ["-y", "hono-mcp@latest"]
58
+ }
59
+ }
60
+ }
33
61
  `);
34
62
  process.exit(0);
35
63
  }
@@ -38,43 +66,53 @@ Examples:
38
66
  }
39
67
  async function main() {
40
68
  const options = parseArgs();
41
- const port = options.port || parseInt(process.env.PORT || '3000', 10);
42
- const host = options.host || process.env.HOST || '0.0.0.0';
43
- const env = options.env || process.env.NODE_ENV || 'production';
44
- console.log(`🚀 Starting Hono MCP Server...`);
45
- console.log(`📦 Environment: ${env}`);
46
- console.log(`🌐 Host: ${host}`);
47
- console.log(`🔌 Port: ${port}`);
48
- console.log(`📡 MCP Endpoint: http://${host}:${port}/mcp`);
49
- console.log(`📖 Help: http://${host}:${port}/help`);
50
- console.log('');
51
- try {
52
- const server = await serve({
53
- fetch: app.fetch,
54
- port,
55
- hostname: host,
56
- });
57
- console.log(`✅ Server is running!`);
69
+ const mode = options.mode || "stdio";
70
+ if (mode === "stdio") {
71
+ console.log(`🚀 Starting Hono MCP Server in stdio mode...`);
58
72
  console.log(``);
59
- console.log(`Press Ctrl+C to stop the server`);
60
- process.on('SIGINT', () => {
61
- console.log('\n\n🛑 Shutting down server...');
62
- server.close(() => {
63
- console.log('✅ Server stopped');
64
- process.exit(0);
73
+ await runStdioServer();
74
+ }
75
+ else {
76
+ const port = options.port || parseInt(process.env.PORT || "3000", 10);
77
+ const host = options.host || process.env.HOST || "0.0.0.0";
78
+ const env = options.env ||
79
+ process.env.NODE_ENV ||
80
+ "production";
81
+ console.log(`🚀 Starting Hono MCP Server...`);
82
+ console.log(`📦 Environment: ${env}`);
83
+ console.log(`🌐 Host: ${host}`);
84
+ console.log(`🔌 Port: ${port}`);
85
+ console.log(`📡 MCP Endpoint: http://${host}:${port}/mcp`);
86
+ console.log(`📖 Help: http://${host}:${port}/help`);
87
+ console.log("");
88
+ try {
89
+ const server = serve({
90
+ fetch: app.fetch,
91
+ port,
92
+ hostname: host,
65
93
  });
66
- });
67
- process.on('SIGTERM', () => {
68
- console.log('\n\n🛑 Shutting down server...');
69
- server.close(() => {
70
- console.log('✅ Server stopped');
71
- process.exit(0);
94
+ console.log(`✅ Server is running!`);
95
+ console.log(``);
96
+ console.log(`Press Ctrl+C to stop the server`);
97
+ process.on("SIGINT", () => {
98
+ console.log("\n\n🛑 Shutting down server...");
99
+ server.close(() => {
100
+ console.log("✅ Server stopped");
101
+ process.exit(0);
102
+ });
72
103
  });
73
- });
74
- }
75
- catch (error) {
76
- console.error('❌ Failed to start server:', error);
77
- process.exit(1);
104
+ process.on("SIGTERM", () => {
105
+ console.log("\n\n🛑 Shutting down server...");
106
+ server.close(() => {
107
+ console.log("✅ Server stopped");
108
+ process.exit(0);
109
+ });
110
+ });
111
+ }
112
+ catch (error) {
113
+ console.error("❌ Failed to start server:", error);
114
+ process.exit(1);
115
+ }
78
116
  }
79
117
  }
80
118
  main();
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
- import 'reflect-metadata';
2
1
  import { Hono } from "hono";
3
2
  import { createMcpHandler } from "mcp-handler";
3
+ import 'reflect-metadata';
4
4
  import vscodeSettings from './data/vscode-settings.json' with { type: 'json' };
5
5
  import { executeCommandTool, helpTool } from "./tools/decorator-tools.js";
6
6
  import './commands/math.js';
package/dist/stdio.js ADDED
@@ -0,0 +1,22 @@
1
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
3
+ import "reflect-metadata";
4
+ import "./commands/math.js";
5
+ import { executeCommandTool, helpTool } from "./tools/decorator-tools.js";
6
+ async function runStdioServer() {
7
+ const server = new McpServer({
8
+ name: "hono-mcp",
9
+ version: "1.0.0",
10
+ }, {
11
+ capabilities: {
12
+ tools: {},
13
+ },
14
+ });
15
+ const tools = [executeCommandTool, helpTool];
16
+ tools.forEach((tool) => {
17
+ tool(server);
18
+ });
19
+ const transport = new StdioServerTransport();
20
+ await server.connect(transport);
21
+ }
22
+ export { runStdioServer };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hono-mcp",
3
- "version": "1.3.0",
3
+ "version": "1.4.1",
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": {
@@ -15,7 +15,10 @@
15
15
  "build": "tsc",
16
16
  "start": "node dist/cli.js",
17
17
  "dev": "tsx src/cli.ts",
18
- "dev:vercel": "tsx src/index.ts"
18
+ "dev:vercel": "tsx src/index.ts",
19
+ "build:linux": "bun build src/cli.ts --compile --target=bun-linux-x64 --outfile=dist/hono-mcp-linux",
20
+ "build:windows": "bun build src/cli.ts --compile --target=bun-windows-x64 --outfile=dist/hono-mcp.exe",
21
+ "build:all": "bun run build:linux && bun run build:windows"
19
22
  },
20
23
  "keywords": [
21
24
  "mcp",
@@ -43,7 +46,11 @@
43
46
  },
44
47
  "devDependencies": {
45
48
  "@types/node": "^20.11.17",
49
+ "terser-webpack-plugin": "^5.3.16",
50
+ "ts-loader": "^9.5.4",
46
51
  "tsx": "^4.7.0",
47
- "typescript": "^5.9.3"
52
+ "typescript": "^5.9.3",
53
+ "webpack": "^5.104.1",
54
+ "webpack-cli": "^6.0.1"
48
55
  }
49
56
  }