惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

M
MIT News - Artificial intelligence
雷峰网
雷峰网
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Last Week in AI
Last Week in AI
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
阮一峰的网络日志
阮一峰的网络日志
月光博客
月光博客
博客园 - Franky
腾讯CDC
T
Tailwind CSS Blog
Recent Announcements
Recent Announcements
V
V2EX
N
Netflix TechBlog - Medium
量子位
Jina AI
Jina AI
Y
Y Combinator Blog
The GitHub Blog
The GitHub Blog
G
Google Developers Blog
爱范儿
爱范儿
博客园 - 叶小钗
D
Docker
MongoDB | Blog
MongoDB | Blog
D
DataBreaches.Net
T
The Blog of Author Tim Ferriss

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
fix(codex): scope user MCP servers by agent (#82180) · op...
sercada · 2026-05-16 · via Recent Commits to openclaw:main

@@ -1,13 +1,9 @@

11

import { normalizeConfiguredMcpServers } from "../../config/mcp-config-normalize.js";

22

import type { OpenClawConfig } from "../../config/types.openclaw.js";

33

import type { BundleMcpConfig, BundleMcpServerConfig } from "../../plugins/bundle-mcp.js";

4-

import { normalizeOptionalLowercaseString } from "../../shared/string-coerce.js";

5-

import { buildCodexMcpServersConfig } from "../codex-mcp-config.js";

6-

import {

7-

applyCommonServerConfig,

8-

decodeHeaderEnvPlaceholder,

9-

normalizeStringRecord,

10-

} from "./bundle-mcp-adapter-shared.js";

4+

import { isValidAgentId, normalizeAgentId } from "../../routing/session-key.js";

5+

import { buildCodexMcpServersConfig, normalizeCodexMcpServerConfig } from "../codex-mcp-config.js";

6+

import { isRecord } from "./bundle-mcp-adapter-shared.js";

117

import { serializeTomlInlineValue } from "./toml-inline.js";

128139

// Mutable JSON shape structurally compatible with the bundled Codex

@@ -24,47 +20,38 @@ type CodexThreadConfigValue =

2420

| { [key: string]: CodexThreadConfigValue };

2521

type CodexThreadConfigObject = { [key: string]: CodexThreadConfigValue };

262227-

function isOpenClawLoopbackMcpServer(name: string, server: BundleMcpServerConfig): boolean {

28-

return (

29-

name === "openclaw" &&

30-

typeof server.url === "string" &&

31-

/^https?:\/\/(?:127\.0\.0\.1|localhost):\d+\/mcp(?:[?#].*)?$/.test(server.url)

32-

);

23+

type CodexUserMcpServersProjectionOptions = {

24+

agentId?: string;

25+

};

26+27+

function normalizeAgentIds(value: unknown): string[] {

28+

if (!Array.isArray(value)) {

29+

return [];

30+

}

31+

return value

32+

.filter((entry): entry is string => typeof entry === "string")

33+

.map((entry) => entry.trim())

34+

.filter((entry) => isValidAgentId(entry))

35+

.map((entry) => normalizeAgentId(entry));

3336

}

343735-

function normalizeCodexServerConfig(

36-

name: string,

38+

function readCodexProjectionConfig(server: BundleMcpServerConfig): Record<string, unknown> {

39+

return isRecord(server.codex) ? server.codex : {};

40+

}

41+42+

function isCodexMcpServerAllowedForAgent(

3743

server: BundleMcpServerConfig,

38-

): CodexThreadConfigObject {

39-

const next: CodexThreadConfigObject = {};

40-

applyCommonServerConfig(next, server);

41-

if (isOpenClawLoopbackMcpServer(name, server)) {

42-

next.default_tools_approval_mode = "approve";

44+

options: CodexUserMcpServersProjectionOptions | undefined,

45+

): boolean {

46+

const codex = readCodexProjectionConfig(server);

47+

if (!Object.hasOwn(codex, "agents")) {

48+

return true;

4349

}

44-

const httpHeaders = normalizeStringRecord(server.headers);

45-

if (httpHeaders) {

46-

const staticHeaders: Record<string, string> = {};

47-

const envHeaders: Record<string, string> = {};

48-

for (const [name, value] of Object.entries(httpHeaders)) {

49-

const decoded = decodeHeaderEnvPlaceholder(value);

50-

if (!decoded) {

51-

staticHeaders[name] = value;

52-

continue;

53-

}

54-

if (decoded.bearer && normalizeOptionalLowercaseString(name) === "authorization") {

55-

next.bearer_token_env_var = decoded.envVar;

56-

continue;

57-

}

58-

envHeaders[name] = decoded.envVar;

59-

}

60-

if (Object.keys(staticHeaders).length > 0) {

61-

next.http_headers = staticHeaders;

62-

}

63-

if (Object.keys(envHeaders).length > 0) {

64-

next.env_http_headers = envHeaders;

65-

}

50+

const agentIds = normalizeAgentIds(codex.agents);

51+

if (agentIds.length === 0 || !options?.agentId) {

52+

return false;

6653

}

67-

return next;

54+

return agentIds.includes(normalizeAgentId(options.agentId));

6855

}

69567057

export function injectCodexMcpConfigArgs(

@@ -89,6 +76,7 @@ export function injectCodexMcpConfigArgs(

8976

*/

9077

export function buildCodexUserMcpServersThreadConfigPatch(

9178

cfg: OpenClawConfig | undefined,

79+

options?: CodexUserMcpServersProjectionOptions,

9280

): { mcp_servers: CodexThreadConfigObject } | undefined {

9381

const userServers = normalizeConfiguredMcpServers(cfg?.mcp?.servers);

9482

const entries = Object.entries(userServers);

@@ -97,7 +85,16 @@ export function buildCodexUserMcpServersThreadConfigPatch(

9785

}

9886

const mcp_servers: CodexThreadConfigObject = {};

9987

for (const [name, server] of entries) {

100-

mcp_servers[name] = normalizeCodexServerConfig(name, server as BundleMcpServerConfig);

88+

if (!isCodexMcpServerAllowedForAgent(server as BundleMcpServerConfig, options)) {

89+

continue;

90+

}

91+

mcp_servers[name] = normalizeCodexMcpServerConfig(

92+

name,

93+

server as BundleMcpServerConfig,

94+

) as CodexThreadConfigObject;

95+

}

96+

if (Object.keys(mcp_servers).length === 0) {

97+

return undefined;

10198

}

10299

return { mcp_servers };

103100

}