mirror of
https://github.com/pchuan98/codex.git
synced 2026-07-01 00:31:56 +08:00
910578792f
WIll make it easier to uprev when the new draft spec is supported. Also updates reqwest where needed for compatibility but doesn't update it everywhere since this is already a large diff. The new version of rmcp handles certain kinds of authentication failures differently, this patch includes support for identifying the failing scope in a WWW-Authenticate header.
121 lines
3.4 KiB
Rust
121 lines
3.4 KiB
Rust
use super::mcp_call_tool_result_output_schema;
|
|
use super::parse_mcp_tool;
|
|
use crate::JsonSchema;
|
|
use crate::ToolDefinition;
|
|
use pretty_assertions::assert_eq;
|
|
use std::collections::BTreeMap;
|
|
|
|
fn mcp_tool(name: &str, description: &str, input_schema: serde_json::Value) -> rmcp::model::Tool {
|
|
rmcp::model::Tool::new(
|
|
name.to_string(),
|
|
description.to_string(),
|
|
std::sync::Arc::new(rmcp::model::object(input_schema)),
|
|
)
|
|
}
|
|
|
|
#[test]
|
|
fn parse_mcp_tool_inserts_empty_properties() {
|
|
let tool = mcp_tool(
|
|
"no_props",
|
|
"No properties",
|
|
serde_json::json!({
|
|
"type": "object"
|
|
}),
|
|
);
|
|
|
|
assert_eq!(
|
|
parse_mcp_tool(&tool).expect("parse MCP tool"),
|
|
ToolDefinition {
|
|
name: "no_props".to_string(),
|
|
description: "No properties".to_string(),
|
|
input_schema: JsonSchema::object(
|
|
BTreeMap::new(),
|
|
/*required*/ None,
|
|
/*additional_properties*/ None
|
|
),
|
|
output_schema: Some(mcp_call_tool_result_output_schema(serde_json::json!({}))),
|
|
defer_loading: false,
|
|
}
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn parse_mcp_tool_preserves_top_level_output_schema() {
|
|
let mut tool = mcp_tool(
|
|
"with_output",
|
|
"Has output schema",
|
|
serde_json::json!({
|
|
"type": "object"
|
|
}),
|
|
);
|
|
tool.output_schema = Some(std::sync::Arc::new(rmcp::model::object(
|
|
serde_json::json!({
|
|
"properties": {
|
|
"result": {
|
|
"properties": {
|
|
"nested": {}
|
|
}
|
|
}
|
|
},
|
|
"required": ["result"]
|
|
}),
|
|
)));
|
|
|
|
assert_eq!(
|
|
parse_mcp_tool(&tool).expect("parse MCP tool"),
|
|
ToolDefinition {
|
|
name: "with_output".to_string(),
|
|
description: "Has output schema".to_string(),
|
|
input_schema: JsonSchema::object(
|
|
BTreeMap::new(),
|
|
/*required*/ None,
|
|
/*additional_properties*/ None
|
|
),
|
|
output_schema: Some(mcp_call_tool_result_output_schema(serde_json::json!({
|
|
"properties": {
|
|
"result": {
|
|
"properties": {
|
|
"nested": {}
|
|
}
|
|
}
|
|
},
|
|
"required": ["result"]
|
|
}))),
|
|
defer_loading: false,
|
|
}
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn parse_mcp_tool_preserves_output_schema_without_inferred_type() {
|
|
let mut tool = mcp_tool(
|
|
"with_enum_output",
|
|
"Has enum output schema",
|
|
serde_json::json!({
|
|
"type": "object"
|
|
}),
|
|
);
|
|
tool.output_schema = Some(std::sync::Arc::new(rmcp::model::object(
|
|
serde_json::json!({
|
|
"enum": ["ok", "error"]
|
|
}),
|
|
)));
|
|
|
|
assert_eq!(
|
|
parse_mcp_tool(&tool).expect("parse MCP tool"),
|
|
ToolDefinition {
|
|
name: "with_enum_output".to_string(),
|
|
description: "Has enum output schema".to_string(),
|
|
input_schema: JsonSchema::object(
|
|
BTreeMap::new(),
|
|
/*required*/ None,
|
|
/*additional_properties*/ None
|
|
),
|
|
output_schema: Some(mcp_call_tool_result_output_schema(serde_json::json!({
|
|
"enum": ["ok", "error"]
|
|
}))),
|
|
defer_loading: false,
|
|
}
|
|
);
|
|
}
|