Skip to content

Commit 7c5e2cb

Browse files
LittleCoinCoinLittleCoinCoin
authored andcommitted
fix(codex): map http_headers to universal headers field
Remove redundant http_headers field from MCPServerConfigOmni model. Codex's http_headers should map to the universal headers field, not be a separate field. Root cause: Initial implementation incorrectly added http_headers as a separate Codex-specific field in Omni model, when it's semantically identical to the universal headers field. Solution: - Remove http_headers from MCPServerConfigOmni (line 688) - Update MCPServerConfigCodex.from_omni() to map headers → http_headers - Update CodexHostStrategy._flatten_toml_server() to map TOML http_headers → headers - Update CodexHostStrategy._to_toml_server() to map headers → TOML http_headers Data flow: - CLI: --header → Omni headers → Codex http_headers → TOML http_headers - TOML: http_headers → MCPServerConfig headers → Omni headers → Codex http_headers This ensures proper mapping between universal headers and Codex http_headers while maintaining correct TOML format for Codex configuration files.
1 parent 88e81fe commit 7c5e2cb

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

hatch/mcp_host_config/models.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -623,9 +623,17 @@ class MCPServerConfigCodex(MCPServerConfigBase):
623623

624624
@classmethod
625625
def from_omni(cls, omni: 'MCPServerConfigOmni') -> 'MCPServerConfigCodex':
626-
"""Convert Omni model to Codex-specific model."""
626+
"""Convert Omni model to Codex-specific model.
627+
628+
Maps universal 'headers' field to Codex-specific 'http_headers' field.
629+
"""
627630
supported_fields = set(cls.model_fields.keys())
628631
codex_data = omni.model_dump(include=supported_fields, exclude_unset=True)
632+
633+
# Map universal 'headers' to Codex 'http_headers'
634+
if hasattr(omni, 'headers') and omni.headers is not None:
635+
codex_data['http_headers'] = omni.headers
636+
629637
return cls.model_validate(codex_data)
630638

631639

@@ -685,8 +693,8 @@ class MCPServerConfigOmni(BaseModel):
685693
enabled_tools: Optional[List[str]] = None
686694
disabled_tools: Optional[List[str]] = None
687695
bearer_token_env_var: Optional[str] = None
688-
http_headers: Optional[Dict[str, str]] = None
689696
env_http_headers: Optional[Dict[str, str]] = None
697+
# Note: http_headers maps to universal 'headers' field, not a separate Codex field
690698

691699
@field_validator('url')
692700
@classmethod

hatch/mcp_host_config/strategies.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -750,16 +750,31 @@ def _flatten_toml_server(self, server_data: Dict[str, Any]) -> Dict[str, Any]:
750750
751751
Becomes:
752752
{"command": "npx", "args": [...], "env": {"VAR": "value"}}
753+
754+
Also maps Codex-specific 'http_headers' to universal 'headers' field.
753755
"""
754756
# TOML already parses nested tables into nested dicts
755757
# So [mcp_servers.name.env] becomes {"env": {...}}
756-
return dict(server_data)
758+
data = dict(server_data)
759+
760+
# Map Codex 'http_headers' to universal 'headers' for MCPServerConfig
761+
if 'http_headers' in data:
762+
data['headers'] = data.pop('http_headers')
763+
764+
return data
757765

758766
def _to_toml_server(self, server_config: MCPServerConfig) -> Dict[str, Any]:
759-
"""Convert MCPServerConfig to TOML-compatible dict structure."""
767+
"""Convert MCPServerConfig to TOML-compatible dict structure.
768+
769+
Maps universal 'headers' field back to Codex-specific 'http_headers'.
770+
"""
760771
data = server_config.model_dump(exclude_unset=True)
761772

762773
# Remove 'name' field as it's the table key in TOML
763774
data.pop('name', None)
764775

776+
# Map universal 'headers' to Codex 'http_headers' for TOML
777+
if 'headers' in data:
778+
data['http_headers'] = data.pop('headers')
779+
765780
return data

0 commit comments

Comments
 (0)