lhwapi-mcp-server 1.0.4 → 1.0.6

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.
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env node
2
+ const { spawn } = require("child_process");
3
+ const path = require("path");
4
+
5
+ const args = process.argv.slice(2);
6
+ const child = spawn("node", [path.join(__dirname, "bundle.js"), ...args], {
7
+ stdio: "inherit",
8
+ shell: true,
9
+ });
10
+
11
+ child.on("exit", (code) => {
12
+ process.exit(code || 0);
13
+ });
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
@@ -0,0 +1,123 @@
1
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
3
+ import { z } from "zod";
4
+ const TRANSLATE_API = "https://api.mymemory.translated.net/get";
5
+ const SUPPORTED_LANGUAGES = {
6
+ en: "英语",
7
+ zh: "中文",
8
+ ja: "日语",
9
+ ko: "韩语",
10
+ fr: "法语",
11
+ de: "德语",
12
+ es: "西班牙语",
13
+ it: "意大利语",
14
+ ru: "俄语",
15
+ pt: "葡萄牙语",
16
+ ar: "阿拉伯语",
17
+ hi: "印地语",
18
+ th: "泰语",
19
+ vi: "越南语",
20
+ id: "印尼语",
21
+ ms: "马来语",
22
+ tr: "土耳其语",
23
+ pl: "波兰语",
24
+ nl: "荷兰语",
25
+ sv: "瑞典语",
26
+ };
27
+ async function translate(text, from, to) {
28
+ const langPair = `${from}|${to}`;
29
+ const url = `${TRANSLATE_API}?q=${encodeURIComponent(text)}&langpair=${langPair}`;
30
+ const response = await fetch(url);
31
+ if (!response.ok) {
32
+ throw new Error(`翻译 API 错误: ${response.status}`);
33
+ }
34
+ const data = await response.json();
35
+ if (data.responseStatus !== 200) {
36
+ throw new Error(data.responseDetails || "翻译失败");
37
+ }
38
+ return data.responseData.translatedText;
39
+ }
40
+ const server = new McpServer({
41
+ name: "translate-mcp-server",
42
+ version: "1.0.0",
43
+ });
44
+ server.registerTool("translate", {
45
+ description: "翻译文本",
46
+ inputSchema: z.object({
47
+ text: z.string().describe("要翻译的文本"),
48
+ from: z.string().describe("源语言代码,如 en, zh, ja"),
49
+ to: z.string().describe("目标语言代码,如 en, zh, ja"),
50
+ }).shape,
51
+ }, async ({ text, from, to }) => {
52
+ try {
53
+ const result = await translate(text, from, to);
54
+ return {
55
+ content: [
56
+ {
57
+ type: "text",
58
+ text: `原文 (${SUPPORTED_LANGUAGES[from] || from}): ${text}\n\n翻译 (${SUPPORTED_LANGUAGES[to] || to}): ${result}`,
59
+ },
60
+ ],
61
+ };
62
+ }
63
+ catch (error) {
64
+ return {
65
+ content: [
66
+ {
67
+ type: "text",
68
+ text: `翻译错误: ${error instanceof Error ? error.message : String(error)}`,
69
+ },
70
+ ],
71
+ isError: true,
72
+ };
73
+ }
74
+ });
75
+ server.registerTool("listLanguages", {
76
+ description: "列出支持的语言",
77
+ inputSchema: z.object({}).shape,
78
+ }, async () => {
79
+ const list = Object.entries(SUPPORTED_LANGUAGES)
80
+ .map(([code, name]) => `${code} - ${name}`)
81
+ .join("\n");
82
+ return {
83
+ content: [{ type: "text", text: `支持的语言:\n\n${list}` }],
84
+ };
85
+ });
86
+ server.registerTool("detectLanguage", {
87
+ description: "检测文本语言",
88
+ inputSchema: z.object({
89
+ text: z.string().describe("要检测的文本"),
90
+ }).shape,
91
+ }, async ({ text }) => {
92
+ try {
93
+ const result = await translate(text, "auto", "en");
94
+ return {
95
+ content: [
96
+ {
97
+ type: "text",
98
+ text: `检测结果: ${result} (通过翻译到英语间接检测)`,
99
+ },
100
+ ],
101
+ };
102
+ }
103
+ catch (error) {
104
+ return {
105
+ content: [
106
+ {
107
+ type: "text",
108
+ text: `检测错误: ${error instanceof Error ? error.message : String(error)}`,
109
+ },
110
+ ],
111
+ isError: true,
112
+ };
113
+ }
114
+ });
115
+ async function main() {
116
+ const transport = new StdioServerTransport();
117
+ await server.connect(transport);
118
+ }
119
+ main().catch((error) => {
120
+ console.error("Server error:", error);
121
+ process.exit(1);
122
+ });
123
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,aAAa,GAAG,yCAAyC,CAAC;AAEhE,MAAM,mBAAmB,GAA2B;IAClD,EAAE,EAAE,IAAI;IACR,EAAE,EAAE,IAAI;IACR,EAAE,EAAE,IAAI;IACR,EAAE,EAAE,IAAI;IACR,EAAE,EAAE,IAAI;IACR,EAAE,EAAE,IAAI;IACR,EAAE,EAAE,MAAM;IACV,EAAE,EAAE,MAAM;IACV,EAAE,EAAE,IAAI;IACR,EAAE,EAAE,MAAM;IACV,EAAE,EAAE,MAAM;IACV,EAAE,EAAE,KAAK;IACT,EAAE,EAAE,IAAI;IACR,EAAE,EAAE,KAAK;IACT,EAAE,EAAE,KAAK;IACT,EAAE,EAAE,KAAK;IACT,EAAE,EAAE,MAAM;IACV,EAAE,EAAE,KAAK;IACT,EAAE,EAAE,KAAK;IACT,EAAE,EAAE,KAAK;CACV,CAAC;AAEF,KAAK,UAAU,SAAS,CACtB,IAAY,EACZ,IAAY,EACZ,EAAU;IAEV,MAAM,QAAQ,GAAG,GAAG,IAAI,IAAI,EAAE,EAAE,CAAC;IACjC,MAAM,GAAG,GAAG,GAAG,aAAa,MAAM,kBAAkB,CAAC,IAAI,CAAC,aAAa,QAAQ,EAAE,CAAC;IAElF,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,CAA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AAO,EAAE;gBACP;oBACE,IAAI,EAAE,MAAe;oBACrB,IAAI,EAAE,SAAS,MAAM,gBAAgB;iBACtC;aACF;SACF,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO;YACL,OAAO,EAAE;gBACP;oBACE,IAAI,EAAE,MAAe;oBACrB,IAAI,EAAE,SAAS,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;iBACxE;aACF;YACD,OAAO,EAAE,IAAI;SACd,CAAC;IACJ,CAAC;AACH,CAAC,CACF,CAAC;AAEF,KAAK,UAAU,IAAI;IACjB,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;IAC7C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;AAClC,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IACrB,OAAO,CAAC,KAAK,CAAC,eAAe,EAAE,KAAK,CAAC,CAAC;IACtC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "translate-mcp-server",
3
+ "version": "1.0.1",
4
+ "description": "MCP server for translation",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "bin": {
9
+ "translate-mcp-server": "dist/cli.cjs"
10
+ },
11
+ "scripts": {
12
+ "build": "tsc",
13
+ "bundle": "node scripts/build.mjs",
14
+ "start": "node dist/bundle.js",
15
+ "dev": "tsx src/index.ts"
16
+ },
17
+ "keywords": [
18
+ "mcp",
19
+ "translate"
20
+ ],
21
+ "author": "",
22
+ "license": "MIT",
23
+ "dependencies": {
24
+ "@modelcontextprotocol/sdk": "^1.27.1",
25
+ "zod": "^4.3.6"
26
+ },
27
+ "devDependencies": {
28
+ "@types/node": "^25.3.2",
29
+ "esbuild": "^0.27.3",
30
+ "tsx": "^4.21.0",
31
+ "typescript": "^5.9.3"
32
+ }
33
+ }
@@ -0,0 +1,10 @@
1
+ import * as esbuild from 'esbuild';
2
+
3
+ await esbuild.build({
4
+ entryPoints: ['src/index.ts'],
5
+ bundle: true,
6
+ platform: 'node',
7
+ target: 'node18',
8
+ outfile: 'dist/bundle.js',
9
+ format: 'esm',
10
+ });
@@ -0,0 +1,153 @@
1
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
3
+ import { z } from "zod";
4
+
5
+ const TRANSLATE_API = "https://api.mymemory.translated.net/get";
6
+
7
+ const SUPPORTED_LANGUAGES: Record<string, string> = {
8
+ en: "英语",
9
+ zh: "中文",
10
+ ja: "日语",
11
+ ko: "韩语",
12
+ fr: "法语",
13
+ de: "德语",
14
+ es: "西班牙语",
15
+ it: "意大利语",
16
+ ru: "俄语",
17
+ pt: "葡萄牙语",
18
+ ar: "阿拉伯语",
19
+ hi: "印地语",
20
+ th: "泰语",
21
+ vi: "越南语",
22
+ id: "印尼语",
23
+ ms: "马来语",
24
+ tr: "土耳其语",
25
+ pl: "波兰语",
26
+ nl: "荷兰语",
27
+ sv: "瑞典语",
28
+ };
29
+
30
+ async function translate(
31
+ text: string,
32
+ from: string,
33
+ to: string
34
+ ): Promise<string> {
35
+ const langPair = `${from}|${to}`;
36
+ const url = `${TRANSLATE_API}?q=${encodeURIComponent(text)}&langpair=${langPair}`;
37
+
38
+ const response = await fetch(url);
39
+ if (!response.ok) {
40
+ throw new Error(`翻译 API 错误: ${response.status}`);
41
+ }
42
+
43
+ const data = await response.json() as {
44
+ responseStatus: number;
45
+ responseDetails?: string;
46
+ responseData: { translatedText: string };
47
+ };
48
+
49
+ if (data.responseStatus !== 200) {
50
+ throw new Error(data.responseDetails || "翻译失败");
51
+ }
52
+
53
+ return data.responseData.translatedText;
54
+ }
55
+
56
+ const server = new McpServer({
57
+ name: "translate-mcp-server",
58
+ version: "1.0.0",
59
+ });
60
+
61
+ server.registerTool(
62
+ "translate",
63
+ {
64
+ description: "翻译文本",
65
+ inputSchema: z.object({
66
+ text: z.string().describe("要翻译的文本"),
67
+ from: z.string().describe("源语言代码,如 en, zh, ja"),
68
+ to: z.string().describe("目标语言代码,如 en, zh, ja"),
69
+ }).shape,
70
+ },
71
+ async ({ text, from, to }: { text: string; from: string; to: string }) => {
72
+ try {
73
+ const result = await translate(text, from, to);
74
+ return {
75
+ content: [
76
+ {
77
+ type: "text" as const,
78
+ text: `原文 (${SUPPORTED_LANGUAGES[from] || from}): ${text}\n\n翻译 (${SUPPORTED_LANGUAGES[to] || to}): ${result}`,
79
+ },
80
+ ],
81
+ };
82
+ } catch (error) {
83
+ return {
84
+ content: [
85
+ {
86
+ type: "text" as const,
87
+ text: `翻译错误: ${error instanceof Error ? error.message : String(error)}`,
88
+ },
89
+ ],
90
+ isError: true,
91
+ };
92
+ }
93
+ }
94
+ );
95
+
96
+ server.registerTool(
97
+ "listLanguages",
98
+ {
99
+ description: "列出支持的语言",
100
+ inputSchema: z.object({}).shape,
101
+ },
102
+ async () => {
103
+ const list = Object.entries(SUPPORTED_LANGUAGES)
104
+ .map(([code, name]) => `${code} - ${name}`)
105
+ .join("\n");
106
+ return {
107
+ content: [{ type: "text" as const, text: `支持的语言:\n\n${list}` }],
108
+ };
109
+ }
110
+ );
111
+
112
+ server.registerTool(
113
+ "detectLanguage",
114
+ {
115
+ description: "检测文本语言",
116
+ inputSchema: z.object({
117
+ text: z.string().describe("要检测的文本"),
118
+ }).shape,
119
+ },
120
+ async ({ text }: { text: string }) => {
121
+ try {
122
+ const result = await translate(text, "auto", "en");
123
+ return {
124
+ content: [
125
+ {
126
+ type: "text" as const,
127
+ text: `检测结果: ${result} (通过翻译到英语间接检测)`,
128
+ },
129
+ ],
130
+ };
131
+ } catch (error) {
132
+ return {
133
+ content: [
134
+ {
135
+ type: "text" as const,
136
+ text: `检测错误: ${error instanceof Error ? error.message : String(error)}`,
137
+ },
138
+ ],
139
+ isError: true,
140
+ };
141
+ }
142
+ }
143
+ );
144
+
145
+ async function main() {
146
+ const transport = new StdioServerTransport();
147
+ await server.connect(transport);
148
+ }
149
+
150
+ main().catch((error) => {
151
+ console.error("Server error:", error);
152
+ process.exit(1);
153
+ });
@@ -0,0 +1,19 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "NodeNext",
5
+ "moduleResolution": "NodeNext",
6
+ "lib": ["ES2022"],
7
+ "outDir": "./dist",
8
+ "rootDir": "./src",
9
+ "strict": true,
10
+ "esModuleInterop": true,
11
+ "skipLibCheck": true,
12
+ "forceConsistentCasingInFileNames": true,
13
+ "declaration": true,
14
+ "declarationMap": true,
15
+ "sourceMap": true
16
+ },
17
+ "include": ["src/**/*"],
18
+ "exclude": ["node_modules", "dist"]
19
+ }