mirror of
https://github.com/openai/codex.git
synced 2026-06-01 19:02:59 +00:00
fix: treat null MCP resource args as empty (#8917)
Handle null tool arguments in the MCP resource handler so optional resource tools accept null without failing, preserving normal JSON parsing for non-null payloads and improving robustness when models emit null; this avoids spurious argument parse errors for list/read MCP resource calls.
This commit is contained in:
committed by
GitHub
parent
6372ba9d5f
commit
51dd5af807
@@ -640,9 +640,14 @@ fn parse_arguments(raw_args: &str) -> Result<Option<Value>, FunctionCallError> {
|
||||
if raw_args.trim().is_empty() {
|
||||
Ok(None)
|
||||
} else {
|
||||
serde_json::from_str(raw_args).map(Some).map_err(|err| {
|
||||
let value: Value = serde_json::from_str(raw_args).map_err(|err| {
|
||||
FunctionCallError::RespondToModel(format!("failed to parse function arguments: {err}"))
|
||||
})
|
||||
})?;
|
||||
if value.is_null() {
|
||||
Ok(None)
|
||||
} else {
|
||||
Ok(Some(value))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -769,6 +774,11 @@ mod tests {
|
||||
"expected None for empty arguments"
|
||||
);
|
||||
|
||||
assert!(
|
||||
parse_arguments("null").unwrap().is_none(),
|
||||
"expected None for null arguments"
|
||||
);
|
||||
|
||||
let value = parse_arguments(r#"{"server":"figma"}"#)
|
||||
.expect("parse json")
|
||||
.expect("value present");
|
||||
|
||||
Reference in New Issue
Block a user