UNPKG

@mseep/supabase-mcp

Version:

MCP server for Supabase CRUD operations

82 lines 2.52 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.handleJsonRpc = void 0; const mcp_js_1 = require("../services/mcp.js"); /** * Handle JSON-RPC requests for the Model Context Protocol */ const handleJsonRpc = async (req, res) => { try { // Parse the JSON-RPC request const jsonRpcRequest = req.body; if (!jsonRpcRequest || !jsonRpcRequest.method) { return res.status(400).json({ jsonrpc: '2.0', id: null, error: { code: -32600, message: 'Invalid Request' } }); } // Handle initialization if (jsonRpcRequest.method === 'initialize') { // Just acknowledge the initialization return res.status(200).json({ jsonrpc: '2.0', id: jsonRpcRequest.id, result: { capabilities: { tools: true } } }); } // Handle tool calls if (jsonRpcRequest.method === 'tools/invoke') { const { name, parameters } = jsonRpcRequest.params; const result = await mcp_js_1.mcpService.handleToolCall({ name, parameters }); if (result.error) { return res.status(200).json({ jsonrpc: '2.0', id: jsonRpcRequest.id, error: { code: -32000, message: result.error } }); } return res.status(200).json({ jsonrpc: '2.0', id: jsonRpcRequest.id, result: result.content }); } // Unknown method return res.status(200).json({ jsonrpc: '2.0', id: jsonRpcRequest.id, error: { code: -32601, message: 'Method not found' } }); } catch (error) { console.error('JSON-RPC handler error:', error); return res.status(200).json({ jsonrpc: '2.0', id: null, error: { code: -32603, message: 'Internal error', data: error.message } }); } }; exports.handleJsonRpc = handleJsonRpc; //# sourceMappingURL=mcp-rpc.js.map