mirror of
https://github.com/openai/codex.git
synced 2026-04-24 14:45:27 +00:00
fix: prevent MCP startup failure on missing 'type' field (#7417)
Fix the issue #7416 that the codex-cli produce an error "MCP startup failure on missing 'type' field" in the startup. - Cause: serde in `convert_to_rmcp` (`codex-rs/rmcp-client/src/utils.rs`) failed because no `r#type` value was provided - Fix: set a default `r#type` value in the corresponding structs
This commit is contained in:
@@ -38,6 +38,13 @@ SERVER_NOTIFICATION_TYPE_NAMES: list[str] = []
|
||||
# order to compile without warnings.
|
||||
LARGE_ENUMS = {"ServerResult"}
|
||||
|
||||
# some types need setting a default value for `r#type`
|
||||
# ref: [#7417](https://github.com/openai/codex/pull/7417)
|
||||
default_type_values: dict[str, str] = {
|
||||
"ToolInputSchema": "object",
|
||||
"ToolOutputSchema": "object",
|
||||
}
|
||||
|
||||
|
||||
def main() -> int:
|
||||
parser = argparse.ArgumentParser(
|
||||
@@ -351,6 +358,14 @@ class StructField:
|
||||
out.append(f" pub {self.name}: {self.type_name},\n")
|
||||
|
||||
|
||||
def append_serde_attr(existing: str | None, fragment: str) -> str:
|
||||
if existing is None:
|
||||
return f"#[serde({fragment})]"
|
||||
assert existing.startswith("#[serde(") and existing.endswith(")]"), existing
|
||||
body = existing[len("#[serde(") : -2]
|
||||
return f"#[serde({body}, {fragment})]"
|
||||
|
||||
|
||||
def define_struct(
|
||||
name: str,
|
||||
properties: dict[str, Any],
|
||||
@@ -359,6 +374,14 @@ def define_struct(
|
||||
) -> list[str]:
|
||||
out: list[str] = []
|
||||
|
||||
type_default_fn: str | None = None
|
||||
if name in default_type_values:
|
||||
snake_name = to_snake_case(name) or name
|
||||
type_default_fn = f"{snake_name}_type_default_str"
|
||||
out.append(f"fn {type_default_fn}() -> String {{\n")
|
||||
out.append(f' "{default_type_values[name]}".to_string()\n')
|
||||
out.append("}\n\n")
|
||||
|
||||
fields: list[StructField] = []
|
||||
for prop_name, prop in properties.items():
|
||||
if prop_name == "_meta":
|
||||
@@ -380,6 +403,10 @@ def define_struct(
|
||||
if is_optional:
|
||||
prop_type = f"Option<{prop_type}>"
|
||||
rs_prop = rust_prop_name(prop_name, is_optional)
|
||||
|
||||
if prop_name == "type" and type_default_fn:
|
||||
rs_prop.serde = append_serde_attr(rs_prop.serde, f'default = "{type_default_fn}"')
|
||||
|
||||
if prop_type.startswith("&'static str"):
|
||||
fields.append(StructField("const", rs_prop.name, prop_type, rs_prop.serde, rs_prop.ts))
|
||||
else:
|
||||
|
||||
@@ -1474,6 +1474,10 @@ pub struct Tool {
|
||||
pub title: Option<String>,
|
||||
}
|
||||
|
||||
fn tool_output_schema_type_default_str() -> String {
|
||||
"object".to_string()
|
||||
}
|
||||
|
||||
/// An optional JSON Schema object defining the structure of the tool's output returned in
|
||||
/// the structuredContent field of a CallToolResult.
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
|
||||
@@ -1484,9 +1488,14 @@ pub struct ToolOutputSchema {
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
#[ts(optional)]
|
||||
pub required: Option<Vec<String>>,
|
||||
#[serde(default = "tool_output_schema_type_default_str")]
|
||||
pub r#type: String, // &'static str = "object"
|
||||
}
|
||||
|
||||
fn tool_input_schema_type_default_str() -> String {
|
||||
"object".to_string()
|
||||
}
|
||||
|
||||
/// A JSON Schema object defining the expected parameters for the tool.
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, TS)]
|
||||
pub struct ToolInputSchema {
|
||||
@@ -1496,6 +1505,7 @@ pub struct ToolInputSchema {
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
#[ts(optional)]
|
||||
pub required: Option<Vec<String>>,
|
||||
#[serde(default = "tool_input_schema_type_default_str")]
|
||||
pub r#type: String, // &'static str = "object"
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user