weather-mcp-server 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/index.js +55 -0
- package/package.json +19 -0
package/index.js
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
#!/usr/bin/env node
|
2
|
+
|
3
|
+
const { spawn } = require('child_process');
|
4
|
+
const path = require('path');
|
5
|
+
const fs = require('fs');
|
6
|
+
|
7
|
+
// 验证API密钥
|
8
|
+
const apiKey = process.env.WEATHER_API_KEY;
|
9
|
+
if (!apiKey) {
|
10
|
+
console.error('Error: WEATHER_API_KEY environment variable is required');
|
11
|
+
process.exit(1);
|
12
|
+
}
|
13
|
+
|
14
|
+
// 找到JAR文件路径
|
15
|
+
const jarPath = path.join(__dirname, 'lib', 'weather-service.jar');
|
16
|
+
|
17
|
+
if (!fs.existsSync(jarPath)) {
|
18
|
+
console.error(
|
19
|
+
Error: JAR file not found at ${jarPath}
|
20
|
+
);
|
21
|
+
process.exit(1);
|
22
|
+
}
|
23
|
+
|
24
|
+
// 启动Java服务
|
25
|
+
const java = spawn('java', [
|
26
|
+
'-jar',
|
27
|
+
jarPath,
|
28
|
+
--
|
29
|
+
weather.api.key=${apiKey}
|
30
|
+
]);
|
31
|
+
|
32
|
+
// 处理输出
|
33
|
+
java.stdout.on('data', (data) => {
|
34
|
+
console.log(${data}
|
35
|
+
);
|
36
|
+
});
|
37
|
+
|
38
|
+
java.stderr.on('data', (data) => {
|
39
|
+
console.error(${data}
|
40
|
+
);
|
41
|
+
});
|
42
|
+
|
43
|
+
java.on('close', (code) => {
|
44
|
+
console.log(Weather service exited with code ${code}
|
45
|
+
);
|
46
|
+
});
|
47
|
+
|
48
|
+
// 处理进程终止信号
|
49
|
+
process.on('SIGINT', () => {
|
50
|
+
java.kill('SIGINT');
|
51
|
+
});
|
52
|
+
|
53
|
+
process.on('SIGTERM', () => {
|
54
|
+
java.kill('SIGTERM');
|
55
|
+
});
|
package/package.json
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
{
|
2
|
+
"name": "weather-mcp-server",
|
3
|
+
"version": "1.0.0",
|
4
|
+
"description": "Weather MCP Server",
|
5
|
+
"main": "index.js",
|
6
|
+
"bin": {
|
7
|
+
"weather-mcp-server": "./index.js"
|
8
|
+
},
|
9
|
+
"files": [
|
10
|
+
"index.js",
|
11
|
+
"lib/weather-service.jar"
|
12
|
+
],
|
13
|
+
"scripts": {
|
14
|
+
"start": "node index.js"
|
15
|
+
},
|
16
|
+
"keywords": ["mcp", "weather", "server"],
|
17
|
+
"author": "Your Name",
|
18
|
+
"license": "MIT"
|
19
|
+
}
|