fix(mcp): fix empty args format + sanitize tool name (#7615)

* fix empty args format + sanitize tool name

* cleaning
This commit is contained in:
centdix
2026-01-19 21:24:12 +01:00
committed by GitHub
parent f33b79936b
commit f55dac6958
2 changed files with 17 additions and 3 deletions

View File

@@ -190,7 +190,7 @@ impl McpClient {
args_str: &str,
) -> Result<Option<serde_json::Map<String, serde_json::Value>>> {
if args_str.trim().is_empty() {
return Ok(None);
return Ok(Some(serde_json::Map::new()));
}
let args_value: serde_json::Value =
@@ -198,7 +198,7 @@ impl McpClient {
match args_value {
serde_json::Value::Object(map) => Ok(Some(map)),
serde_json::Value::Null => Ok(None),
serde_json::Value::Null => Ok(Some(serde_json::Map::new())),
_ => Ok(Some(
vec![("value".to_string(), args_value)]
.into_iter()

View File

@@ -351,6 +351,19 @@ pub async fn cleanup_mcp_clients(mcp_clients: HashMap<String, Arc<McpClient>>) {
}
}
#[cfg(feature = "mcp")]
fn sanitize_tool_name_part(s: &str) -> String {
s.chars()
.map(|c| {
if c.is_ascii_alphanumeric() || c == '_' || c == '-' {
c
} else {
'_'
}
})
.collect()
}
/// Convert raw MCP tools to Windmill Tool format with source tracking
#[cfg(feature = "mcp")]
fn convert_mcp_tools_to_windmill_tools(
@@ -361,7 +374,8 @@ fn convert_mcp_tools_to_windmill_tools(
mcp_tools
.iter()
.map(|mcp_tool| {
let tool_name = format!("mcp_{}_{}", resource_name, mcp_tool.name);
let sanitized_resource_name = sanitize_tool_name_part(resource_name);
let tool_name = format!("mcp_{}_{}", sanitized_resource_name, mcp_tool.name);
let mut schema_value = serde_json::to_value(&*mcp_tool.input_schema)
.context("Failed to convert MCP schema to JSON value")?;