Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(review): preserve plugin MCP isolation

Chrisff3307442512
diff --git a/packages/maker-core/src/agents/codex/index.test.ts b/packages/maker-core/src/agents/codex/index.test.ts
index 48fb6d1599..6bf07dddd9 100644
--- a/packages/maker-core/src/agents/codex/index.test.ts
+++ b/packages/maker-core/src/agents/codex/index.test.ts
@@ -537,10 +537,12 @@ describe('CodexAgent permissions', () => {
if (method === Method.ConfigRead) {
return {
config: {
- mcp_servers: { local_docs: { enabled: true } },
+ mcp_servers: { local_docs: { command: '/usr/bin/local-docs', enabled: true } },
plugins: {
'configured@personal': {
- mcp_servers: { configured_server: { enabled: true } },
+ mcp_servers: {
+ configured_server: { url: 'https://example.invalid/mcp', enabled: true },
+ },
},
},
},
@@ -551,6 +553,7 @@ describe('CodexAgent permissions', () => {
data: [
{ name: 'codex_apps', tools: {} },
{ name: 'local_docs', tools: {} },
+ { name: 'configured_server', tools: {} },
],
nextCursor: null,
};
@@ -635,8 +638,9 @@ describe('CodexAgent permissions', () => {
enabled: false,
},
]);
- expect(threadStart.config).not.toHaveProperty('mcp_servers.should_not_exist');
- expect(threadStart.config).not.toHaveProperty('mcp_servers.codex_apps.enabled');
+ expect(threadStart.config).not.toHaveProperty(['mcp_servers.should_not_exist']);
+ expect(threadStart.config).not.toHaveProperty(['mcp_servers.codex_apps.enabled']);
+ expect(threadStart.config).not.toHaveProperty(['mcp_servers.configured_server.enabled']);
expect(handle.getPlanMode?.()).toBe(false);
await expect(
@@ -735,6 +739,48 @@ describe('CodexAgent permissions', () => {
).rejects.toThrow(/runtime MCP servers without transport-bearing config: unknown_runtime_mcp/);
});
+ it('fails closed when a runtime MCP only matches a transportless plugin entry', async () => {
+ const reviewDir = await fs.mkdtemp(path.join(os.tmpdir(), 'codex-review-plugin-mcp-'));
+ tempRoots.push(reviewDir);
+ const agent = new CodexAgent(createDeps());
+ installFakeHost(
+ agent,
+ (method) => {
+ if (method === Method.ExperimentalFeatureEnablementSet) return {};
+ if (method === Method.ConfigRead) {
+ return {
+ config: {
+ plugins: {
+ 'transportless@personal': {
+ mcp_servers: { colliding_runtime_name: { enabled: true } },
+ },
+ },
+ },
+ };
+ }
+ if (method === Method.McpServerStatusList) {
+ return {
+ data: [{ name: 'colliding_runtime_name', tools: {} }],
+ nextCursor: null,
+ };
+ }
+ return undefined;
+ },
+ { userAgent: 'mock-codex/0.145.0' },
+ );
+
+ await expect(
+ agent.startSession({
+ sessionId: 'session-review-plugin-mcp',
+ model: 'gpt-5.5',
+ workingDir: reviewDir,
+ reviewMode: true,
+ }),
+ ).rejects.toThrow(
+ /runtime MCP servers without transport-bearing config: colliding_runtime_name/,
+ );
+ });
+
it('refuses to start Review when Codex native memory cannot be disabled', async () => {
const reviewDir = await fs.mkdtemp(path.join(os.tmpdir(), 'codex-review-memory-'));
tempRoots.push(reviewDir);
diff --git a/packages/maker-core/src/agents/codex/index.ts b/packages/maker-core/src/agents/codex/index.ts
index 3d8b56c281..b1e09b3e04 100644
--- a/packages/maker-core/src/agents/codex/index.ts
+++ b/packages/maker-core/src/agents/codex/index.ts
@@ -609,6 +609,13 @@ function asRecord(value: unknown): Record<string, unknown> {
: {};
}
+function hasCodexMcpTransport(value: unknown): boolean {
+ const config = asRecord(value);
+ return [config.command, config.url].some(
+ (transport) => typeof transport === 'string' && transport.trim().length > 0,
+ );
+}
+
/**
* SandboxMode (thread/start 用 kebab enum) → SandboxPolicy (turn/start 用 tag union)。
* 两者**字段名 + 类型都不一样**, 是 Codex 协议的不对称设计 — turn/start 接 SandboxPolicy
@@ -3850,7 +3857,19 @@ export class CodexAgent extends BaseAgent {
const effectiveConfig = asRecord(configResponse.config);
const configuredMcp = asRecord(effectiveConfig.mcp_servers);
const configuredPlugins = asRecord(effectiveConfig.plugins);
- const configuredMcpServerNames = new Set(Object.keys(configuredMcp));
+ const configuredMcpServerNames = new Set(
+ Object.entries(configuredMcp)
+ .filter(([, serverConfig]) => hasCodexMcpTransport(serverConfig))
+ .map(([serverName]) => serverName),
+ );
+ const transportConfiguredMcpServerNames = new Set(configuredMcpServerNames);
+ for (const pluginConfig of Object.values(configuredPlugins)) {
+ const pluginMcp = asRecord(asRecord(pluginConfig).mcp_servers);
+ for (const [serverName, serverConfig] of Object.entries(pluginMcp)) {
+ if (!hasCodexMcpTransport(serverConfig)) continue;
+ transportConfiguredMcpServerNames.add(serverName);
+ }
+ }
const unconfiguredRuntimeMcpServerNames = new Set<string>();
let cursor: string | null = null;
do {
@@ -3862,7 +3881,7 @@ export class CodexAgent extends BaseAgent {
);
for (const server of status.data) {
if (
- !configuredMcpServerNames.has(server.name) &&
+ !transportConfiguredMcpServerNames.has(server.name) &&
server.name !== CODEX_APPS_MCP_SERVER_NAME
) {
unconfiguredRuntimeMcpServerNames.add(server.name);
@@ -3910,7 +3929,8 @@ export class CodexAgent extends BaseAgent {
`plugins.${quoteReviewConfigSegment(pluginId)}.enabled`
] = false;
const pluginMcp = asRecord(asRecord(configuredPlugins[pluginId]).mcp_servers);
- for (const serverName of Object.keys(pluginMcp)) {
+ for (const [serverName, serverConfig] of Object.entries(pluginMcp)) {
+ if (!hasCodexMcpTransport(serverConfig)) continue;
reviewCapabilityConfig[
`plugins.${quoteReviewConfigSegment(pluginId)}.mcp_servers.${renderReviewConfigSegment(serverName)}.enabled`
] = false;