61 lines
1.6 KiB
JavaScript
61 lines
1.6 KiB
JavaScript
#!/usr/bin/env bun
|
|
/**
|
|
* mcp-gitea-stdio.cjs
|
|
* MCP Stdio Bridge — wraps @ric_/forgejo-mcp for Kilo Code infrastructure
|
|
*
|
|
* This replaces HTTP↔SSE fallback complexity with direct stdio invocation
|
|
* of the official forgejo-mcp package.
|
|
*
|
|
* Usage: MCP_STDIO_COMMAND="bun scripts/mcp-gitea-stdio.cjs"
|
|
* Or: FORGEJO_TOKEN=xxx bun scripts/mcp-gitea-stdio.cjs
|
|
*/
|
|
|
|
import { spawn } from "child_process"
|
|
|
|
const FORGEJO_TOKEN = process.env.FORGEJO_TOKEN || process.env.GITEA_TOKEN || ""
|
|
const FORGEJO_URL = process.env.FORGEJO_URL || "https://git.softuniq.eu"
|
|
const USE_CONTAINER = process.env.USE_MCP_CONTAINER === "1"
|
|
|
|
let child = null
|
|
|
|
function log(...args) {
|
|
// eslint-disable-next-line no-console
|
|
console.error("[stdio]", ...args)
|
|
}
|
|
|
|
log("Starting forgejo-mcp stdio bridge...")
|
|
|
|
if (!FORGEJO_TOKEN) {
|
|
log("WARNING: FORGEJO_TOKEN not set. MCP tools will fail authentication.")
|
|
}
|
|
|
|
if (USE_CONTAINER) {
|
|
// Spawn Docker container with stdio passthrough
|
|
child = spawn(
|
|
"docker", ["exec", "-i", "mcp-gitea", "node", "dist/index.js"],
|
|
{ env: { ...process.env, FORGEJO_TOKEN, FORGEJO_URL } }
|
|
)
|
|
} else {
|
|
child = spawn(
|
|
"bunx", ["@ric_/forgejo-mcp"],
|
|
{ env: { ...process.env, FORGEJO_URL, FORGEJO_TOKEN, LOG_LEVEL: "warn" } }
|
|
)
|
|
}
|
|
|
|
process.stdin.pipe(child.stdin)
|
|
child.stdout.pipe(process.stdout)
|
|
child.stderr.pipe(process.stderr)
|
|
|
|
child.on("exit", (code) => {
|
|
log("forgejo-mcp exited with code", code)
|
|
process.exit(code || 0)
|
|
})
|
|
|
|
child.on("error", (err) => {
|
|
log("Failed to start forgejo-mcp:", err.message)
|
|
process.exit(1)
|
|
})
|
|
|
|
process.on("SIGTERM", () => child && child.kill("SIGTERM"))
|
|
process.on("SIGINT", () => child && child.kill("SIGINT"))
|