From 45cb02b1dd86c693f4d39c5f4dda96a0e148b6c8 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Tue, 17 Mar 2026 04:07:28 +0000 Subject: [PATCH] refactor(plugins): share MCP server map extraction --- src/agents/cli-runner/bundle-mcp.ts | 27 ++------------------------- src/plugins/bundle-mcp.ts | 2 +- 2 files changed, 3 insertions(+), 26 deletions(-) diff --git a/src/agents/cli-runner/bundle-mcp.ts b/src/agents/cli-runner/bundle-mcp.ts index 60e6149519c..96aeb867869 100644 --- a/src/agents/cli-runner/bundle-mcp.ts +++ b/src/agents/cli-runner/bundle-mcp.ts @@ -5,43 +5,20 @@ import type { OpenClawConfig } from "../../config/config.js"; import { applyMergePatch } from "../../config/merge-patch.js"; import type { CliBackendConfig } from "../../config/types.js"; import { + extractMcpServerMap, loadEnabledBundleMcpConfig, type BundleMcpConfig, - type BundleMcpServerConfig, } from "../../plugins/bundle-mcp.js"; -import { isRecord } from "../../utils.js"; type PreparedCliBundleMcpConfig = { backend: CliBackendConfig; cleanup?: () => Promise; }; -function extractServerMap(raw: unknown): Record { - if (!isRecord(raw)) { - return {}; - } - const nested = isRecord(raw.mcpServers) - ? raw.mcpServers - : isRecord(raw.servers) - ? raw.servers - : raw; - if (!isRecord(nested)) { - return {}; - } - const result: Record = {}; - for (const [serverName, serverRaw] of Object.entries(nested)) { - if (!isRecord(serverRaw)) { - continue; - } - result[serverName] = { ...serverRaw }; - } - return result; -} - async function readExternalMcpConfig(configPath: string): Promise { try { const raw = JSON.parse(await fs.readFile(configPath, "utf-8")) as unknown; - return { mcpServers: extractServerMap(raw) }; + return { mcpServers: extractMcpServerMap(raw) }; } catch { return { mcpServers: {} }; } diff --git a/src/plugins/bundle-mcp.ts b/src/plugins/bundle-mcp.ts index 6ce186384c7..62c10e59156 100644 --- a/src/plugins/bundle-mcp.ts +++ b/src/plugins/bundle-mcp.ts @@ -105,7 +105,7 @@ function resolveBundleMcpConfigPaths(params: { return mergeUniquePathLists(defaults, declared); } -function extractMcpServerMap(raw: unknown): Record { +export function extractMcpServerMap(raw: unknown): Record { if (!isRecord(raw)) { return {}; }