mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Route hook MCP calls through current connections (#39331)
## What changed - Execute hook-triggered MCP calls through the runtime's latest connection set instead of preparing a separate catalog-bound call. - Keep hook calls from waiting for server startup or reconnecting, and reject disconnected servers immediately. - Apply the shorter of the hook-requested timeout and the server's configured tool timeout. ## Testing - Update connection manager tests to cover non-waiting calls and disabled tool filters. GitOrigin-RevId: 3166b2d1e26d9ae2b8b3a648b4d0897cc260eb93
This commit is contained in:
1 parent
67ed4e717a
commit
d35e5495f9
8 files changed
+84
-269
No files matched your search
@@ -53,6 +53,7 @@ use crate::tools::filter_tools;
|
||||
use anyhow::Context;
|
||||
use anyhow::Result;
|
||||
use anyhow::anyhow;
|
||||
use anyhow::bail;
|
||||
use codex_config::McpServerTransportConfig;
|
||||
use codex_diagnostics::Gauge;
|
||||
use codex_diagnostics::GaugeGuard;
|
||||
@@ -862,6 +863,8 @@ impl McpConnectionSet {
|
||||
tool: &str,
|
||||
arguments: Option<serde_json::Value>,
|
||||
meta: Option<serde_json::Value>,
|
||||
requested_timeout: Option<Duration>,
|
||||
wait_for_server: bool,
|
||||
) -> Result<CallToolResult> {
|
||||
let view = self
|
||||
.servers
|
||||
@@ -872,14 +875,32 @@ impl McpConnectionSet {
|
||||
"tool '{tool}' is disabled for MCP server '{server}'"
|
||||
));
|
||||
}
|
||||
let client = view
|
||||
.connection
|
||||
.client()
|
||||
.await
|
||||
.context("failed to get client")?;
|
||||
let client = if wait_for_server {
|
||||
view.connection
|
||||
.client()
|
||||
.await
|
||||
.context("failed to get client")?
|
||||
} else {
|
||||
let client = view
|
||||
.connection
|
||||
.client
|
||||
.ready_client()
|
||||
.ok_or_else(|| anyhow!("MCP server '{server}' is not connected"))?;
|
||||
if client.client.is_closed().await {
|
||||
bail!("MCP server '{server}' is not connected");
|
||||
}
|
||||
client
|
||||
};
|
||||
|
||||
let effective_timeout = match (view.tool_timeout, requested_timeout) {
|
||||
(Some(server_timeout), Some(requested_timeout)) => {
|
||||
Some(server_timeout.min(requested_timeout))
|
||||
}
|
||||
(server_timeout, requested_timeout) => server_timeout.or(requested_timeout),
|
||||
};
|
||||
let result: rmcp::model::CallToolResult = client
|
||||
.client
|
||||
.call_tool(tool.to_string(), arguments, meta, view.tool_timeout)
|
||||
.call_tool(tool.to_string(), arguments, meta, effective_timeout)
|
||||
.await
|
||||
.with_context(|| format!("tool call failed for `{server}/{tool}`"))?;
|
||||
|
||||
|
||||
Reference in new issue
Block a user