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
9 changes: 9 additions & 0 deletions crates/mcp-tools/src/domains/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5804,9 +5804,16 @@ fn current_dir_search_root() -> Option<String> {
best.map(|(_, _, normalized)| normalized)
}

/// The session's folder, when it is a checkout of the project being searched.
///
/// `session_project_id` is the project `init` resolved for that folder. On a
/// hosted gateway it is the only evidence: the local mapping and index cannot
/// be read there, and without it results were rooted at the project's stored
/// path, the folder of whichever machine first indexed it.
fn scoped_session_folder_path<'a>(
session_folder_path: Option<&'a str>,
session_folder_project_id: Option<Uuid>,
session_project_id: Option<Uuid>,
local_index_project_id: Option<Uuid>,
target_project_id: Option<Uuid>,
local_project_root: Option<&'a str>,
Expand All @@ -5817,6 +5824,7 @@ fn scoped_session_folder_path<'a>(
};

if session_folder_project_id == Some(target_project_id)
|| session_project_id == Some(target_project_id)
|| local_index_project_id == Some(target_project_id)
{
return Some(session_path);
Expand Down Expand Up @@ -11196,6 +11204,7 @@ impl SearchTool {
let scoped_session_folder_path = scoped_session_folder_path(
session_folder_path.as_deref(),
resolved_folder_project_id,
state.project_id,
local_index_project_id,
target_project_id,
local_project_root.as_deref(),
Expand Down
29 changes: 29 additions & 0 deletions crates/mcp-tools/src/domains/search_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4484,13 +4484,41 @@ mod auto_mode_tests {
Some("/srv/projects/mcp"),
Some(mcp),
Some(mcp),
Some(mcp),
Some(other_project),
Some("/srv/example-repo"),
),
None
);
}

#[test]
fn test_hosted_session_folder_roots_results_for_its_own_project() {
// A hosted gateway reads no local mapping or index; init resolved the
// session's folder to the project being searched, so results are
// rooted there, not at the folder of the machine that first indexed
// the project.
let project = uuid::Uuid::parse_str("22222222-2222-4222-8222-222222222222").unwrap();
let session = scoped_session_folder_path(
Some("/data/dev/maker/contextstream"),
None,
Some(project),
None,
Some(project),
None,
);
assert_eq!(session, Some("/data/dev/maker/contextstream"));
assert_eq!(
resolve_effective_folder_path(
session,
Some("/home/core/dev/maker/contextstream"),
None,
false,
),
Some("/data/dev/maker/contextstream".to_string())
);
}

#[test]
fn test_scoped_session_folder_path_keeps_nested_target_project_root() {
let canonical_project =
Expand All @@ -4500,6 +4528,7 @@ mod auto_mode_tests {
Some("/srv/example-repo/web"),
None,
None,
None,
Some(canonical_project),
Some("/srv/example-repo"),
),
Expand Down
Loading