fix(core/mcp): allow per-call timeouts

This commit is contained in:
James Peter
2025-09-28 07:46:47 +10:00
parent ed09ddd281
commit bd6aad0ba5
4 changed files with 9 additions and 3 deletions
+4
View File
@@ -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?;
+2 -1
View File
@@ -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
}
+2 -1
View File
@@ -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)
+1 -1
View File
@@ -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() });