mirror of
https://github.com/openai/codex.git
synced 2026-05-04 21:32:21 +03:00
Fix MCP tool calling (#14491)
Properly escape mcp tool names and make tools only available via imports.
This commit is contained in:
@@ -45,6 +45,7 @@ impl TestToolServer {
|
||||
fn new() -> Self {
|
||||
let tools = vec![
|
||||
Self::echo_tool(),
|
||||
Self::echo_dash_tool(),
|
||||
Self::image_tool(),
|
||||
Self::image_scenario_tool(),
|
||||
];
|
||||
@@ -58,6 +59,20 @@ impl TestToolServer {
|
||||
}
|
||||
|
||||
fn echo_tool() -> Tool {
|
||||
Self::build_echo_tool(
|
||||
"echo",
|
||||
"Echo back the provided message and include environment data.",
|
||||
)
|
||||
}
|
||||
|
||||
fn echo_dash_tool() -> Tool {
|
||||
Self::build_echo_tool(
|
||||
"echo-tool",
|
||||
"Echo back the provided message via a tool name that is not a legal JS identifier.",
|
||||
)
|
||||
}
|
||||
|
||||
fn build_echo_tool(name: &'static str, description: &'static str) -> Tool {
|
||||
#[expect(clippy::expect_used)]
|
||||
let schema: JsonObject = serde_json::from_value(json!({
|
||||
"type": "object",
|
||||
@@ -71,8 +86,8 @@ impl TestToolServer {
|
||||
.expect("echo tool schema should deserialize");
|
||||
|
||||
Tool::new(
|
||||
Cow::Borrowed("echo"),
|
||||
Cow::Borrowed("Echo back the provided message and include environment data."),
|
||||
Cow::Borrowed(name),
|
||||
Cow::Borrowed(description),
|
||||
Arc::new(schema),
|
||||
)
|
||||
}
|
||||
@@ -296,7 +311,7 @@ impl ServerHandler for TestToolServer {
|
||||
_context: rmcp::service::RequestContext<rmcp::service::RoleServer>,
|
||||
) -> Result<CallToolResult, McpError> {
|
||||
match request.name.as_ref() {
|
||||
"echo" => {
|
||||
"echo" | "echo-tool" => {
|
||||
let args: EchoArgs = match request.arguments {
|
||||
Some(arguments) => serde_json::from_value(serde_json::Value::Object(
|
||||
arguments.into_iter().collect(),
|
||||
@@ -304,7 +319,7 @@ impl ServerHandler for TestToolServer {
|
||||
.map_err(|err| McpError::invalid_params(err.to_string(), None))?,
|
||||
None => {
|
||||
return Err(McpError::invalid_params(
|
||||
"missing arguments for echo tool",
|
||||
format!("missing arguments for {} tool", request.name),
|
||||
None,
|
||||
));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user