Keep VoidBot MCP alive across deployments
This commit is contained in:
parent
a21d173ec0
commit
03edb8fffc
9 changed files with 120 additions and 12 deletions
50
scripts/serve-voidbot-remote-mcp-relay.mjs
Normal file
50
scripts/serve-voidbot-remote-mcp-relay.mjs
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
#!/usr/bin/env node
|
||||
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
||||
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
|
||||
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
||||
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
||||
import {
|
||||
CallToolRequestSchema,
|
||||
ListToolsRequestSchema,
|
||||
} from "@modelcontextprotocol/sdk/types.js";
|
||||
|
||||
const host = process.env.VOIDBOT_MCP_REMOTE_HOST;
|
||||
const keyPath = process.env.VOIDBOT_MCP_SSH_KEY_PATH;
|
||||
if (!host || !keyPath) {
|
||||
throw new Error("VOIDBOT_MCP_REMOTE_HOST and VOIDBOT_MCP_SSH_KEY_PATH are required.");
|
||||
}
|
||||
|
||||
const server = new Server(
|
||||
{ name: "voidbot-yggdrasil-relay", version: "1.0.0" },
|
||||
{ capabilities: { tools: {} } },
|
||||
);
|
||||
|
||||
server.setRequestHandler(ListToolsRequestSchema, async () =>
|
||||
withRemoteClient((client) => client.listTools()),
|
||||
);
|
||||
|
||||
server.setRequestHandler(CallToolRequestSchema, async (request) =>
|
||||
withRemoteClient((client) => client.callTool(request.params)),
|
||||
);
|
||||
|
||||
async function withRemoteClient(operation) {
|
||||
const transport = new StdioClientTransport({
|
||||
command: process.env.VOIDBOT_MCP_SSH_EXECUTABLE ?? "ssh",
|
||||
args: [
|
||||
"-T", "-i", keyPath, host,
|
||||
"sudo", "docker", "exec", "-i", "compose-worker-1",
|
||||
"node", "/app/apps/worker/dist/mcp-server.js",
|
||||
],
|
||||
env: process.env,
|
||||
stderr: "pipe",
|
||||
});
|
||||
const client = new Client({ name: "voidbot-yggdrasil-relay-upstream", version: "1.0.0" });
|
||||
try {
|
||||
await client.connect(transport);
|
||||
return await operation(client);
|
||||
} finally {
|
||||
await client.close().catch(() => undefined);
|
||||
}
|
||||
}
|
||||
|
||||
await server.connect(new StdioServerTransport());
|
||||
32
scripts/smoke-voidbot-remote-mcp-relay.mjs
Normal file
32
scripts/smoke-voidbot-remote-mcp-relay.mjs
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
||||
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
|
||||
|
||||
const node = process.execPath;
|
||||
const transport = new StdioClientTransport({
|
||||
command: node,
|
||||
args: ["scripts/serve-voidbot-remote-mcp-relay.mjs"],
|
||||
env: process.env,
|
||||
stderr: "inherit",
|
||||
});
|
||||
const client = new Client({ name: "voidbot-remote-relay-smoke", version: "1.0.0" });
|
||||
|
||||
try {
|
||||
await client.connect(transport);
|
||||
const tools = await client.listTools();
|
||||
const repositories = await client.callTool({ name: "list_indexed_repos", arguments: {} });
|
||||
const sources = await client.callTool({
|
||||
name: "search_sources",
|
||||
arguments: { query: "VoidBot indexed source retrieval", repoName: "VoidBot", limit: 1 },
|
||||
});
|
||||
if (repositories.isError || sources.isError) {
|
||||
throw new Error("Remote relay returned an MCP error for indexed-source retrieval.");
|
||||
}
|
||||
process.stdout.write(`${JSON.stringify({
|
||||
ok: true,
|
||||
toolCount: tools.tools.length,
|
||||
repoCount: repositories.structuredContent?.repoCount,
|
||||
sourceResultCount: sources.structuredContent?.resultCount,
|
||||
})}\n`);
|
||||
} finally {
|
||||
await client.close();
|
||||
}
|
||||
|
|
@ -22,18 +22,38 @@ const client = new Client({ name: "voidbot-remote-mcp-smoke", version: "1.0.0" }
|
|||
try {
|
||||
await client.connect(transport);
|
||||
const tools = await client.listTools();
|
||||
if (!tools.tools.some((tool) => tool.name === "search_history")) {
|
||||
throw new Error("Remote VoidBot MCP did not advertise search_history.");
|
||||
for (const requiredTool of ["search_history", "list_indexed_repos", "search_sources"]) {
|
||||
if (!tools.tools.some((tool) => tool.name === requiredTool)) {
|
||||
throw new Error(`Remote VoidBot MCP did not advertise ${requiredTool}.`);
|
||||
}
|
||||
}
|
||||
const result = await client.callTool({
|
||||
const historyResult = await client.callTool({
|
||||
name: "search_history",
|
||||
arguments: { query: "VoidBot deployment Yggdrasil", limit: 2 },
|
||||
});
|
||||
if (result.isError) {
|
||||
const detail = result.content?.map((entry) => entry.type === "text" ? entry.text : entry.type).join(" ");
|
||||
if (historyResult.isError) {
|
||||
const detail = historyResult.content?.map((entry) => entry.type === "text" ? entry.text : entry.type).join(" ");
|
||||
throw new Error(`Remote search_history failed: ${detail || "unknown MCP error"}`);
|
||||
}
|
||||
process.stdout.write(`${JSON.stringify({ ok: true, toolCount: tools.tools.length, result }, null, 2)}\n`);
|
||||
const repositoriesResult = await client.callTool({ name: "list_indexed_repos", arguments: {} });
|
||||
if (repositoriesResult.isError) {
|
||||
throw new Error("Remote list_indexed_repos failed.");
|
||||
}
|
||||
const sourceResult = await client.callTool({
|
||||
name: "search_sources",
|
||||
arguments: { query: "VoidBot indexed source retrieval", limit: 2 },
|
||||
});
|
||||
if (sourceResult.isError) {
|
||||
const detail = sourceResult.content?.map((entry) => entry.type === "text" ? entry.text : entry.type).join(" ");
|
||||
throw new Error(`Remote search_sources failed: ${detail || "unknown MCP error"}`);
|
||||
}
|
||||
process.stdout.write(`${JSON.stringify({
|
||||
ok: true,
|
||||
toolCount: tools.tools.length,
|
||||
historyResult,
|
||||
repositoriesResult,
|
||||
sourceResult,
|
||||
}, null, 2)}\n`);
|
||||
} finally {
|
||||
await client.close();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue