hono-mcp 1.4.0 → 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/cli.js +118 -1
- package/dist/commands/math.js +113 -0
- package/dist/data/vscode-settings.json +185 -185
- package/dist/decorators/command.js +37 -0
- package/dist/index.js +40 -1
- package/dist/stdio.js +22 -0
- package/dist/tools/decorator-tools.js +90 -0
- package/package.json +2 -3
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 };
|
|
@@ -0,0 +1,90 @@
|
|
|
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: 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"),
|
|
9
|
+
}, async ({ type, params }) => {
|
|
10
|
+
console.log("executeCommand called with:", { type, params });
|
|
11
|
+
const command = getCommandRegistry().get(type);
|
|
12
|
+
if (!command) {
|
|
13
|
+
return {
|
|
14
|
+
content: [
|
|
15
|
+
{
|
|
16
|
+
type: "text",
|
|
17
|
+
text: `Unknown command type: ${type}\n\nAvailable commands:\n${Array.from(getCommandRegistry().keys())
|
|
18
|
+
.map((t) => `- ${t}`)
|
|
19
|
+
.join("\n")}`,
|
|
20
|
+
},
|
|
21
|
+
],
|
|
22
|
+
isError: true,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
const schema = z.object(Object.fromEntries(Array.from(command.params.entries()).map(([key, val]) => [key, val])));
|
|
26
|
+
const validationResult = schema.safeParse(params);
|
|
27
|
+
if (!validationResult.success) {
|
|
28
|
+
return {
|
|
29
|
+
content: [
|
|
30
|
+
{
|
|
31
|
+
type: "text",
|
|
32
|
+
text: `Invalid parameters: ${validationResult.error.message}`,
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
isError: true,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
return await command.handler(validationResult.data);
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
export const helpTool = (server) => {
|
|
42
|
+
server.tool("help", "Get help information about available commands", {
|
|
43
|
+
type: {
|
|
44
|
+
type: "string",
|
|
45
|
+
description: "Command type to get help for (optional)",
|
|
46
|
+
},
|
|
47
|
+
}, async ({ type }) => {
|
|
48
|
+
if (type) {
|
|
49
|
+
const command = getCommandRegistry().get(type);
|
|
50
|
+
if (!command) {
|
|
51
|
+
return {
|
|
52
|
+
content: [
|
|
53
|
+
{
|
|
54
|
+
type: "text",
|
|
55
|
+
text: `Unknown command type: ${type}\n\nAvailable commands:\n${Array.from(getCommandRegistry().keys())
|
|
56
|
+
.map((t) => `- ${t}`)
|
|
57
|
+
.join("\n")}`,
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
isError: true,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
const paramsInfo = Array.from(command.params.entries())
|
|
64
|
+
.map(([key, schema]) => {
|
|
65
|
+
const description = schema.description || "No description";
|
|
66
|
+
return `- ${key}: ${description}`;
|
|
67
|
+
})
|
|
68
|
+
.join("\n");
|
|
69
|
+
return {
|
|
70
|
+
content: [
|
|
71
|
+
{
|
|
72
|
+
type: "text",
|
|
73
|
+
text: `Command: ${command.type}\nDescription: ${command.description}\n\nParameters:\n${paramsInfo}`,
|
|
74
|
+
},
|
|
75
|
+
],
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
const commandList = Array.from(getCommandRegistry().values())
|
|
79
|
+
.map((cmd) => `- ${cmd.type}: ${cmd.description}`)
|
|
80
|
+
.join("\n");
|
|
81
|
+
return {
|
|
82
|
+
content: [
|
|
83
|
+
{
|
|
84
|
+
type: "text",
|
|
85
|
+
text: `Available commands:\n${commandList}\n\nUse help with a specific command type for details.`,
|
|
86
|
+
},
|
|
87
|
+
],
|
|
88
|
+
};
|
|
89
|
+
});
|
|
90
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hono-mcp",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.2",
|
|
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,8 +12,7 @@
|
|
|
12
12
|
"README.md"
|
|
13
13
|
],
|
|
14
14
|
"scripts": {
|
|
15
|
-
"build": "
|
|
16
|
-
"build:clean": "tsc",
|
|
15
|
+
"build": "tsc",
|
|
17
16
|
"start": "node dist/cli.js",
|
|
18
17
|
"dev": "tsx src/cli.ts",
|
|
19
18
|
"dev:vercel": "tsx src/index.ts",
|