fix(runtime): 修复 Skill/MCP 调用链路3个断点
Some checks failed
CI / Lint & TypeCheck (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Build Frontend (push) Has been cancelled
CI / Rust Check (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled

1. Anthropic Driver ToolResult 格式修复 — ContentBlock 添加 ToolResult 变体,
   tool_call_id 不再被丢弃, 按 Anthropic API 规范发送 tool_result 格式
2. 前端 callMcpTool 参数名对齐 — serviceName/toolName/args 改为
   service_name/tool_name/arguments, 后端支持 service_name 精确路由
3. MCP 工具桥接到 ToolRegistry — McpToolAdapter 添加 service_name/clone,
   新建 McpToolWrapper 实现 Tool trait, Kernel 添加 mcp_adapters 共享状态,
   McpManagerState 与 Kernel 共享同一 Arc<RwLock<Vec>>, MCP 服务启停时
   自动同步工具列表到 LLM 可见的 ToolRegistry
This commit is contained in:
iven
2026-04-11 16:20:38 +08:00
parent 2843bd204f
commit 9e0aa496cd
12 changed files with 389 additions and 29 deletions

View File

@@ -20,7 +20,9 @@ use crate::mcp::{McpClient, McpTool, McpToolCallRequest};
/// so we expose a simple trait here that mirrors the essential Tool interface.
/// The runtime side will wrap this in a thin `Tool` impl.
pub struct McpToolAdapter {
/// Tool name (prefixed with server name to avoid collisions)
/// Service name this tool belongs to
service_name: String,
/// Tool name (original from MCP server, NOT prefixed)
name: String,
/// Tool description
description: String,
@@ -30,9 +32,22 @@ pub struct McpToolAdapter {
client: Arc<dyn McpClient>,
}
impl McpToolAdapter {
pub fn new(tool: McpTool, client: Arc<dyn McpClient>) -> Self {
impl Clone for McpToolAdapter {
fn clone(&self) -> Self {
Self {
service_name: self.service_name.clone(),
name: self.name.clone(),
description: self.description.clone(),
input_schema: self.input_schema.clone(),
client: self.client.clone(),
}
}
}
impl McpToolAdapter {
pub fn new(service_name: String, tool: McpTool, client: Arc<dyn McpClient>) -> Self {
Self {
service_name,
name: tool.name,
description: tool.description,
input_schema: tool.input_schema,
@@ -41,16 +56,29 @@ impl McpToolAdapter {
}
/// Create adapters for all tools from an MCP server
pub async fn from_server(client: Arc<dyn McpClient>) -> Result<Vec<Self>> {
pub async fn from_server(service_name: String, client: Arc<dyn McpClient>) -> Result<Vec<Self>> {
let tools = client.list_tools().await?;
debug!(count = tools.len(), "Discovered MCP tools");
Ok(tools.into_iter().map(|t| Self::new(t, client.clone())).collect())
Ok(tools.into_iter().map(|t| Self::new(service_name.clone(), t, client.clone())).collect())
}
pub fn name(&self) -> &str {
&self.name
}
/// Full qualified name: service_name.tool_name (for ToolRegistry to avoid collisions)
pub fn qualified_name(&self) -> String {
format!("{}.{}", self.service_name, self.name)
}
pub fn service_name(&self) -> &str {
&self.service_name
}
pub fn tool_name(&self) -> &str {
&self.name
}
pub fn description(&self) -> &str {
&self.description
}
@@ -129,7 +157,7 @@ impl McpServiceManager {
name: String,
client: Arc<dyn McpClient>,
) -> Result<Vec<&McpToolAdapter>> {
let adapters = McpToolAdapter::from_server(client.clone()).await?;
let adapters = McpToolAdapter::from_server(name.clone(), client.clone()).await?;
self.clients.insert(name.clone(), client);
self.adapters.insert(name.clone(), adapters);
Ok(self.adapters.get(&name).unwrap().iter().collect())