diff --git a/crates/goose-mcp/src/developer/rmcp_developer.rs b/crates/goose-mcp/src/developer/rmcp_developer.rs index e77b5b6883ae..006c5a9c175a 100644 --- a/crates/goose-mcp/src/developer/rmcp_developer.rs +++ b/crates/goose-mcp/src/developer/rmcp_developer.rs @@ -21,6 +21,8 @@ use rmcp::{ const WORKING_DIR_HEADER: &str = "agent-working-dir"; const SESSION_ID_HEADER: &str = "agent-session-id"; +pub const WORKING_DIR_PLACEHOLDER: &str = "{{WORKING_DIR}}"; + fn extract_working_dir_from_meta(meta: &Meta) -> Option { meta.0 .get(WORKING_DIR_HEADER) @@ -242,8 +244,6 @@ pub struct DeveloperServer { impl ServerHandler for DeveloperServer { #[allow(clippy::too_many_lines)] fn get_info(&self) -> ServerInfo { - // Get base instructions and working directory - let cwd = std::env::current_dir().expect("should have a current working dir"); let os = std::env::consts::OS; let in_container = Self::is_definitely_container(); @@ -268,7 +268,7 @@ impl ServerHandler for DeveloperServer { {container_info} "#, os=os, - cwd=cwd.to_string_lossy(), + cwd=WORKING_DIR_PLACEHOLDER, container_info=if in_container { "container: true" } else { "" }, }, _ => { @@ -295,7 +295,7 @@ impl ServerHandler for DeveloperServer { {container_info} "#, os=os, - cwd=cwd.to_string_lossy(), + cwd=WORKING_DIR_PLACEHOLDER, shell=shell_info, container_info=if in_container { "container: true" } else { "" }, } diff --git a/crates/goose-mcp/src/lib.rs b/crates/goose-mcp/src/lib.rs index f9c47a5b8203..e1077683c982 100644 --- a/crates/goose-mcp/src/lib.rs +++ b/crates/goose-mcp/src/lib.rs @@ -20,6 +20,7 @@ pub mod tutorial; pub use autovisualiser::AutoVisualiserRouter; pub use computercontroller::ComputerControllerServer; pub use developer::rmcp_developer::DeveloperServer; +pub use developer::rmcp_developer::WORKING_DIR_PLACEHOLDER; pub use memory::MemoryServer; pub use tutorial::TutorialServer; diff --git a/crates/goose/src/agents/agent.rs b/crates/goose/src/agents/agent.rs index 9ed9f8838731..0663c7d6dc0e 100644 --- a/crates/goose/src/agents/agent.rs +++ b/crates/goose/src/agents/agent.rs @@ -1728,7 +1728,15 @@ impl Agent { ) -> Result { tracing::info!("Starting recipe creation with {} messages", messages.len()); - let extensions_info = self.extension_manager.get_extensions_info().await; + let session = self + .config + .session_manager + .get_session(session_id, false) + .await?; + let extensions_info = self + .extension_manager + .get_extensions_info(&session.working_dir) + .await; tracing::debug!("Retrieved {} extensions info", extensions_info.len()); let (extension_count, tool_count) = self .extension_manager diff --git a/crates/goose/src/agents/extension_manager.rs b/crates/goose/src/agents/extension_manager.rs index 0c9d645248a1..d77668cf4d34 100644 --- a/crates/goose/src/agents/extension_manager.rs +++ b/crates/goose/src/agents/extension_manager.rs @@ -791,17 +791,17 @@ impl ExtensionManager { } /// Get extensions info for building the system prompt - pub async fn get_extensions_info(&self) -> Vec { + pub async fn get_extensions_info(&self, working_dir: &std::path::Path) -> Vec { + let working_dir_str = working_dir.to_string_lossy(); self.extensions .lock() .await .iter() .map(|(name, ext)| { - ExtensionInfo::new( - name, - ext.get_instructions().unwrap_or_default().as_str(), - ext.supports_resources(), - ) + let instructions = ext.get_instructions().unwrap_or_default(); + let instructions = + instructions.replace(goose_mcp::WORKING_DIR_PLACEHOLDER, &working_dir_str); + ExtensionInfo::new(name, &instructions, ext.supports_resources()) }) .collect() } diff --git a/crates/goose/src/agents/reply_parts.rs b/crates/goose/src/agents/reply_parts.rs index 54e6d81ae8ed..a220a843a657 100644 --- a/crates/goose/src/agents/reply_parts.rs +++ b/crates/goose/src/agents/reply_parts.rs @@ -162,7 +162,10 @@ impl Agent { tools.sort_by(|a, b| a.name.cmp(&b.name)); // Prepare system prompt - let extensions_info = self.extension_manager.get_extensions_info().await; + let extensions_info = self + .extension_manager + .get_extensions_info(working_dir) + .await; let (extension_count, tool_count) = self .extension_manager .get_extension_and_tool_counts(session_id) diff --git a/crates/goose/tests/providers.rs b/crates/goose/tests/providers.rs index 0d3ff3a46eeb..b934cc857efa 100644 --- a/crates/goose/tests/providers.rs +++ b/crates/goose/tests/providers.rs @@ -120,7 +120,10 @@ impl ProviderTester { .await .expect("get_prefixed_tools failed"); - let info = self.extension_manager.get_extensions_info().await; + let info = self + .extension_manager + .get_extensions_info(std::path::Path::new(".")) + .await; let system = PromptManager::new() .builder() .with_extensions(info.into_iter())