Skip to content
Merged
Show file tree
Hide file tree
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 Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/goose-mcp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ oauth2 = { version = "5.0.0", features = ["reqwest"] }
utoipa = { version = "4.1", optional = true }
hyper = "1"
serde_with = "3"
which = "6.0"


[dev-dependencies]
Expand Down
32 changes: 22 additions & 10 deletions crates/goose-mcp/src/computercontroller/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -736,10 +736,7 @@ impl ComputerControllerRouter {
ToolError::ExecutionError(format!("Failed to write script: {}", e))
})?;

format!(
"powershell -NoProfile -NonInteractive -File {}",
script_path.display()
)
script_path.display().to_string()
}
_ => {
return Err( ToolError::InvalidParameters(
Expand All @@ -749,12 +746,27 @@ impl ComputerControllerRouter {
};

// Run the script
let output = Command::new(shell)
.arg(shell_arg)
.arg(&command)
.output()
.await
.map_err(|e| ToolError::ExecutionError(format!("Failed to run script: {}", e)))?;
let output = match language {
"powershell" => {
// For PowerShell, we need to use -File instead of -Command
Command::new("powershell")
.arg("-NoProfile")
.arg("-NonInteractive")
.arg("-File")
.arg(&command)
.output()
.await
.map_err(|e| {
ToolError::ExecutionError(format!("Failed to run script: {}", e))
})?
}
_ => Command::new(shell)
.arg(shell_arg)
.arg(&command)
.output()
.await
.map_err(|e| ToolError::ExecutionError(format!("Failed to run script: {}", e)))?,
};

let output_str = String::from_utf8_lossy(&output.stdout).into_owned();
let error_str = String::from_utf8_lossy(&output.stderr).into_owned();
Expand Down
10 changes: 3 additions & 7 deletions crates/goose-mcp/src/developer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@ use mcp_server::Router;
use mcp_core::role::Role;

use self::editor_models::{create_editor_model, EditorModel};
use self::shell::{
expand_path, format_command_for_platform, get_shell_config, is_absolute_path,
normalize_line_endings,
};
use self::shell::{expand_path, get_shell_config, is_absolute_path, normalize_line_endings};
use indoc::indoc;
use std::process::Stdio;
use std::sync::{Arc, Mutex};
Expand Down Expand Up @@ -540,16 +537,15 @@ impl DeveloperRouter {

// Get platform-specific shell configuration
let shell_config = get_shell_config();
let cmd_str = format_command_for_platform(command);

// Execute the command using platform-specific shell
let mut child = Command::new(&shell_config.executable)
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.stdin(Stdio::null())
.kill_on_drop(true)
.arg(&shell_config.arg)
.arg(cmd_str)
.args(&shell_config.args)
.arg(command)
.spawn()
.map_err(|e| ToolError::ExecutionError(e.to_string()))?;

Expand Down
66 changes: 50 additions & 16 deletions crates/goose-mcp/src/developer/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,72 @@ use std::env;
#[derive(Debug, Clone)]
pub struct ShellConfig {
pub executable: String,
pub arg: String,
pub args: Vec<String>,
}

impl Default for ShellConfig {
fn default() -> Self {
if cfg!(windows) {
// Execute PowerShell commands directly
Self {
executable: "powershell.exe".to_string(),
arg: "-NoProfile -NonInteractive -Command".to_string(),
// Detect the default shell on Windows
#[cfg(windows)]
{
Self::detect_windows_shell()
}
#[cfg(not(windows))]
{
// This branch should never be taken on non-Windows
// but we need it for compilation
Self {
executable: "cmd".to_string(),
args: vec!["/c".to_string()],
}
}
} else {
// Use bash on Unix/macOS (keep existing behavior)
Self {
executable: "bash".to_string(),
arg: "-c".to_string(),
args: vec!["-c".to_string()],
}
}
}
}

pub fn get_shell_config() -> ShellConfig {
ShellConfig::default()
impl ShellConfig {
#[cfg(windows)]
fn detect_windows_shell() -> Self {
// Check for PowerShell first (more modern)
if let Ok(ps_path) = which::which("pwsh") {
// PowerShell 7+ (cross-platform PowerShell)
Self {
executable: ps_path.to_string_lossy().to_string(),
args: vec![
"-NoProfile".to_string(),
"-NonInteractive".to_string(),
"-Command".to_string(),
],
}
} else if let Ok(ps_path) = which::which("powershell") {
// Windows PowerShell 5.1
Self {
executable: ps_path.to_string_lossy().to_string(),
args: vec![
"-NoProfile".to_string(),
"-NonInteractive".to_string(),
"-Command".to_string(),
],
}
} else {
// Fall back to cmd.exe
Self {
executable: "cmd".to_string(),
args: vec!["/c".to_string()],
}
}
}
}

pub fn format_command_for_platform(command: &str) -> String {
if cfg!(windows) {
// For PowerShell, wrap the command in braces to handle special characters
format!("{{ {} }}", command)
} else {
// For other shells, no braces needed
command.to_string()
}
pub fn get_shell_config() -> ShellConfig {
ShellConfig::default()
}

pub fn expand_path(path_str: &str) -> String {
Expand Down
Loading