Files
aiworker-agent/mcp-bridge-server.js
Hector Ros 7ea10571c4
All checks were successful
Build and Push Agent / build (push) Successful in 4s
Add MCP bridge server for Claude Code integration
- MCP bridge: stdio protocol <-> HTTP endpoints
- Config file for Claude Code with aiworker MCP server
- Maps Claude MCP calls to /api/mcp/* endpoints
- To install: copy to /root/.config/claude/config.json in pod

Co-Authored-By: Claude Sonnet 4.5 (1M context) <noreply@anthropic.com>
2026-01-20 02:24:48 +01:00

102 lines
2.3 KiB
JavaScript

#!/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)
})