@@ -60,10 +60,7 @@ use crate::cli::chat::tools::custom_tool::{
6060 TransportType ,
6161} ;
6262use 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
6966macro_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