fix: sort list_all() output in ToolRouter and PromptRouter for deterministic ordering (#665)

ToolRouter::list_all() and PromptRouter::list_all() iterate over a
HashMap, which returns items in non-deterministic order. Since list_all()
backs the tools/list and prompts/list MCP protocol responses, this causes
MCP clients to receive differently-ordered results across calls and
process restarts, leading to intermittent tool discovery failures.

Sort the output alphabetically by name to guarantee stable ordering.
This commit is contained in:
Peter 2026-02-17 15:37:17 +01:00 • committed by GitHub
commit 61ffba84b5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 59 additions and 2 deletions

View file

@ -187,7 +187,9 @@ where
}
pub fn list_all(&self) -> Vec<crate::model::Prompt> {
self.map.values().map(|item| item.attr.clone()).collect()
let mut prompts: Vec<_> = self.map.values().map(|item| item.attr.clone()).collect();
prompts.sort_by(|a, b| a.name.cmp(&b.name));
prompts
}
}

View file

@ -252,7 +252,9 @@ where
}
pub fn list_all(&self) -> Vec<crate::model::Tool> {
self.map.values().map(|item| item.attr.clone()).collect()
let mut tools: Vec<_> = self.map.values().map(|item| item.attr.clone()).collect();
tools.sort_by(|a, b| a.name.cmp(&b.name));
tools
}
/// Get a tool definition by name.