Skip to main content
Glama

Canteen MCP

by c0dr
server.ts1.86 kB
import axios from "axios"; import dotenv from "dotenv"; import { FastMCP } from "fastmcp"; import { z } from "zod"; // Load environment variables dotenv.config(); // Function to create and configure server export function createServer(): FastMCP { // Validate environment before creating server validateEnvironment(); return new FastMCP({ name: "Breuni Kantine Helper", version: "1.0.0", }); } // Function to validate environment variables export function validateEnvironment(): void { const requiredEnvVars = ['API_URL', 'PORT', 'ENDPOINT']; for (const envVar of requiredEnvVars) { if (!process.env[envVar] || process.env[envVar].trim() === '') { throw new Error(`Missing required environment variable: ${envVar}`); } } } // Create the server instance export const server = createServer(); // Function to configure and start the server export function initializeServer(): void { server.addTool({ annotations: { openWorldHint: true, // This tool interacts with external API readOnlyHint: true, // This tool doesn't modify anything title: "Lunch Menu", }, description: "Get the lunch menu from the canteen for a specific date", execute: async (args) => { try { const response = await axios.get(process.env.API_URL!, { params: { date: args.date } }); return JSON.stringify(response.data, null, 2); } catch (error) { if (axios.isAxiosError(error)) { throw new Error(`Failed to fetch menu: ${error.message}`); } throw error; } }, name: "get_lunch_menu", parameters: z.object({ date: z.string().date(), }), }); server.start({ sse: { endpoint: process.env.ENDPOINT as `/${string}`, port: parseInt(process.env.PORT!, 10), }, transportType: "sse", }); }

Latest Blog Posts

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/c0dr/canteen-mcp'

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