|
14 | 14 | import tomli as tomllib |
15 | 15 |
|
16 | 16 | from cycode.cli.apps.ai_guardrails.consts import CYCODE_SCAN_PROMPT_COMMAND, CYCODE_SESSION_START_COMMAND |
17 | | -from cycode.cli.apps.ai_guardrails.ides._plugin_utils import load_plugin_json, walk_enabled_plugins |
| 17 | +from cycode.cli.apps.ai_guardrails.ides._plugin_utils import ( |
| 18 | + build_global_config_file, |
| 19 | + load_plugin_json, |
| 20 | + walk_enabled_plugins, |
| 21 | +) |
18 | 22 | from cycode.cli.apps.ai_guardrails.ides.base import IDE, DecisionAction, HookDecision |
19 | 23 | from cycode.cli.apps.ai_guardrails.scan.payload import AIHookPayload |
20 | 24 | from cycode.cli.apps.ai_guardrails.scan.types import AiHookEventType |
@@ -129,12 +133,14 @@ def _read_codex_plugin(plugin_dir: Path) -> tuple[dict, dict]: |
129 | 133 | mcp_ref = manifest.get('mcpServers') |
130 | 134 | if not mcp_ref: |
131 | 135 | return entry, {} |
132 | | - mcp_doc = load_plugin_json(plugin_dir / mcp_ref) or {} |
| 136 | + mcp_config_path = plugin_dir / mcp_ref |
| 137 | + mcp_doc = load_plugin_json(mcp_config_path) or {} |
133 | 138 | servers = mcp_doc.get('mcpServers', mcp_doc) |
134 | 139 | if not isinstance(servers, dict): |
135 | 140 | servers = {} |
136 | 141 | if servers: |
137 | 142 | entry['mcp_server_names'] = list(servers.keys()) |
| 143 | + entry['mcp_config_file_path'] = str(mcp_config_path) |
138 | 144 | entry['mcp_config_file'] = json.dumps(mcp_doc) |
139 | 145 | return entry, servers |
140 | 146 |
|
@@ -298,13 +304,14 @@ def build_session_payload(self, raw_payload: dict) -> AIHookPayload: |
298 | 304 | def get_user_email(self) -> Optional[str]: |
299 | 305 | return _email_from_auth() |
300 | 306 |
|
301 | | - def get_session_context(self) -> tuple[dict, dict]: |
| 307 | + def get_session_context(self) -> tuple[Optional[dict], dict]: |
302 | 308 | config = _load_codex_config() |
303 | 309 | if not config: |
304 | | - return {}, {} |
305 | | - # Codex stores MCP servers under `[mcp_servers.<name>]`. Plugin-contributed |
306 | | - # servers (via `[plugins."<plugin>@<marketplace>"]`) merge on top. |
307 | | - mcp_servers: dict = dict(config.get('mcp_servers') or {}) |
308 | | - plugin_mcp, enriched_plugins = _resolve_codex_plugins(config) |
309 | | - mcp_servers.update(plugin_mcp) |
310 | | - return mcp_servers, enriched_plugins |
| 310 | + return None, {} |
| 311 | + # Codex stores MCP servers under `[mcp_servers.<name>]`; the global config |
| 312 | + # file becomes its own session-context file. Plugins (via |
| 313 | + # `[plugins."<plugin>@<marketplace>"]`) carry their own config files. |
| 314 | + config_path = _codex_home() / _CONFIG_TOML_NAME |
| 315 | + global_config_file = build_global_config_file(config_path, config.get('mcp_servers')) |
| 316 | + _, enriched_plugins = _resolve_codex_plugins(config) |
| 317 | + return global_config_file, enriched_plugins |
0 commit comments