Skip to main content
Glama
yone-k

MCP Base Server

by yone-k
index.ts2.05 kB
#!/usr/bin/env node import { Server } from '@modelcontextprotocol/sdk/server/index.js'; import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'; import { ListToolsRequestSchema, CallToolRequestSchema, ErrorCode, McpError, } from '@modelcontextprotocol/sdk/types.js'; import { registeredTools } from './tools/registry.js'; import { ToolHandler } from './core/tool-handler.js'; class BaseMCPServer { private server: Server; private toolHandler: ToolHandler; constructor() { this.server = new Server({ name: 'mcp-base', version: '1.0.0', }); this.toolHandler = new ToolHandler(); this.setupHandlers(); this.setupErrorHandling(); } private setupHandlers(): void { this.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: registeredTools, }; }); this.server.setRequestHandler(CallToolRequestSchema, async (request) => { const { name, arguments: args } = request.params; try { return await this.toolHandler.executeTool(name, args); } catch (error) { if (error instanceof McpError) { throw error; } throw new McpError( ErrorCode.InternalError, `Tool execution failed: ${error instanceof Error ? error.message : String(error)}` ); } }); } private setupErrorHandling(): void { this.server.onerror = (error) => { console.error('[MCP Error]', error); }; process.on('SIGINT', async () => { await this.server.close(); process.exit(0); }); } async run(): Promise<void> { const transport = new StdioServerTransport(); await this.server.connect(transport); console.error('Base MCP Server started'); } } async function main(): Promise<void> { const server = new BaseMCPServer(); await server.run(); } if (import.meta.url === `file://${process.argv[1]}`) { main().catch((error) => { console.error('Fatal error:', error); process.exit(1); }); }

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/yone-k/mcp-base'

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