#!/usr/bin/env node /** * MCP Bridge Server for Claude Code * Bridges stdio MCP protocol to HTTP endpoints */ const BACKEND_URL = process.env.BACKEND_URL || 'https://api.fuq.tv' const MCP_ENDPOINT = `${BACKEND_URL}/api/mcp` // Read from stdin line by line const readline = require('readline') const rl = readline.createInterface({ input: process.stdin, output: process.stdout, terminal: false, }) // Handle MCP requests rl.on('line', async (line) => { try { const request = JSON.parse(line) // Handle tool calls if (request.method === 'tools/call') { const { name, arguments: args } = request.params // Map to HTTP endpoint const endpoint = `${MCP_ENDPOINT}/${name}` const response = await fetch(endpoint, { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify(args), }) const data = await response.json() // Send MCP response console.log(JSON.stringify({ jsonrpc: '2.0', id: request.id, result: { content: [ { type: 'text', text: JSON.stringify(data, null, 2), }, ], }, })) } // Handle tools list if (request.method === 'tools/list') { const response = await fetch(`${MCP_ENDPOINT}/tools`) const data = await response.json() console.log(JSON.stringify({ jsonrpc: '2.0', id: request.id, result: { tools: data.tools.map((tool) => ({ name: tool.name, description: tool.description, inputSchema: { type: 'object', properties: tool.params || {}, }, })), }, })) } // Handle initialize if (request.method === 'initialize') { console.log(JSON.stringify({ jsonrpc: '2.0', id: request.id, result: { protocolVersion: '2024-11-05', capabilities: { tools: {}, }, serverInfo: { name: 'aiworker-mcp-bridge', version: '1.0.0', }, }, })) } } catch (error) { console.error('MCP Bridge Error:', error) } }) process.stdin.on('end', () => { process.exit(0) })