MCPcopy Index your code
hub / github.com/ChrisFeldmeier/OpenCodeRust / new

Method new

crates/opencode-mcp/src/transport.rs:32–62  ·  view source on GitHub ↗
(
        command: &str,
        args: &[String],
        env: Option<Vec<(String, String)>>,
    )

Source from the content-addressed store, hash-verified

30
31impl StdioTransport {
32 pub async fn new(
33 command: &str,
34 args: &[String],
35 env: Option<Vec<(String, String)>>,
36 ) -> Result<Self, McpClientError> {
37 let mut cmd = Command::new(command);
38 cmd.args(args)
39 .stdin(Stdio::piped())
40 .stdout(Stdio::piped())
41 .stderr(Stdio::piped())
42 .kill_on_drop(true);
43
44 if let Some(env_vars) = env {
45 for (key, value) in env_vars {
46 cmd.env(key, value);
47 }
48 }
49 let mut child = cmd.spawn().map_err(|e| {
50 McpClientError::TransportError(format!("Failed to spawn process: {}", e))
51 })?;
52
53 let stdin = child
54 .stdin
55 .take()
56 .ok_or_else(|| McpClientError::TransportError("Failed to get stdin".to_string()))?;
57
58 Ok(Self {
59 process: Mutex::new(Some(child)),
60 stdin: Mutex::new(Some(stdin)),
61 })
62 }
63}
64
65#[async_trait]

Callers

nothing calls this directly

Calls 2

newFunction · 0.85
spawnMethod · 0.80

Tested by

no test coverage detected