Skip to content

Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.

1.6 KB
Raw Blame
#!/usr/bin/env node

/**
 * stdio -> streamable-HTTP MCP proxy for the OpenViking Agent Plugins 1.0 package.
 *
 * A conforming Agent Plugins client starts this process as a local stdio MCP
 * server (see ../mcp.json). The proxy reads the same OpenViking credential
 * sources as the ov CLI (OPENVIKING_* env → ~/.openviking/ovcli.conf →
 * ~/.openviking/ov.conf), forwards JSON-RPC requests to the server's /mcp
 * endpoint, and keeps stdout protocol-clean.
 *
 * The modules under ./shared/ are generated by `node
 * examples/memory-plugin-shared/sync.mjs` (this directory is one of its
 * TARGETS) — edit them in examples/memory-plugin-shared/lib, never here.
 */

import { realpathSync } from "node:fs";
import { resolve as resolvePath } from "node:path";
import { fileURLToPath } from "node:url";
import { buildProxyConnection } from "./shared/credentials.mjs";
import { createLogger } from "./shared/debug-log.mjs";
import { toMcpProxyConfig } from "./shared/mcp-proxy-config.mjs";
import { createOpenVikingMcpProxy } from "./shared/mcp-proxy-core.mjs";

export function readProxyConfig(env = process.env) {
  const cfg = buildProxyConnection("agent-plugins", {
    env,
    manifestUrl: new URL("../plugin.json", import.meta.url),
  });
  return toMcpProxyConfig(cfg, { env });
}

function isDirectRun() {
  if (!process.argv[1]) return false;
  try {
    return realpathSync(process.argv[1]) === realpathSync(fileURLToPath(import.meta.url));
  } catch {
    return resolvePath(process.argv[1]) === fileURLToPath(import.meta.url);
  }
}

if (isDirectRun()) {
  createOpenVikingMcpProxy({ readConfig: readProxyConfig, loggerFactory: createLogger }).start();
}