fix: sanitize server names for passing into model tool calls (#563)

This commit is contained in:
Kalvin C
2025-01-08 19:24:01 -08:00
committed by GitHub
parent cbbb25373b
commit c3cf4eec37
+15 -1
View File
@@ -19,6 +19,20 @@ pub struct Capabilities {
provider_usage: Mutex<Vec<ProviderUsage>>,
}
/// Sanitizes a string by replacing invalid characters with underscores.
/// Valid characters match [a-zA-Z0-9_-]
fn sanitize(input: String) -> String {
let mut result = String::with_capacity(input.len());
for c in input.chars() {
result.push(if c.is_ascii_alphanumeric() || c == '_' || c == '-' {
c
} else {
'_'
});
}
result
}
impl Capabilities {
/// Create a new Capabilities with the specified provider
pub fn new(provider: Box<dyn Provider>) -> Self {
@@ -64,7 +78,7 @@ impl Capabilities {
// Store the client
self.clients.insert(
init_result.server_info.name.clone(),
sanitize(init_result.server_info.name.clone()),
Arc::new(Mutex::new(client)),
);