Skip to content

Commit c90c87d

Browse files
authored
changes how mcp command gets expanded (#2940)
1 parent 46403c1 commit c90c87d

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

crates/chat-cli/src/mcp_client/client.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,7 @@ use crate::cli::chat::tools::custom_tool::{
6060
TransportType,
6161
};
6262
use crate::os::Os;
63-
use crate::util::directories::{
64-
DirectoryError,
65-
canonicalizes_path,
66-
};
63+
use crate::util::directories::DirectoryError;
6764

6865
/// Fetches all pages of specified resources from a server
6966
macro_rules! paginated_fetch {
@@ -153,6 +150,8 @@ pub enum McpClientError {
153150
Auth(#[from] crate::auth::AuthError),
154151
#[error("{0}")]
155152
MalformedConfig(&'static str),
153+
#[error(transparent)]
154+
LookUp(#[from] shellexpand::LookupError<std::env::VarError>),
156155
}
157156

158157
/// Decorates the method passed in with retry logic, but only if the [RunningService] has an
@@ -527,8 +526,11 @@ impl McpClientService {
527526

528527
match r#type {
529528
TransportType::Stdio => {
530-
let expanded_cmd = canonicalizes_path(os, command_as_str)?;
531-
let command = Command::new(expanded_cmd).configure(|cmd| {
529+
let context = |input: &str| Ok(os.env.get(input).ok());
530+
let home_dir = || os.env.home().map(|p| p.to_string_lossy().to_string());
531+
let expanded_cmd = shellexpand::full_with_context(command_as_str, home_dir, context)?;
532+
533+
let command = Command::new(expanded_cmd.as_ref() as &str).configure(|cmd| {
532534
if let Some(envs) = config_envs {
533535
process_env_vars(envs, &os.env);
534536
cmd.envs(envs);

0 commit comments

Comments
 (0)