#!/usr/bin/env node import { Server } from '@modelcontextprotocol/sdk/server/index.js'; import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'; import { CallToolRequestSchema, ListToolsRequestSchema, ListResourcesRequestSchema, ReadResourceRequestSchema, } from '@modelcontextprotocol/sdk/types.js'; import { productTools } from './tools/products.js'; import { orderTools } from './tools/orders.js'; import { fiadoTools } from './tools/fiado.js'; import { customerTools } from './tools/customers.js'; import { inventoryTools } from './tools/inventory.js'; const BACKEND_URL = process.env.BACKEND_URL || 'http://localhost:3141'; // Create server instance const server = new Server({ name: 'michangarrito-mcp', version: '1.0.0', }, { capabilities: { tools: {}, resources: {}, }, }); // Combine all tools const allTools = [ ...productTools, ...orderTools, ...fiadoTools, ...customerTools, ...inventoryTools, ]; // List available tools server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: allTools.map((tool) => ({ name: tool.name, description: tool.description, inputSchema: tool.inputSchema, })), })); // Handle tool calls server.setRequestHandler(CallToolRequestSchema, async (request) => { const { name, arguments: args } = request.params; const tool = allTools.find((t) => t.name === name); if (!tool) { return { content: [{ type: 'text', text: `Tool not found: ${name}` }], isError: true, }; } try { const result = await tool.handler(args || {}, BACKEND_URL); return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }], }; } catch (error) { const message = error instanceof Error ? error.message : 'Unknown error'; return { content: [{ type: 'text', text: `Error: ${message}` }], isError: true, }; } }); // List resources server.setRequestHandler(ListResourcesRequestSchema, async () => ({ resources: [ { uri: 'michangarrito://config/business', name: 'Business Configuration', description: 'Current business settings and configuration', mimeType: 'application/json', }, { uri: 'michangarrito://catalog/categories', name: 'Product Categories', description: 'List of product categories', mimeType: 'application/json', }, ], })); // Read resources server.setRequestHandler(ReadResourceRequestSchema, async (request) => { const { uri } = request.params; switch (uri) { case 'michangarrito://config/business': return { contents: [ { uri, mimeType: 'application/json', text: JSON.stringify({ name: 'MiChangarrito', currency: 'MXN', timezone: 'America/Mexico_City', fiadoEnabled: true, maxFiadoAmount: 500, workingHours: { open: '07:00', close: '22:00', }, }), }, ], }; case 'michangarrito://catalog/categories': return { contents: [ { uri, mimeType: 'application/json', text: JSON.stringify([ { id: 'bebidas', name: 'Bebidas', icon: '🥤' }, { id: 'botanas', name: 'Botanas', icon: '🍿' }, { id: 'abarrotes', name: 'Abarrotes', icon: '🛒' }, { id: 'lacteos', name: 'Lácteos', icon: '🥛' }, { id: 'panaderia', name: 'Panadería', icon: '🍞' }, { id: 'limpieza', name: 'Limpieza', icon: '🧹' }, ]), }, ], }; default: throw new Error(`Resource not found: ${uri}`); } }); // Start server async function main() { const transport = new StdioServerTransport(); await server.connect(transport); console.error('MiChangarrito MCP Server running on stdio'); } main().catch(console.error); //# sourceMappingURL=index.js.map