|
| 1 | +use std::borrow::Cow; |
| 2 | +use std::path::Path; |
| 3 | +use std::process::Stdio; |
| 4 | +use std::sync::Arc; |
| 5 | + |
| 6 | +use anyhow::Result; |
| 7 | +use pretty_assertions::assert_eq; |
| 8 | +use rmcp::ServiceExt; |
| 9 | +use rmcp::model::Tool; |
| 10 | +use rmcp::model::object; |
| 11 | +use rmcp::transport::ConfigureCommandExt; |
| 12 | +use rmcp::transport::TokioChildProcess; |
| 13 | +use serde_json::json; |
| 14 | +use tokio::process::Command; |
| 15 | + |
| 16 | +#[tokio::test(flavor = "current_thread")] |
| 17 | +async fn auto_approve() -> Result<()> { |
| 18 | + let mcp_executable = assert_cmd::Command::cargo_bin("codex-exec-mcp-server")?; |
| 19 | + let execve_wrapper = assert_cmd::Command::cargo_bin("codex-execve-wrapper")?; |
| 20 | + let bash = Path::new(env!("CARGO_MANIFEST_DIR")) |
| 21 | + .join("tests") |
| 22 | + .join("suite") |
| 23 | + .join("bash"); |
| 24 | + let transport = |
| 25 | + TokioChildProcess::new(Command::new(mcp_executable.get_program()).configure(|cmd| { |
| 26 | + cmd.arg("--bash").arg(bash); |
| 27 | + cmd.arg("--execve").arg(execve_wrapper.get_program()); |
| 28 | + |
| 29 | + // Important: pipe stdio so rmcp can speak JSON-RPC over stdin/stdout |
| 30 | + cmd.stdin(Stdio::piped()); |
| 31 | + cmd.stdout(Stdio::piped()); |
| 32 | + |
| 33 | + // Optional but very helpful while debugging: |
| 34 | + cmd.stderr(Stdio::inherit()); |
| 35 | + }))?; |
| 36 | + |
| 37 | + let service = ().serve(transport).await?; |
| 38 | + let tools = service.list_tools(Default::default()).await?.tools; |
| 39 | + assert_eq!( |
| 40 | + vec![Tool { |
| 41 | + name: Cow::Borrowed("shell"), |
| 42 | + title: None, |
| 43 | + description: Some(Cow::Borrowed( |
| 44 | + "Runs a shell command and returns its output. You MUST provide the workdir as an absolute path." |
| 45 | + )), |
| 46 | + input_schema: Arc::new(object(json!( { |
| 47 | + "$schema": "https://json-schema.org/draft/2020-12/schema", |
| 48 | + "properties": { |
| 49 | + "command": { |
| 50 | + "description": "The bash string to execute.", |
| 51 | + "type": "string", |
| 52 | + }, |
| 53 | + "login": { |
| 54 | + "description": "Launch Bash with -lc instead of -c: defaults to true.", |
| 55 | + "nullable": true, |
| 56 | + "type": "boolean", |
| 57 | + }, |
| 58 | + "timeout_ms": { |
| 59 | + "description": "The timeout for the command in milliseconds.", |
| 60 | + "format": "uint64", |
| 61 | + "minimum": 0, |
| 62 | + "nullable": true, |
| 63 | + "type": "integer", |
| 64 | + }, |
| 65 | + "workdir": { |
| 66 | + "description": "The working directory to execute the command in. Must be an absolute path.", |
| 67 | + "type": "string", |
| 68 | + }, |
| 69 | + }, |
| 70 | + "required": [ |
| 71 | + "command", |
| 72 | + "workdir", |
| 73 | + ], |
| 74 | + "title": "ExecParams", |
| 75 | + "type": "object", |
| 76 | + }))), |
| 77 | + output_schema: None, |
| 78 | + annotations: None, |
| 79 | + icons: None, |
| 80 | + meta: None |
| 81 | + }], |
| 82 | + tools |
| 83 | + ); |
| 84 | + |
| 85 | + // TODO(mbolin): Make shell tool calls and verify they work. |
| 86 | + |
| 87 | + Ok(()) |
| 88 | +} |
0 commit comments