Skip to main content
Glama
server.ts1.22 kB
import { createMcpHandler } from "mcp-handler"; import { z } from "zod"; const handler = createMcpHandler((server) => { server.tool( "roll_dice", "Rolls an N-sided die", { sides: z.number().int().min(2) }, async ({ sides }) => { const value = 1 + Math.floor(Math.random() * sides); return { content: [{ type: "text", text: `🎲 You rolled a ${value}!` }], }; }, ); server.tool( "get_weather", "Get the current weather at a location", { latitude: z.number(), longitude: z.number(), city: z.string(), }, async ({ latitude, longitude, city }) => { const response = await fetch( `https://api.open-meteo.com/v1/forecast?latitude=${latitude}&longitude=${longitude}&current=temperature_2m,weathercode,relativehumidity_2m&timezone=auto`, ); const weatherData = await response.json(); return { content: [ { type: "text", text: `🌤️ Weather in ${city}: ${weatherData.current.temperature_2m}°C, Humidity: ${weatherData.current.relativehumidity_2m}%`, }, ], }; }, ); }); export { handler as GET, handler as POST, handler as DELETE };

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/usephedm/model-context-protocol-mcp-with-vercel-functions'

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