From dfbd21e2949e1d08c29436c91a408ce12284ae21 Mon Sep 17 00:00:00 2001 From: Jeremy lewi Date: Tue, 14 Apr 2026 14:24:13 -0700 Subject: [PATCH] refactor: make codex-tools rmcp-optional on wasm --- codex-rs/tools/Cargo.toml | 6 ++++-- codex-rs/tools/src/lib.rs | 3 +++ codex-rs/tools/src/mcp_tool.rs | 5 ++++- codex-rs/tools/src/responses_api.rs | 5 ++++- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/codex-rs/tools/Cargo.toml b/codex-rs/tools/Cargo.toml index 3d61dab7d8..4977d495dd 100644 --- a/codex-rs/tools/Cargo.toml +++ b/codex-rs/tools/Cargo.toml @@ -11,14 +11,16 @@ workspace = true codex-app-server-protocol = { workspace = true } codex-code-mode = { workspace = true } codex-protocol = { workspace = true } +serde = { workspace = true, features = ["derive"] } +serde_json = { workspace = true } + +[target.'cfg(not(target_arch = "wasm32"))'.dependencies] rmcp = { workspace = true, default-features = false, features = [ "base64", "macros", "schemars", "server", ] } -serde = { workspace = true, features = ["derive"] } -serde_json = { workspace = true } [dev-dependencies] pretty_assertions = { workspace = true } diff --git a/codex-rs/tools/src/lib.rs b/codex-rs/tools/src/lib.rs index 9ae6031ccd..5877a1ee2e 100644 --- a/codex-rs/tools/src/lib.rs +++ b/codex-rs/tools/src/lib.rs @@ -54,6 +54,7 @@ pub use mcp_resource_tool::create_list_mcp_resource_templates_tool; pub use mcp_resource_tool::create_list_mcp_resources_tool; pub use mcp_resource_tool::create_read_mcp_resource_tool; pub use mcp_tool::mcp_call_tool_result_output_schema; +#[cfg(not(target_arch = "wasm32"))] pub use mcp_tool::parse_mcp_tool; pub use request_user_input_tool::create_request_user_input_tool; pub use responses_api::FreeformTool; @@ -63,7 +64,9 @@ pub use responses_api::ResponsesApiNamespaceTool; pub use responses_api::ResponsesApiTool; pub use responses_api::ToolSearchOutputTool; pub use responses_api::dynamic_tool_to_responses_api_tool; +#[cfg(not(target_arch = "wasm32"))] pub use responses_api::mcp_tool_to_deferred_responses_api_tool; +#[cfg(not(target_arch = "wasm32"))] pub use responses_api::mcp_tool_to_responses_api_tool; pub use responses_api::tool_definition_to_responses_api_tool; pub use tool_definition::ToolDefinition; diff --git a/codex-rs/tools/src/mcp_tool.rs b/codex-rs/tools/src/mcp_tool.rs index 3fd3c5e751..56c952f7da 100644 --- a/codex-rs/tools/src/mcp_tool.rs +++ b/codex-rs/tools/src/mcp_tool.rs @@ -1,8 +1,11 @@ +#[cfg(not(target_arch = "wasm32"))] use crate::ToolDefinition; +#[cfg(not(target_arch = "wasm32"))] use crate::parse_tool_input_schema; use serde_json::Value as JsonValue; use serde_json::json; +#[cfg(not(target_arch = "wasm32"))] pub fn parse_mcp_tool(tool: &rmcp::model::Tool) -> Result { let mut serialized_input_schema = serde_json::Value::Object(tool.input_schema.as_ref().clone()); @@ -55,6 +58,6 @@ pub fn mcp_call_tool_result_output_schema(structured_content_schema: JsonValue) }) } -#[cfg(test)] +#[cfg(all(test, not(target_arch = "wasm32")))] #[path = "mcp_tool_tests.rs"] mod tests; diff --git a/codex-rs/tools/src/responses_api.rs b/codex-rs/tools/src/responses_api.rs index 6a8823582a..4705693719 100644 --- a/codex-rs/tools/src/responses_api.rs +++ b/codex-rs/tools/src/responses_api.rs @@ -1,6 +1,7 @@ use crate::JsonSchema; use crate::ToolDefinition; use crate::parse_dynamic_tool; +#[cfg(not(target_arch = "wasm32"))] use crate::parse_mcp_tool; use codex_protocol::dynamic_tools::DynamicToolSpec; use serde::Deserialize; @@ -68,6 +69,7 @@ pub fn dynamic_tool_to_responses_api_tool( )?)) } +#[cfg(not(target_arch = "wasm32"))] pub fn mcp_tool_to_responses_api_tool( name: String, tool: &rmcp::model::Tool, @@ -77,6 +79,7 @@ pub fn mcp_tool_to_responses_api_tool( )) } +#[cfg(not(target_arch = "wasm32"))] pub fn mcp_tool_to_deferred_responses_api_tool( name: String, tool: &rmcp::model::Tool, @@ -97,6 +100,6 @@ pub fn tool_definition_to_responses_api_tool(tool_definition: ToolDefinition) -> } } -#[cfg(test)] +#[cfg(all(test, not(target_arch = "wasm32")))] #[path = "responses_api_tests.rs"] mod tests;