diff --git a/claude-code-config.json b/claude-code-config.json new file mode 100644 index 0000000..b50d543 --- /dev/null +++ b/claude-code-config.json @@ -0,0 +1,11 @@ +{ + "mcpServers": { + "aiworker": { + "command": "node", + "args": ["/workspace/mcp-bridge-server.js"], + "env": { + "BACKEND_URL": "https://api.fuq.tv" + } + } + } +} diff --git a/mcp-bridge-server.js b/mcp-bridge-server.js new file mode 100644 index 0000000..cdea13f --- /dev/null +++ b/mcp-bridge-server.js @@ -0,0 +1,101 @@ +#!/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) +})