Skip to main content
Glama

Demo MCP Server

by kylekanouse
index.tsโ€ข3.39 kB
#!/usr/bin/env node /** * Demo MCP Server - Main Entry Point * * A comprehensive boilerplate MCP server built with TypeScript using * Domain-Driven Design patterns and dynamic component loading. */ import { MyMCPServer } from "./server/index.js"; import type { MCPServerConfig } from "./types/index.js"; /** * Server configuration */ const serverConfig: MCPServerConfig = { name: "demo-mcp-server", version: "1.0.0", capabilities: { tools: true, resources: true, prompts: true, logging: true } }; /** * Initialize and start the MCP server */ async function main(): Promise<void> { console.log("๐Ÿš€ Starting Demo MCP Server..."); console.log(`๐Ÿ“‹ Server: ${serverConfig.name} v${serverConfig.version}`); let server: MyMCPServer | null = null; try { // Create server instance server = new MyMCPServer(serverConfig); // Initialize the server and register all components console.log("๐Ÿ”ง Initializing server..."); await server.initialize(); // Connect to transport console.log("๐Ÿ”Œ Connecting to transport..."); await server.connect(); // Log server status const status = server.getStatus(); console.log("โœ… Server started successfully!"); console.log(`๐Ÿ“Š Status: ${JSON.stringify({ initialized: status.initialized, connected: status.connected, loadedModules: status.loadedModules.length }, null, 2)}`); console.log("๐Ÿ“ก Demo MCP Server is running on stdio"); console.log("๐ŸŽฏ Ready to handle MCP requests..."); // Setup graceful shutdown setupGracefulShutdown(server); } catch (error) { console.error("โŒ Fatal error starting server:", error); if (server) { try { await server.shutdown(); } catch (shutdownError) { console.error("โŒ Error during emergency shutdown:", shutdownError); } } process.exit(1); } } /** * Setup graceful shutdown handlers */ function setupGracefulShutdown(server: MyMCPServer): void { const shutdown = async (signal: string) => { console.log(`\n๐Ÿ›‘ Received ${signal}, shutting down gracefully...`); try { await server.shutdown(); console.log("โœ… Server shutdown completed"); process.exit(0); } catch (error) { console.error("โŒ Error during shutdown:", error); process.exit(1); } }; // Handle various shutdown signals process.on("SIGINT", () => shutdown("SIGINT")); process.on("SIGTERM", () => shutdown("SIGTERM")); process.on("SIGQUIT", () => shutdown("SIGQUIT")); // Handle uncaught exceptions process.on("uncaughtException", async (error) => { console.error("โŒ Uncaught exception:", error); try { await server.shutdown(); } catch (shutdownError) { console.error("โŒ Error during emergency shutdown:", shutdownError); } process.exit(1); }); // Handle unhandled promise rejections process.on("unhandledRejection", async (reason, promise) => { console.error("โŒ Unhandled rejection at:", promise, "reason:", reason); try { await server.shutdown(); } catch (shutdownError) { console.error("โŒ Error during emergency shutdown:", shutdownError); } process.exit(1); }); } /** * Start the server */ main().catch((error) => { console.error("โŒ Fatal error in main():", error); process.exit(1); });

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/kylekanouse/Test-MCP---DEMO-MCP-Dev-1'

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