Add MCP bridge server for Claude Code integration
All checks were successful
Build and Push Agent / build (push) Successful in 4s
All checks were successful
Build and Push Agent / build (push) Successful in 4s
- 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>
This commit is contained in:
11
claude-code-config.json
Normal file
11
claude-code-config.json
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"mcpServers": {
|
||||||
|
"aiworker": {
|
||||||
|
"command": "node",
|
||||||
|
"args": ["/workspace/mcp-bridge-server.js"],
|
||||||
|
"env": {
|
||||||
|
"BACKEND_URL": "https://api.fuq.tv"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
101
mcp-bridge-server.js
Normal file
101
mcp-bridge-server.js
Normal file
@@ -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)
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user