@flyme-ha/meizu-ha-mcp-stdio 1.0.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/README.md ADDED
File without changes
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
package/dist/index.js ADDED
@@ -0,0 +1,71 @@
1
+ #!/usr/bin/env node
2
+ import axios from 'axios';
3
+ function getConfig() {
4
+ const httpUrl = "http://iot-ha-test.meizu.com";
5
+ const token = process.env.MCP_TOKEN;
6
+ if (!httpUrl) {
7
+ throw new Error('MCP_HTTP_URL environment variable is required');
8
+ }
9
+ if (!token) {
10
+ throw new Error('MCP_TOKEN environment variable is required');
11
+ }
12
+ return { httpUrl, token };
13
+ }
14
+ async function main() {
15
+ const config = getConfig();
16
+ const httpClient = axios.create({
17
+ baseURL: config.httpUrl,
18
+ headers: {
19
+ 'Authorization': `Bearer ${config.token}`,
20
+ 'Content-Type': 'application/json'
21
+ },
22
+ });
23
+ console.error('MCP stdio proxy server started');
24
+ console.error(`Forwarding to: ${config.httpUrl}`);
25
+ console.error(`Token: ${config.token.substring(0, 10)}...`);
26
+ let buffer = '';
27
+ process.stdin.setEncoding('utf8');
28
+ process.stdin.on('data', async (data) => {
29
+ buffer += data;
30
+ const lines = buffer.split('\n');
31
+ buffer = lines.pop() || '';
32
+ for (const line of lines) {
33
+ if (!line.trim())
34
+ continue;
35
+ try {
36
+ const request = JSON.parse(line);
37
+ console.error(`[转发请求] method: ${request.method}, id: ${request.id}`);
38
+ const response = await httpClient.post('/api/mcp', request);
39
+ const responseStr = JSON.stringify(response.data);
40
+ console.log(responseStr);
41
+ }
42
+ catch (error) {
43
+ console.error(`[错误] ${error instanceof Error ? error.message : String(error)}`);
44
+ let errorResponse = {
45
+ jsonrpc: '2.0',
46
+ id: null,
47
+ error: {
48
+ code: -32603,
49
+ message: error instanceof Error ? error.message : 'Unknown error',
50
+ },
51
+ };
52
+ try {
53
+ const request = JSON.parse(line);
54
+ errorResponse.id = request.id;
55
+ }
56
+ catch {
57
+ // ignore
58
+ }
59
+ console.log(JSON.stringify(errorResponse));
60
+ }
61
+ }
62
+ });
63
+ process.stdin.on('end', () => {
64
+ console.error('MCP stdio proxy server stopped');
65
+ });
66
+ }
67
+ main().catch((error) => {
68
+ console.error('Fatal error:', error);
69
+ process.exit(1);
70
+ });
71
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,KAAK,MAAM,OAAO,CAAC;AAO1B,SAAS,SAAS;IAChB,MAAM,OAAO,GAAG,8BAA8B,CAAC;IAC/C,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC;IAEpC,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;IACnE,CAAC;IAED,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;IAChE,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;AAC5B,CAAC;AAED,KAAK,UAAU,IAAI;IACjB,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;IAE3B,MAAM,UAAU,GAAG,KAAK,CAAC,MAAM,CAAC;QAC9B,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,OAAO,EAAE;YACP,eAAe,EAAE,UAAU,MAAM,CAAC,KAAK,EAAE;YACzC,cAAc,EAAE,kBAAkB;SACnC;KACF,CAAC,CAAC;IAEH,OAAO,CAAC,KAAK,CAAC,gCAAgC,CAAC,CAAC;IAChD,OAAO,CAAC,KAAK,CAAC,kBAAkB,MAAM,CAAC,OAAO,EA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AAE,EAAE,IAAI;oBACR,KAAK,EAAE;wBACL,IAAI,EAAE,CAAC,KAAK;wBACZ,OAAO,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe;qBAClE;iBACF,CAAC;gBAEF,IAAI,CAAC;oBACH,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;oBACjC,aAAa,CAAC,EAAE,GAAG,OAAO,CAAC,EAAE,CAAC;gBAChC,CAAC;gBAAC,MAAM,CAAC;oBACP,SAAS;gBACX,CAAC;gBAED,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC,CAAC;YAC7C,CAAC;QACH,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE;QAC3B,OAAO,CAAC,KAAK,CAAC,gCAAgC,CAAC,CAAC;IAClD,CAAC,CAAC,CAAC;AACL,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IACrB,OAAO,CAAC,KAAK,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;IACrC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "@flyme-ha/meizu-ha-mcp-stdio",
3
+ "version": "1.0.0",
4
+ "description": "MCP stdio proxy for HTTP service with token authentication",
5
+ "type": "module",
6
+ "publishConfig": {
7
+ "access": "public"
8
+ },
9
+ "bin": {
10
+ "meizu-ha-mcp-stdio": "./dist/index.js"
11
+ },
12
+ "scripts": {
13
+ "build": "tsc",
14
+ "start": "node dist/index.js",
15
+ "dev": "tsx src/index.ts"
16
+ },
17
+ "dependencies": {
18
+ "@modelcontextprotocol/sdk": "^1.0.4",
19
+ "axios": "^1.7.9",
20
+ "zod": "^4.4.3"
21
+ },
22
+ "devDependencies": {
23
+ "@types/node": "^22.10.2",
24
+ "tsx": "^4.19.2",
25
+ "typescript": "^5.7.2"
26
+ }
27
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "ES2022",
5
+ "moduleResolution": "node",
6
+ "outDir": "./dist",
7
+ "rootDir": "./src",
8
+ "strict": true,
9
+ "esModuleInterop": true,
10
+ "skipLibCheck": true,
11
+ "forceConsistentCasingInFileNames": true,
12
+ "resolveJsonModule": true,
13
+ "declaration": true,
14
+ "declarationMap": true,
15
+ "sourceMap": true
16
+ },
17
+ "include": ["src/**/*"],
18
+ "exclude": ["node_modules", "dist"]
19
+ }