@lemili9804/mcp-weather-server 1.0.2 → 1.0.4
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/build/index.js +53 -4
- package/package.json +1 -1
package/build/index.js
CHANGED
|
@@ -35,10 +35,7 @@ function formatAlert(feature) {
|
|
|
35
35
|
].join("\n");
|
|
36
36
|
}
|
|
37
37
|
// Create server instance
|
|
38
|
-
const server = new McpServer({
|
|
39
|
-
name: "weather",
|
|
40
|
-
version: "1.0.0",
|
|
41
|
-
});
|
|
38
|
+
const server = new McpServer({ name: "weather", version: "1.0.0" }, { capabilities: { tools: { listChanged: true } } });
|
|
42
39
|
// Register weather tools
|
|
43
40
|
server.registerTool("get-alerts", {
|
|
44
41
|
title: "Get Weather Alerts",
|
|
@@ -159,6 +156,58 @@ server.registerTool("get-forecast", {
|
|
|
159
156
|
],
|
|
160
157
|
};
|
|
161
158
|
});
|
|
159
|
+
let airQualityEnabled = false;
|
|
160
|
+
server.registerTool("enable-air-quality", {
|
|
161
|
+
title: "Enable Air Quality Tool",
|
|
162
|
+
description: "Dynamically registers the get-air-quality tool",
|
|
163
|
+
inputSchema: {},
|
|
164
|
+
}, async () => {
|
|
165
|
+
if (airQualityEnabled) {
|
|
166
|
+
return {
|
|
167
|
+
content: [{ type: "text", text: "Air quality tool is already enabled." }],
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
server.registerTool("get-air-quality", {
|
|
171
|
+
title: "Get Air Quality",
|
|
172
|
+
description: "Get current air quality index and pollutant levels for a location",
|
|
173
|
+
inputSchema: {
|
|
174
|
+
latitude: z.number().min(-90).max(90).describe("Latitude of the location"),
|
|
175
|
+
longitude: z.number().min(-180).max(180).describe("Longitude of the location"),
|
|
176
|
+
},
|
|
177
|
+
}, async ({ latitude, longitude }) => {
|
|
178
|
+
const url = `https://air-quality-api.open-meteo.com/v1/air-quality?latitude=${latitude}&longitude=${longitude}` +
|
|
179
|
+
`&hourly=pm2_5,pm10,european_aqi&forecast_days=1`;
|
|
180
|
+
const data = await makeNWSRequest(url);
|
|
181
|
+
if (!data) {
|
|
182
|
+
return {
|
|
183
|
+
isError: true,
|
|
184
|
+
content: [{ type: "text", text: "Failed to retrieve air quality data." }],
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
const now = new Date();
|
|
188
|
+
const currentHour = now.toISOString().slice(0, 13);
|
|
189
|
+
const idx = data.hourly.time.findIndex((t) => t.startsWith(currentHour));
|
|
190
|
+
const i = idx >= 0 ? idx : 0;
|
|
191
|
+
return {
|
|
192
|
+
content: [
|
|
193
|
+
{
|
|
194
|
+
type: "text",
|
|
195
|
+
text: [
|
|
196
|
+
`Air quality for ${latitude}, ${longitude} at ${data.hourly.time[i]}:`,
|
|
197
|
+
`European AQI: ${data.hourly.european_aqi[i]}`,
|
|
198
|
+
`PM2.5: ${data.hourly.pm2_5[i]} μg/m³`,
|
|
199
|
+
`PM10: ${data.hourly.pm10[i]} μg/m³`,
|
|
200
|
+
].join("\n"),
|
|
201
|
+
},
|
|
202
|
+
],
|
|
203
|
+
};
|
|
204
|
+
});
|
|
205
|
+
airQualityEnabled = true;
|
|
206
|
+
await server.sendToolListChanged();
|
|
207
|
+
return {
|
|
208
|
+
content: [{ type: "text", text: "Air quality tool enabled. Tool list updated." }],
|
|
209
|
+
};
|
|
210
|
+
});
|
|
162
211
|
// Start the server
|
|
163
212
|
async function main() {
|
|
164
213
|
const transport = new StdioServerTransport();
|