-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
57 lines (49 loc) · 1.27 KB
/
index.js
File metadata and controls
57 lines (49 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { z } from "zod";
// 创建 MCP 服务
const server = new McpServer({
name: "mcp-text-tools",
version: "1.0.0"
});
// 工具:命名风格转换
server.tool(
"convertCase",
{
text: z.string(),
style: z.enum(["camel", "kebab", "snake"]),
},
async ({ text, style }) => {
let result = "";
function toCamel(str) {
return str
.replace(/[-_](.)/g, (_, c) => c.toUpperCase())
.replace(/^(.)/, (c) => c.toLowerCase());
}
function toKebab(str) {
return str
.replace(/([a-z])([A-Z])/g, "$1-$2")
.replace(/_/g, "-")
.toLowerCase();
}
function toSnake(str) {
return str
.replace(/([a-z])([A-Z])/g, "$1_$2")
.replace(/-/g, "_")
.toLowerCase();
}
if (style === "camel") {
result = toCamel(text);
} else if (style === "kebab") {
result = toKebab(text);
} else if (style === "snake") {
result = toSnake(text);
}
return {
content: [{ type: "text", text: result }]
};
}
);
// 启动服务
const transport = new StdioServerTransport();
await server.connect(transport);