Skip to main content
Glama
main.ts1.57 kB
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; import { z } from "zod"; import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"; const server = new McpServer({ name: "mcpWeather", version: "0.0.1", }); server.registerTool( 'fetch-weather', { title: "Fetch Weather", description: "Fetches the current weather for a given location.", inputSchema: z.object({ city: z.string().describe("city name"), }), }, async ({ city }) => { const response = await fetch(`https://geocoding-api.open-meteo.com/v1/search?name=${city}&count=10&language=en&format=json`); const data = await response.json(); if (!data.results || data.results.length === 0) { return { content:[ { type: 'text', text: `Could not find city: ${city}.`, } ] } } const { latitude, longitude } = data.results[0]; const weatherResponse = await fetch(`https://api.open-meteo.com/v1/forecast?latitude=${latitude}&longitude=${longitude}&current_weather=true`); const weatherData = await weatherResponse.json(); return { content: [ { type: 'text', text: JSON.stringify(weatherData, null, 2), } ], }; } ); const transport = new StdioServerTransport(); await server.connect(transport);

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/acenaga/mcpWeather'

If you have feedback or need assistance with the MCP directory API, please join our Discord server