/
iRumba
/
OpenCodeExperiments
Обзор
Документация
Войти
/
iRumba
/
OpenCodeExperiments
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
.opencode/gitverse-mcp-proxy.js
89 строк
2 KB
iRumba
Initial commit: OpenCode configuration
21 май 2026, 06:16
21 май 2026, 06:16
d78f764
Код
Авторство
О чём код?
import { request } from "node:http"; import { env, stdin, stdout } from "node:process"; const GITVERSE_URL = "https://mcp.gitverse.ru"; const TOKEN = env.GITVERSE_TOKEN; if (!TOKEN) { console.error("GITVERSE_TOKEN is not set"); process.exit(1); } let sessionId = null; let buffer = ""; function gitverseRequest(body) { return new Promise((resolve, reject) => { const url = new URL(GITVERSE_URL); const headers = { "Content-Type": "application/json", Accept: "application/json, text/event-stream", Authorization: `Bearer ${TOKEN}`, }; if (sessionId) { headers["Mcp-Session-Id"] = sessionId; } const req = request( { hostname: url.hostname, port: url.port || 443, path: url.pathname || "/", method: "POST", headers: { ...headers, "Content-Length": Buffer.byteLength(body).toString() }, }, (res) => { let data = ""; res.on("data", (chunk) => (data += chunk)); res.on("end", () => { const sid = res.headers["mcp-session-id"]; if (sid) sessionId = sid; try { resolve(JSON.parse(data)); } catch { resolve({ jsonrpc: "2.0", error: { code: -32700, message: "Parse error" } }); } }); } ); req.on("error", (err) => { reject(err); }); req.write(body); req.end(); }); } stdin.on("data", async (chunk) => { buffer += chunk.toString(); const lines = buffer.split("\n"); buffer = lines.pop(); for (const line of lines) { const trimmed = line.trim(); if (!trimmed) continue; let requestBody; try { requestBody = JSON.parse(trimmed); } catch { continue; } try { const response = await gitverseRequest(JSON.stringify(requestBody)); stdout.write(JSON.stringify(response) + "\n"); } catch (err) { const errorResponse = { jsonrpc: "2.0", id: requestBody.id ?? null, error: { code: -32603, message: err.message }, }; stdout.write(JSON.stringify(errorResponse) + "\n"); } } }); stdin.on("end", () => process.exit(0));