mirror of
https://github.com/hanzoai/dev.git
synced 2026-10-25 03:32:32 +00:00
fix(core/mcp): allow per-call timeouts
This commit is contained in:
@@ -9,6 +9,7 @@ use mcp_types::CallToolResult;
|
||||
use std::collections::HashMap;
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
use std::time::Duration;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::config_types::{ClientTools, McpToolId};
|
||||
@@ -59,6 +60,7 @@ impl<'a> AcpFileSystem<'a> {
|
||||
&tool.mcp_server,
|
||||
&tool.tool_name,
|
||||
Some(serde_json::to_value(arguments).unwrap_or_default()),
|
||||
Some(Duration::from_secs(15)),
|
||||
)
|
||||
.await?;
|
||||
|
||||
@@ -96,6 +98,7 @@ impl<'a> AcpFileSystem<'a> {
|
||||
&tool.mcp_server,
|
||||
&tool.tool_name,
|
||||
Some(serde_json::to_value(arguments).unwrap_or_default()),
|
||||
Some(Duration::from_secs(15)),
|
||||
)
|
||||
.await?;
|
||||
|
||||
@@ -172,6 +175,7 @@ pub(crate) async fn request_permission(
|
||||
&permission_tool.mcp_server,
|
||||
&permission_tool.tool_name,
|
||||
Some(serde_json::to_value(arguments).unwrap_or_default()),
|
||||
Some(Duration::from_secs(15)),
|
||||
)
|
||||
.await?;
|
||||
|
||||
|
||||
@@ -2389,9 +2389,10 @@ impl Session {
|
||||
server: &str,
|
||||
tool: &str,
|
||||
arguments: Option<serde_json::Value>,
|
||||
timeout: Option<Duration>,
|
||||
) -> anyhow::Result<CallToolResult> {
|
||||
self.mcp_connection_manager
|
||||
.call_tool(server, tool, arguments)
|
||||
.call_tool(server, tool, arguments, timeout)
|
||||
.await
|
||||
}
|
||||
|
||||
|
||||
@@ -320,13 +320,14 @@ impl McpConnectionManager {
|
||||
server: &str,
|
||||
tool: &str,
|
||||
arguments: Option<serde_json::Value>,
|
||||
timeout_override: Option<Duration>,
|
||||
) -> Result<mcp_types::CallToolResult> {
|
||||
let managed = self
|
||||
.clients
|
||||
.get(server)
|
||||
.ok_or_else(|| anyhow!("unknown MCP server '{server}'"))?;
|
||||
let client = managed.client.clone();
|
||||
let timeout = managed.tool_timeout;
|
||||
let timeout = timeout_override.or(managed.tool_timeout);
|
||||
|
||||
client
|
||||
.call_tool(tool.to_string(), arguments, timeout)
|
||||
|
||||
@@ -51,7 +51,7 @@ pub(crate) async fn handle_mcp_tool_call(
|
||||
let start = Instant::now();
|
||||
// Perform the tool call.
|
||||
let result = sess
|
||||
.call_tool(&server, &tool_name, arguments_value.clone())
|
||||
.call_tool(&server, &tool_name, arguments_value.clone(), None)
|
||||
.await
|
||||
.map_err(|e| format!("tool call error: {e}"));
|
||||
let tool_call_end_event = EventMsg::McpToolCallEnd(McpToolCallEndEvent { call_id: ctx.call_id.clone(), invocation, duration: start.elapsed(), result: result.clone() });
|
||||
|
||||
Reference in New Issue
Block a user