invoice-processor-mcp
Version:
MCP server para procesar facturas en formato Excel
48 lines (40 loc) • 1.26 kB
JavaScript
// Simulación de @mcp/server
import express from 'express';
export class MCPServer {
constructor({ functions, handleRequest }) {
this.functions = functions || [];
this.handleRequest = handleRequest;
this.app = express();
// Configuración básica de Express
this.app.use(express.json());
// Configurar rutas
this.app.post('/api/v1/mcp', async (req, res) => {
try {
const result = await this.processRequest(req.body);
res.json(result);
} catch (error) {
res.status(500).json({ error: error.message });
}
});
}
async processRequest(request) {
// Si hay una llamada a función
if (request.function_call) {
const { name, parameters } = request.function_call;
const func = this.functions.find(f => f.name === name);
if (func) {
return await func.execute(parameters);
} else {
throw new Error(`Función '${name}' no encontrada`);
}
}
// Si es una consulta general
return await this.handleRequest(request);
}
createExpressMiddleware() {
return this.app;
}
listen(port, callback) {
return this.app.listen(port, callback);
}
}