my-openapi-mcp-weather-server 1.0.0 → 1.1.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 CHANGED
@@ -1,11 +1,11 @@
1
- # openapi-mcp-server
1
+ # my-openapi-mcp-weather-server
2
2
 
3
- An MCP (Model Context Protocol) server for OpenAPI specification parsing and interaction.
3
+ An MCP (Model Context Protocol) server for querying weather information via shanhe.kim API.
4
4
 
5
5
  ## Installation
6
6
 
7
7
  ```bash
8
- npm install openapi-mcp-server
8
+ npm install my-openapi-mcp-weather-server
9
9
  ```
10
10
 
11
11
  ## Usage
@@ -13,15 +13,42 @@ npm install openapi-mcp-server
13
13
  Run directly with npx:
14
14
 
15
15
  ```bash
16
- npx openapi-mcp-server
16
+ npx my-openapi-mcp-weather-server
17
17
  ```
18
18
 
19
- ## Features
19
+ ## MCP Tools
20
20
 
21
- - Parse OpenAPI specifications
22
- - Provide API endpoint information via MCP protocol
23
- - Support OpenAPI 3.0+ specifications
21
+ ### `query-weather`
22
+
23
+ 查询指定城市的天气信息。
24
+
25
+ **参数:**
26
+
27
+ | 参数 | 类型 | 必填 | 说明 |
28
+ |------|------|------|------|
29
+ | city | string | 是 | 城市名,如:成都、北京、上海 |
30
+ | type | string | 否 | 返回格式,json 或 text,默认 json |
31
+
32
+ **返回信息包括:**
33
+
34
+ - 当前天气、温度、湿度、风力、能见度
35
+ - 空气质量(AQI、PM2.5)
36
+ - 今日天气预报(最高/最低温、天气状况)
37
+ - 30 项生活指数(穿衣、紫外线、感冒、运动等)
38
+
39
+ ## Example
40
+
41
+ 在 MCP 客户端中调用:
42
+
43
+ ```json
44
+ {
45
+ "tool": "query-weather",
46
+ "arguments": {
47
+ "city": "成都"
48
+ }
49
+ }
50
+ ```
24
51
 
25
52
  ## License
26
53
 
27
- MIT
54
+ MIT
package/dist/index.js CHANGED
@@ -4,78 +4,64 @@ Object.defineProperty(exports, "__esModule", { value: true });
4
4
  const mcp_js_1 = require("@modelcontextprotocol/sdk/server/mcp.js");
5
5
  const stdio_js_1 = require("@modelcontextprotocol/sdk/server/stdio.js");
6
6
  const zod_1 = require("zod");
7
+ const WEATHER_API_BASE = "https://api.shanhe.kim/API/天气.php";
7
8
  const server = new mcp_js_1.McpServer({
8
- name: "openapi-mcp-server",
9
- version: "1.0.0",
9
+ name: "my-openapi-mcp-weather-server",
10
+ version: "1.1.0",
10
11
  });
11
- server.tool("parse-openapi", "Parse an OpenAPI specification and return its structure", {
12
- specUrl: zod_1.z.string().url().describe("URL of the OpenAPI specification JSON/YAML file"),
13
- }, async ({ specUrl }) => {
12
+ server.tool("query-weather", "查询指定城市的天气信息,包括当前天气、温度、风力、湿度、空气质量及生活指数等", {
13
+ city: zod_1.z.string().describe("城市名,如:成都、北京、上海"),
14
+ type: zod_1.z.enum(["json", "text"]).optional().describe("返回格式,json text,默认 json"),
15
+ }, async ({ city, type }) => {
14
16
  try {
15
- const response = await fetch(specUrl);
16
- const contentType = response.headers.get("content-type") || "";
17
- let spec;
18
- if (contentType.includes("yaml") || specUrl.endsWith(".yaml") || specUrl.endsWith(".yml")) {
19
- const text = await response.text();
17
+ const params = new URLSearchParams({ city });
18
+ if (type)
19
+ params.set("type", type);
20
+ const url = `${WEATHER_API_BASE}?${params.toString()}`;
21
+ const response = await fetch(url);
22
+ if (!response.ok) {
23
+ const statusMessages = {
24
+ 403: "服务器拒绝请求,可能缺少 API 密钥或权限不足",
25
+ 404: "请求的资源未找到,请检查请求地址是否正确",
26
+ 429: "请求过于频繁,已超出速率限制,请稍后再试",
27
+ 500: "服务器内部错误,执行请求时遇到问题",
28
+ };
29
+ const msg = statusMessages[response.status] || `HTTP ${response.status}`;
20
30
  return {
21
- content: [
22
- {
23
- type: "text",
24
- text: `YAML parsing not yet supported. Please provide a JSON spec. Raw content length: ${text.length}`,
25
- },
26
- ],
31
+ content: [{ type: "text", text: `请求失败: ${msg}` }],
32
+ isError: true,
27
33
  };
28
34
  }
29
- spec = await response.json();
30
- const info = spec.info;
31
- const paths = spec.paths;
32
- const pathCount = paths ? Object.keys(paths).length : 0;
33
- const summary = [
34
- `OpenAPI Specification:`,
35
- ` Title: ${info?.title || "Unknown"}`,
36
- ` Version: ${info?.version || "Unknown"}`,
37
- ` Paths: ${pathCount}`,
38
- ` Endpoints:`,
39
- ...Object.keys(paths || {}).map((p) => ` ${p}`),
40
- ].join("\n");
41
- return {
42
- content: [{ type: "text", text: summary }],
43
- };
44
- }
45
- catch (error) {
46
- return {
47
- content: [
48
- {
49
- type: "text",
50
- text: `Error parsing OpenAPI spec: ${error instanceof Error ? error.message : String(error)}`,
51
- },
52
- ],
53
- };
54
- }
55
- });
56
- server.tool("list-endpoints", "List all API endpoints from an OpenAPI specification", {
57
- specUrl: zod_1.z.string().url().describe("URL of the OpenAPI specification JSON file"),
58
- }, async ({ specUrl }) => {
59
- try {
60
- const response = await fetch(specUrl);
61
- const spec = (await response.json());
62
- const paths = spec.paths;
63
- if (!paths) {
35
+ const data = (await response.json());
36
+ if (data.code !== 200) {
64
37
  return {
65
- content: [{ type: "text", text: "No paths found in the specification." }],
38
+ content: [{ type: "text", text: `查询失败: ${data.msg}` }],
39
+ isError: true,
66
40
  };
67
41
  }
68
- const endpoints = [];
69
- for (const [path, methods] of Object.entries(paths)) {
70
- for (const method of Object.keys(methods)) {
71
- const detail = methods[method];
72
- const opId = detail.operationId || "";
73
- const summary = detail.summary || "";
74
- endpoints.push(`${method.toUpperCase().padEnd(7)} ${path}${opId ? ` (${opId})` : ""}${summary ? ` - ${summary}` : ""}`);
75
- }
76
- }
42
+ const d = data.data;
43
+ const c = d.current;
44
+ const lines = [
45
+ `🏙️ 城市: ${d.city} (${d.cityEnglish})`,
46
+ `📅 日期: ${c.date} ${c.time}`,
47
+ ``,
48
+ `🌡️ 今日天气: ${d.weather}`,
49
+ ` 最高温: ${d.temp}°C 最低温: ${d.tempn}°C`,
50
+ ` 风力: ${d.wind} ${d.windSpeed}`,
51
+ ``,
52
+ `🌤️ 当前实况:`,
53
+ ` 天气: ${c.weather} (${c.weatherEnglish})`,
54
+ ` 温度: ${c.temp}°C / ${c.fahrenheit}°F`,
55
+ ` 湿度: ${c.humidity}`,
56
+ ` 风向: ${c.wind} ${c.windSpeed}`,
57
+ ` 能见度: ${c.visibility}`,
58
+ ` 空气质量: AQI ${c.air} PM2.5 ${c.air_pm25}`,
59
+ ``,
60
+ `📋 生活指数:`,
61
+ ...d.living.map((l) => ` ${l.name}: ${l.index} - ${l.tips}`),
62
+ ];
77
63
  return {
78
- content: [{ type: "text", text: endpoints.join("\n") || "No endpoints found." }],
64
+ content: [{ type: "text", text: lines.join("\n") }],
79
65
  };
80
66
  }
81
67
  catch (error) {
@@ -83,9 +69,10 @@ server.tool("list-endpoints", "List all API endpoints from an OpenAPI specificat
83
69
  content: [
84
70
  {
85
71
  type: "text",
86
- text: `Error listing endpoints: ${error instanceof Error ? error.message : String(error)}`,
72
+ text: `查询天气时出错: ${error instanceof Error ? error.message : String(error)}`,
87
73
  },
88
74
  ],
75
+ isError: true,
89
76
  };
90
77
  }
91
78
  });
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAEA,oEAAoE;AACpE,wEAAiF;AACjF,6BAAwB;AAExB,MAAM,MAAM,GAAG,IAAI,kBAAS,CAAC;IAC3B,IAAI,EAAE,oBAAoB;IAC1B,OAAO,EAAE,OAAO;CACjB,CAAC,CAAC;AAEH,MAAM,CAAC,IAAI,CACT,eAAe,EACf,yDAAyD,EACzD;IACE,OAAO,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,iDAAiD,CAAC;CACtF,EACD,KAAK,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE;IACpB,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,OAAO,CAAC,CAAC;QACtC,MAAM,WAAW,GAAG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I,EAAE,MAAe,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;SAC7D,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO;YACL,OAAO,EAAE;gBACP;oBACE,IAAI,EAAE,MAAe;oBACrB,IAAI,EAAE,YAAY,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;iBAC3E;aACF;YACD,OAAO,EAAE,IAAI;SACd,CAAC;IACJ,CAAC;AACH,CAAC,CACF,CAAC;AAEF,KAAK,UAAU,IAAI;IACjB,MAAM,SAAS,GAAG,IAAI,+BAAoB,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,wBAAwB,EAAE,KAAK,CAAC,CAAC;IAC/C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "my-openapi-mcp-weather-server",
3
- "version": "1.0.0",
4
- "description": "An MCP server for OpenAPI specification parsing and interaction",
3
+ "version": "1.1.0",
4
+ "description": "An MCP server for querying weather information via shanhe.kim API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "bin": {
@@ -22,8 +22,9 @@
22
22
  },
23
23
  "keywords": [
24
24
  "mcp",
25
- "openapi",
26
- "server"
25
+ "weather",
26
+ "server",
27
+ "shanhe"
27
28
  ],
28
29
  "license": "MIT",
29
30
  "dependencies": {