Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.
Python agent-contextagent-memoryagent-pluginsagentic-ragcontext-databasedsh-pluginknowledge-basememorymemory-managementself-evolvingvector-database
feat(memory-plugin): support OPENVIKING_EXTRA_HEADERS for private gateways (#5065)
yorick87ae94031b95
diff --git a/agent-plugins/servers/shared/mcp-proxy-config.mjs b/agent-plugins/servers/shared/mcp-proxy-config.mjsindex dd11897ee..c1e527967 100644--- a/agent-plugins/servers/shared/mcp-proxy-config.mjs+++ b/agent-plugins/servers/shared/mcp-proxy-config.mjs@@ -79,6 +79,67 @@ function uniq(values) {return [...new Set(values.filter(Boolean))];}+/**+ * Parse `OPENVIKING_EXTRA_HEADERS` into a plain string→string map.+ *+ * Some private deployments sit behind gateways that require custom headers+ * (a tenant/vault name, a signed token, a region hint) on every request. The+ * proxy has no other seam to inject those: the credential file's own+ * `extra_headers` field is intentionally not exported to MCP callers (see+ * `workspace-config.mjs` `FORBIDDEN_KEYS`), so this env-only escape hatch keeps+ * that boundary while letting an operator unblock a strict upstream.+ *+ * The value is a JSON object; anything else is ignored with a stderr warning+ * rather than crashing the proxy — a bad env var must not take down the whole+ * memory tool surface. Reserved names (`Content-Type`, `Accept`,+ * `MCP-Protocol-Version`, `Mcp-Session-Id`, `Authorization`) are dropped: they+ * are set by the proxy itself and letting the env override them would break+ * session negotiation or expose the wrong credential.+ */+const RESERVED_HEADER_NAMES = new Set([+ "content-type",+ "accept",+ "mcp-protocol-version",+ "mcp-session-id",+ "authorization",+]);++export function parseExtraHeaders(raw, { onWarn = null } = {}) {+ const source = String(raw || "").trim();+ if (!source) return {};+ const warn = (message) => {+ if (typeof onWarn === "function") onWarn(message);+ else process.stderr.write(`${message}\n`);+ };+ let parsed;+ try {+ parsed = JSON.parse(source);+ } catch (err) {+ warn(`OPENVIKING_EXTRA_HEADERS is not valid JSON; ignoring (${err.message})`);+ return {};+ }+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {+ warn("OPENVIKING_EXTRA_HEADERS must be a JSON object of string values; ignoring");+ return {};+ }+ const out = {};+ for (const [key, value] of Object.entries(parsed)) {+ const name = String(key || "").trim();+ if (!name) continue;+ if (RESERVED_HEADER_NAMES.has(name.toLowerCase())) {+ warn(`OPENVIKING_EXTRA_HEADERS: ignoring reserved header "${name}"`);+ continue;+ }+ if (value === null || value === undefined) continue;+ if (typeof value === "object") {+ warn(`OPENVIKING_EXTRA_HEADERS: header "${name}" must be a scalar; ignoring`);+ continue;+ }+ out[name] = String(value);+ }+ return out;+}+/*** Shape a harness's loaded config into the object `createOpenVikingMcpProxy`* expects.@@ -105,8 +166,12 @@ export function buildMcpProxyConfig({credentialSource = "auto",credentialPath = "",watchedPaths = [],+ extraHeaders = null,env = process.env,} = {}) {+ const resolvedExtraHeaders = extraHeaders && typeof extraHeaders === "object" && !Array.isArray(extraHeaders)+ ? { ...extraHeaders }+ : parseExtraHeaders(env.OPENVIKING_EXTRA_HEADERS);return {mcpUrl: mcpUrl || `${trimSlash(baseUrl)}/mcp`,apiKey: apiKey || "",@@ -124,5 +189,6 @@ export function buildMcpProxyConfig({credentialSource: credentialSource || "auto",credentialPath: credentialPath || "",watchedPaths: uniq([...watchedPaths, ...defaultCredentialPaths(env)]),+ extraHeaders: resolvedExtraHeaders,};}diff --git a/agent-plugins/servers/shared/mcp-proxy-core.mjs b/agent-plugins/servers/shared/mcp-proxy-core.mjsindex de11c2879..d491b824d 100644--- a/agent-plugins/servers/shared/mcp-proxy-core.mjs+++ b/agent-plugins/servers/shared/mcp-proxy-core.mjs@@ -242,7 +242,7 @@ export function createOpenVikingMcpProxy({}function headersForRequest(includeSession = true) {- return buildOvHeaders(proxyConfig, {+ const built = buildOvHeaders(proxyConfig, {actorPeerId: proxyConfig.peerId,extraHeaders: {"Accept": "application/json, text/event-stream",@@ -253,6 +253,16 @@ export function createOpenVikingMcpProxy({...(includeSession && sessionId ? { "Mcp-Session-Id": sessionId } : {}),},});+ // Operator-supplied extras (OPENVIKING_EXTRA_HEADERS) merged with the+ // proxy's own headers winning — the env-only escape hatch fills gaps for+ // strict private-gateway upstreams (tenant/vault names, region hints)+ // without letting a stray env var override authentication or session+ // negotiation.+ const opExtras = proxyConfig.extraHeaders;+ if (opExtras && typeof opExtras === "object") {+ return { ...opExtras, ...built };+ }+ return built;}function writeMessage(obj) {diff --git a/examples/claude-code-memory-plugin/scripts/shared/mcp-proxy-config.mjs b/examples/claude-code-memory-plugin/scripts/shared/mcp-proxy-config.mjsindex dd11897ee..c1e527967 100644--- a/examples/claude-code-memory-plugin/scripts/shared/mcp-proxy-config.mjs+++ b/examples/claude-code-memory-plugin/scripts/shared/mcp-proxy-config.mjs@@ -79,6 +79,67 @@ function uniq(values) {return [...new Set(values.filter(Boolean))];}+/**+ * Parse `OPENVIKING_EXTRA_HEADERS` into a plain string→string map.+ *+ * Some private deployments sit behind gateways that require custom headers+ * (a tenant/vault name, a signed token, a region hint) on every request. The+ * proxy has no other seam to inject those: the credential file's own+ * `extra_headers` field is intentionally not exported to MCP callers (see+ * `workspace-config.mjs` `FORBIDDEN_KEYS`), so this env-only escape hatch keeps+ * that boundary while letting an operator unblock a strict upstream.+ *+ * The value is a JSON object; anything else is ignored with a stderr warning+ * rather than crashing the proxy — a bad env var must not take down the whole+ * memory tool surface. Reserved names (`Content-Type`, `Accept`,+ * `MCP-Protocol-Version`, `Mcp-Session-Id`, `Authorization`) are dropped: they+ * are set by the proxy itself and letting the env override them would break+ * session negotiation or expose the wrong credential.+ */+const RESERVED_HEADER_NAMES = new Set([+ "content-type",+ "accept",+ "mcp-protocol-version",+ "mcp-session-id",+ "authorization",+]);++export function parseExtraHeaders(raw, { onWarn = null } = {}) {+ const source = String(raw || "").trim();+ if (!source) return {};+ const warn = (message) => {+ if (typeof onWarn === "function") onWarn(message);+ else process.stderr.write(`${message}\n`);+ };+ let parsed;+ try {+ parsed = JSON.parse(source);+ } catch (err) {+ warn(`OPENVIKING_EXTRA_HEADERS is not valid JSON; ignoring (${err.message})`);+ return {};+ }+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {+ warn("OPENVIKING_EXTRA_HEADERS must be a JSON object of string values; ignoring");+ return {};+ }+ const out = {};+ for (const [key, value] of Object.entries(parsed)) {+ const name = String(key || "").trim();+ if (!name) continue;+ if (RESERVED_HEADER_NAMES.has(name.toLowerCase())) {+ warn(`OPENVIKING_EXTRA_HEADERS: ignoring reserved header "${name}"`);+ continue;+ }+ if (value === null || value === undefined) continue;+ if (typeof value === "object") {+ warn(`OPENVIKING_EXTRA_HEADERS: header "${name}" must be a scalar; ignoring`);+ continue;+ }+ out[name] = String(value);+ }+ return out;+}+/*** Shape a harness's loaded config into the object `createOpenVikingMcpProxy`* expects.@@ -105,8 +166,12 @@ export function buildMcpProxyConfig({credentialSource = "auto",credentialPath = "",watchedPaths = [],+ extraHeaders = null,env = process.env,} = {}) {+ const resolvedExtraHeaders = extraHeaders && typeof extraHeaders === "object" && !Array.isArray(extraHeaders)+ ? { ...extraHeaders }+ : parseExtraHeaders(env.OPENVIKING_EXTRA_HEADERS);return {mcpUrl: mcpUrl || `${trimSlash(baseUrl)}/mcp`,apiKey: apiKey || "",@@ -124,5 +189,6 @@ export function buildMcpProxyConfig({credentialSource: credentialSource || "auto",credentialPath: credentialPath || "",watchedPaths: uniq([...watchedPaths, ...defaultCredentialPaths(env)]),+ extraHeaders: resolvedExtraHeaders,};}diff --git a/examples/claude-code-memory-plugin/scripts/shared/mcp-proxy-core.mjs b/examples/claude-code-memory-plugin/scripts/shared/mcp-proxy-core.mjsindex de11c2879..d491b824d 100644--- a/examples/claude-code-memory-plugin/scripts/shared/mcp-proxy-core.mjs+++ b/examples/claude-code-memory-plugin/scripts/shared/mcp-proxy-core.mjs@@ -242,7 +242,7 @@ export function createOpenVikingMcpProxy({}function headersForRequest(includeSession = true) {- return buildOvHeaders(proxyConfig, {+ const built = buildOvHeaders(proxyConfig, {actorPeerId: proxyConfig.peerId,extraHeaders: {"Accept": "application/json, text/event-stream",@@ -253,6 +253,16 @@ export function createOpenVikingMcpProxy({...(includeSession && sessionId ? { "Mcp-Session-Id": sessionId } : {}),},});+ // Operator-supplied extras (OPENVIKING_EXTRA_HEADERS) merged with the+ // proxy's own headers winning — the env-only escape hatch fills gaps for+ // strict private-gateway upstreams (tenant/vault names, region hints)+ // without letting a stray env var override authentication or session+ // negotiation.+ const opExtras = proxyConfig.extraHeaders;+ if (opExtras && typeof opExtras === "object") {+ return { ...opExtras, ...built };+ }+ return built;}function writeMessage(obj) {diff --git a/examples/codex-memory-plugin/.mcp.json b/examples/codex-memory-plugin/.mcp.jsonindex a08b1127a..15067efc6 100644--- a/examples/codex-memory-plugin/.mcp.json+++ b/examples/codex-memory-plugin/.mcp.json@@ -24,7 +24,8 @@"OPENVIKING_RECALL_PEER_SCOPE","OPENVIKING_TIMEOUT_MS","OPENVIKING_DEBUG",- "OPENVIKING_DEBUG_LOG"+ "OPENVIKING_DEBUG_LOG",+ "OPENVIKING_EXTRA_HEADERS"]}}diff --git a/examples/codex-memory-plugin/README.md b/examples/codex-memory-plugin/README.mdindex e2f31c525..b751e9738 100644--- a/examples/codex-memory-plugin/README.md+++ b/examples/codex-memory-plugin/README.md@@ -161,6 +161,16 @@ export OPENVIKING_DEBUG=1Full list: see the `Misc env vars` block in `scripts/config.mjs`. Tuning fields have `OPENVIKING_*` counterparts and env vars win for those tuning fields.+#### Private-gateway extra headers++Some private OpenViking deployments sit behind a gateway that requires custom headers on every request. The stdio MCP proxy reads those from `OPENVIKING_EXTRA_HEADERS`, a JSON object of scalar values (header name → header value) — see your deployment's gateway docs for the exact header names it expects.++```sh+export OPENVIKING_EXTRA_HEADERS='{"<header-name>":"<header-value>"}'+```++Reserved headers (`Content-Type`, `Accept`, `MCP-Protocol-Version`, `Mcp-Session-Id`, `Authorization`) are dropped with a stderr warning: the proxy owns those and letting an env var override them would break session negotiation or expose the wrong credential. Bad JSON is ignored with a warning rather than crashing the proxy. This env var is scoped to the stdio MCP proxy; hooks read credentials through the ovcli chain and do not consult it.+#### Input filtersTwo knobs put an ordered list of regex rules in front of the text the plugin sends: `recallQueryFilters` / `OPENVIKING_RECALL_QUERY_FILTERS` shapes the prompt before it becomes a search query, and `captureFilters` / `OPENVIKING_CAPTURE_FILTERS` shapes every turn on the write path before it is stored.diff --git a/examples/codex-memory-plugin/scripts/shared/mcp-proxy-config.mjs b/examples/codex-memory-plugin/scripts/shared/mcp-proxy-config.mjsindex dd11897ee..c1e527967 100644--- a/examples/codex-memory-plugin/scripts/shared/mcp-proxy-config.mjs+++ b/examples/codex-memory-plugin/scripts/shared/mcp-proxy-config.mjs@@ -79,6 +79,67 @@ function uniq(values) {return [...new Set(values.filter(Boolean))];}+/**+ * Parse `OPENVIKING_EXTRA_HEADERS` into a plain string→string map.+ *+ * Some private deployments sit behind gateways that require custom headers+ * (a tenant/vault name, a signed token, a region hint) on every request. The+ * proxy has no other seam to inject those: the credential file's own+ * `extra_headers` field is intentionally not exported to MCP callers (see+ * `workspace-config.mjs` `FORBIDDEN_KEYS`), so this env-only escape hatch keeps+ * that boundary while letting an operator unblock a strict upstream.+ *+ * The value is a JSON object; anything else is ignored with a stderr warning+ * rather than crashing the proxy — a bad env var must not take down the whole+ * memory tool surface. Reserved names (`Content-Type`, `Accept`,+ * `MCP-Protocol-Version`, `Mcp-Session-Id`, `Authorization`) are dropped: they+ * are set by the proxy itself and letting the env override them would break+ * session negotiation or expose the wrong credential.+ */+const RESERVED_HEADER_NAMES = new Set([+ "content-type",+ "accept",+ "mcp-protocol-version",+ "mcp-session-id",+ "authorization",+]);++export function parseExtraHeaders(raw, { onWarn = null } = {}) {+ const source = String(raw || "").trim();+ if (!source) return {};+ const warn = (message) => {+ if (typeof onWarn === "function") onWarn(message);+ else process.stderr.write(`${message}\n`);+ };+ let parsed;+ try {+ parsed = JSON.parse(source);+ } catch (err) {+ warn(`OPENVIKING_EXTRA_HEADERS is not valid JSON; ignoring (${err.message})`);+ return {};+ }+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {+ warn("OPENVIKING_EXTRA_HEADERS must be a JSON object of string values; ignoring");+ return {};+ }+ const out = {};+ for (const [key, value] of Object.entries(parsed)) {+ const name = String(key || "").trim();+ if (!name) continue;+ if (RESERVED_HEADER_NAMES.has(name.toLowerCase())) {+ warn(`OPENVIKING_EXTRA_HEADERS: ignoring reserved header "${name}"`);+ continue;+ }+ if (value === null || value === undefined) continue;+ if (typeof value === "object") {+ warn(`OPENVIKING_EXTRA_HEADERS: header "${name}" must be a scalar; ignoring`);+ continue;+ }+ out[name] = String(value);+ }+ return out;+}+/*** Shape a harness's loaded config into the object `createOpenVikingMcpProxy`* expects.@@ -105,8 +166,12 @@ export function buildMcpProxyConfig({credentialSource = "auto",credentialPath = "",watchedPaths = [],+ extraHeaders = null,env = process.env,} = {}) {+ const resolvedExtraHeaders = extraHeaders && typeof extraHeaders === "object" && !Array.isArray(extraHeaders)+ ? { ...extraHeaders }+ : parseExtraHeaders(env.OPENVIKING_EXTRA_HEADERS);return {mcpUrl: mcpUrl || `${trimSlash(baseUrl)}/mcp`,apiKey: apiKey || "",@@ -124,5 +189,6 @@ export function buildMcpProxyConfig({credentialSource: credentialSource || "auto",credentialPath: credentialPath || "",watchedPaths: uniq([...watchedPaths, ...defaultCredentialPaths(env)]),+ extraHeaders: resolvedExtraHeaders,};}diff --git a/examples/codex-memory-plugin/scripts/shared/mcp-proxy-core.mjs b/examples/codex-memory-plugin/scripts/shared/mcp-proxy-core.mjsindex de11c2879..d491b824d 100644--- a/examples/codex-memory-plugin/scripts/shared/mcp-proxy-core.mjs+++ b/examples/codex-memory-plugin/scripts/shared/mcp-proxy-core.mjs@@ -242,7 +242,7 @@ export function createOpenVikingMcpProxy({}function headersForRequest(includeSession = true) {- return buildOvHeaders(proxyConfig, {+ const built = buildOvHeaders(proxyConfig, {actorPeerId: proxyConfig.peerId,extraHeaders: {"Accept": "application/json, text/event-stream",@@ -253,6 +253,16 @@ export function createOpenVikingMcpProxy({...(includeSession && sessionId ? { "Mcp-Session-Id": sessionId } : {}),},});+ // Operator-supplied extras (OPENVIKING_EXTRA_HEADERS) merged with the+ // proxy's own headers winning — the env-only escape hatch fills gaps for+ // strict private-gateway upstreams (tenant/vault names, region hints)+ // without letting a stray env var override authentication or session+ // negotiation.+ const opExtras = proxyConfig.extraHeaders;+ if (opExtras && typeof opExtras === "object") {+ return { ...opExtras, ...built };+ }+ return built;}function writeMessage(obj) {diff --git a/examples/memory-plugin-shared/lib/mcp-proxy-config.mjs b/examples/memory-plugin-shared/lib/mcp-proxy-config.mjsindex ea34f1746..ffe695428 100644--- a/examples/memory-plugin-shared/lib/mcp-proxy-config.mjs+++ b/examples/memory-plugin-shared/lib/mcp-proxy-config.mjs@@ -78,6 +78,67 @@ function uniq(values) {return [...new Set(values.filter(Boolean))];}+/**+ * Parse `OPENVIKING_EXTRA_HEADERS` into a plain string→string map.+ *+ * Some private deployments sit behind gateways that require custom headers+ * (a tenant/vault name, a signed token, a region hint) on every request. The+ * proxy has no other seam to inject those: the credential file's own+ * `extra_headers` field is intentionally not exported to MCP callers (see+ * `workspace-config.mjs` `FORBIDDEN_KEYS`), so this env-only escape hatch keeps+ * that boundary while letting an operator unblock a strict upstream.+ *+ * The value is a JSON object; anything else is ignored with a stderr warning+ * rather than crashing the proxy — a bad env var must not take down the whole+ * memory tool surface. Reserved names (`Content-Type`, `Accept`,+ * `MCP-Protocol-Version`, `Mcp-Session-Id`, `Authorization`) are dropped: they+ * are set by the proxy itself and letting the env override them would break+ * session negotiation or expose the wrong credential.+ */+const RESERVED_HEADER_NAMES = new Set([+ "content-type",+ "accept",+ "mcp-protocol-version",+ "mcp-session-id",+ "authorization",+]);++export function parseExtraHeaders(raw, { onWarn = null } = {}) {+ const source = String(raw || "").trim();+ if (!source) return {};+ const warn = (message) => {+ if (typeof onWarn === "function") onWarn(message);+ else process.stderr.write(`${message}\n`);+ };+ let parsed;+ try {+ parsed = JSON.parse(source);+ } catch (err) {+ warn(`OPENVIKING_EXTRA_HEADERS is not valid JSON; ignoring (${err.message})`);+ return {};+ }+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {+ warn("OPENVIKING_EXTRA_HEADERS must be a JSON object of string values; ignoring");+ return {};+ }+ const out = {};+ for (const [key, value] of Object.entries(parsed)) {+ const name = String(key || "").trim();+ if (!name) continue;+ if (RESERVED_HEADER_NAMES.has(name.toLowerCase())) {+ warn(`OPENVIKING_EXTRA_HEADERS: ignoring reserved header "${name}"`);+ continue;+ }+ if (value === null || value === undefined) continue;+ if (typeof value === "object") {+ warn(`OPENVIKING_EXTRA_HEADERS: header "${name}" must be a scalar; ignoring`);+ continue;+ }+ out[name] = String(value);+ }+ return out;+}+/*** Shape a harness's loaded config into the object `createOpenVikingMcpProxy`* expects.@@ -104,8 +165,12 @@ export function buildMcpProxyConfig({credentialSource = "auto",credentialPath = "",watchedPaths = [],+ extraHeaders = null,env = process.env,} = {}) {+ const resolvedExtraHeaders = extraHeaders && typeof extraHeaders === "object" && !Array.isArray(extraHeaders)+ ? { ...extraHeaders }+ : parseExtraHeaders(env.OPENVIKING_EXTRA_HEADERS);return {mcpUrl: mcpUrl || `${trimSlash(baseUrl)}/mcp`,apiKey: apiKey || "",@@ -123,5 +188,6 @@ export function buildMcpProxyConfig({credentialSource: credentialSource || "auto",credentialPath: credentialPath || "",watchedPaths: uniq([...watchedPaths, ...defaultCredentialPaths(env)]),+ extraHeaders: resolvedExtraHeaders,};}diff --git a/examples/memory-plugin-shared/lib/mcp-proxy-core.mjs b/examples/memory-plugin-shared/lib/mcp-proxy-core.mjsindex d2019b559..2c44c1f4f 100644--- a/examples/memory-plugin-shared/lib/mcp-proxy-core.mjs+++ b/examples/memory-plugin-shared/lib/mcp-proxy-core.mjs@@ -241,7 +241,7 @@ export function createOpenVikingMcpProxy({}function headersForRequest(includeSession = true) {- return buildOvHeaders(proxyConfig, {+ const built = buildOvHeaders(proxyConfig, {actorPeerId: proxyConfig.peerId,extraHeaders: {"Accept": "application/json, text/event-stream",@@ -252,6 +252,16 @@ export function createOpenVikingMcpProxy({...(includeSession && sessionId ? { "Mcp-Session-Id": sessionId } : {}),},});+ // Operator-supplied extras (OPENVIKING_EXTRA_HEADERS) merged with the+ // proxy's own headers winning — the env-only escape hatch fills gaps for+ // strict private-gateway upstreams (tenant/vault names, region hints)+ // without letting a stray env var override authentication or session+ // negotiation.+ const opExtras = proxyConfig.extraHeaders;+ if (opExtras && typeof opExtras === "object") {+ return { ...opExtras, ...built };+ }+ return built;}function writeMessage(obj) {diff --git a/examples/memory-plugin-shared/mcp-proxy-config.test.mjs b/examples/memory-plugin-shared/mcp-proxy-config.test.mjsindex e4136dbdb..ca74d1edc 100644--- a/examples/memory-plugin-shared/mcp-proxy-config.test.mjs+++ b/examples/memory-plugin-shared/mcp-proxy-config.test.mjs@@ -10,6 +10,7 @@ import {DEFAULT_PROXY_TIMEOUT_MS,defaultCredentialPaths,normalizeConfigPath,+ parseExtraHeaders,resolveMcpActorPeerId,trimSlash,} from "./lib/mcp-proxy-config.mjs";@@ -293,3 +294,80 @@ test("an api_key deployment keeps the operator's identity off the wire", async (await rm(files.dir, { recursive: true, force: true });}});++test("OPENVIKING_EXTRA_HEADERS parses a JSON object of scalar values", () => {+ const headers = parseExtraHeaders(+ JSON.stringify({ "X-Tenant": "acme", "X-Region": "cn", "X-Retries": 3 }),+ );+ assert.deepEqual(headers, { "X-Tenant": "acme", "X-Region": "cn", "X-Retries": "3" });+});++test("OPENVIKING_EXTRA_HEADERS drops reserved names and warns rather than throwing", () => {+ const warnings = [];+ const headers = parseExtraHeaders(+ JSON.stringify({+ Authorization: "Bearer sneaky",+ "content-type": "text/plain",+ "MCP-Protocol-Version": "0000-00-00",+ "X-Vault": "primary",+ }),+ { onWarn: (m) => warnings.push(m) },+ );+ assert.deepEqual(headers, { "X-Vault": "primary" });+ assert.equal(warnings.length, 3);+ for (const w of warnings) assert.match(w, /reserved header/);+});++test("OPENVIKING_EXTRA_HEADERS ignores malformed JSON without taking the proxy down", () => {+ const warnings = [];+ assert.deepEqual(parseExtraHeaders("not json", { onWarn: (m) => warnings.push(m) }), {});+ assert.deepEqual(parseExtraHeaders("[1,2,3]", { onWarn: (m) => warnings.push(m) }), {});+ assert.deepEqual(parseExtraHeaders("", { onWarn: (m) => warnings.push(m) }), {});+ assert.equal(warnings.length, 2, "empty is silent, malformed and non-object each warn once");+});++test("buildMcpProxyConfig reads OPENVIKING_EXTRA_HEADERS from the env by default", () => {+ const cfg = buildMcpProxyConfig({+ env: { OPENVIKING_EXTRA_HEADERS: JSON.stringify({ "X-Tenant": "acme" }) },+ });+ assert.deepEqual(cfg.extraHeaders, { "X-Tenant": "acme" });+});++test("buildMcpProxyConfig lets an explicit extraHeaders override the env", () => {+ const cfg = buildMcpProxyConfig({+ extraHeaders: { "X-Explicit": "yes" },+ env: { OPENVIKING_EXTRA_HEADERS: JSON.stringify({ "X-Tenant": "acme" }) },+ });+ assert.deepEqual(cfg.extraHeaders, { "X-Explicit": "yes" });+});++test("operator-supplied extras cannot override proxy-owned headers on the wire", async () => {+ const sent = [];+ const proxy = createOpenVikingMcpProxy({+ stdout: { write(_line, cb) { if (cb) cb(); return true; } },+ fetchImpl: (_url, init) => {+ sent.push(init.headers);+ return Promise.resolve({+ ok: true,+ status: 200,+ statusText: "OK",+ headers: { get: () => null },+ text: async () => JSON.stringify({ jsonrpc: "2.0", id: 1, result: {} }),+ });+ },+ readConfig: () => buildMcpProxyConfig({+ mcpUrl: "http://127.0.0.1:1933/mcp",+ apiKey: "real-key",+ extraHeaders: {+ "X-Tenant": "acme",+ "openviking_name": "primary",+ Authorization: "Bearer stolen",+ },+ }),+ loggerFactory: () => ({ log() {}, logError() {} }),+ });+ await proxy.handleMessage({ jsonrpc: "2.0", id: 1, method: "initialize", params: {} });+ assert.equal(sent[0]["X-Tenant"], "acme");+ assert.equal(sent[0]["openviking_name"], "primary");+ assert.equal(sent[0].Authorization, "Bearer real-key", "the real api key still wins");+});