Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stdio command path resolve #1386

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion crates/mcp-client/src/transport/stdio.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::collections::HashMap;
use std::sync::Arc;
use tokio::process::{Child, ChildStderr, ChildStdin, ChildStdout, Command};
use std::path::Path;

use async_trait::async_trait;
use mcp_core::protocol::JsonRpcMessage;
Expand Down Expand Up @@ -195,8 +196,26 @@ impl StdioTransport {
}
}

fn resolve_command_path(&self) -> Result<String, Error> {
let command = &self.command;
let path = Path::new(command);

if path.is_absolute() {
return Ok(command.to_string());
}

match std::env::current_dir() {
Ok(cwd) => {
let abs_path = cwd.join(path);
Ok(abs_path.to_string_lossy().into_owned())
}
Err(e) => Err(Error::StdioProcessError(format!("Failed to get current directory: {}", e)))
}
}

async fn spawn_process(&self) -> Result<(Child, ChildStdin, ChildStdout, ChildStderr), Error> {
let mut command = Command::new(&self.command);
let resolved_command = self.resolve_command_path()?;
let mut command = Command::new(&resolved_command);
command
.envs(&self.env)
.args(&self.args)
Expand Down