diff --git a/crates/ide-host/src/mcp/files.rs b/crates/ide-host/src/mcp/files.rs index 2ea2944e4..57f5228cd 100644 --- a/crates/ide-host/src/mcp/files.rs +++ b/crates/ide-host/src/mcp/files.rs @@ -33,8 +33,10 @@ fn get_workspace_roots() -> Tool { "get_workspace_roots", "Returns the root directories of the IDE workspace: this project and the trusted projects attached to it in the same window, as absolute paths. A task works in one directory, but its workspace can hold several projects. -Call this when asked about the workspace, project or working directories, and before planning a change that may span -projects. Other tools reach an attached project by its root as `projectPath`.", +Call this before the first project-related operation in a session, and when asked about the workspace, project or +working directories. `projectRoot` is the project this connection serves, the default base for paths; `roots` is +every project in the workspace, the scope to search and read, not a list of projects to change. It doesn't change the +working directory or permissions. Other tools reach an attached project by its root as `projectPath`.", |call| async move { let root = call.root().to_path_buf(); let mut roots = vec![root.clone()]; diff --git a/crates/ide-mcp/src/protocol.rs b/crates/ide-mcp/src/protocol.rs index 11e9e8ed3..c78d446c9 100644 --- a/crates/ide-mcp/src/protocol.rs +++ b/crates/ide-mcp/src/protocol.rs @@ -168,8 +168,13 @@ impl Session<'_> { "instructions": format!( "Built-in OpenIDEA tools for {about}: they see the files as the IDE has them and, \ for a project open in a window, its editors. The project's workspace can include other \ - projects attached to it: call `get_workspace_roots` to list them before answering about \ - workspace directories or planning a change across projects." + projects attached to it, which a session's working directory doesn't show. Before the \ + first project-related operation in a session, call `get_workspace_roots`: its \ + `projectRoot` is the project this connection serves and the default base for paths, and \ + its `roots` are every project in the IDE workspace. That is the scope to search and read, \ + not a list of projects to change; it doesn't change your working directory or \ + permissions. Pass another root as `projectPath` to reach that project. Call it again \ + when the user switches projects or attaches one." ), }) } diff --git a/crates/ide-mcp/tests/server.rs b/crates/ide-mcp/tests/server.rs index eeb3a4295..21b4e7565 100644 --- a/crates/ide-mcp/tests/server.rs +++ b/crates/ide-mcp/tests/server.rs @@ -282,6 +282,8 @@ async fn a_folder_served_in_the_background_answers_initialize_list_and_call() { let init = rpc_for(&s, &inside, "initialize", json!({})).await; let instructions = init["result"]["instructions"].as_str().unwrap(); assert!(instructions.contains(inventory.to_str().unwrap()), "{instructions}"); + // Clients that load tool descriptions lazily still learn to establish the workspace first (#5751). + assert!(instructions.contains("first project-related operation in a session, call `get_workspace_roots`")); let list = rpc_for(&s, &inside, "tools/list", json!({})).await; assert_eq!(list["result"]["tools"][0]["description"], format!("Names {}", inventory.display()), "{list}"); let call = rpc_for(&s, &inside, "tools/call", json!({ "name": "where" })).await;