From ea3cb4f38ab078488945d3e8c3ae6c1413818ff1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=88=E7=A7=8B?= <49514152+yiqiui@users.noreply.github.com> Date: Sat, 26 Sep 2026 02:07:58 +0800 Subject: [PATCH] fix(mcp): skip plugins without an mcp/tools surface --- crates/dbx-core/src/ai/plugin_tools.rs | 16 +++++++++-- crates/dbx-mcp/src/backend.rs | 38 ++++++++++++++++++++++++-- 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/crates/dbx-core/src/ai/plugin_tools.rs b/crates/dbx-core/src/ai/plugin_tools.rs index 06becda776..e51df75612 100644 --- a/crates/dbx-core/src/ai/plugin_tools.rs +++ b/crates/dbx-core/src/ai/plugin_tools.rs @@ -510,9 +510,12 @@ pub async fn preview_plugin_tools( } /// A plugin that implements no `mcp/tools` simply has no AI tools. Both -/// official SDKs (and the host runtime) answer unknown methods with this text. +/// official SDKs (and the host runtime) answer unknown methods with either +/// phrasing, so accept both. fn lacks_tool_surface(error: &str) -> bool { - error.contains(&format!("Method not found: {PLUGIN_TOOLS_METHOD}")) + let lower = error.to_ascii_lowercase(); + lower.contains(&format!("method not found: {PLUGIN_TOOLS_METHOD}")) + || lower.contains(&format!("unknown method: {PLUGIN_TOOLS_METHOD}")) } /// Invokes a sidecar method, on `host_runtime` when given. Sidecar sessions @@ -919,6 +922,15 @@ fn truncate_chars(value: String, limit: usize) -> String { mod tests { use super::*; + #[test] + fn lacks_tool_surface_accepts_both_unknown_method_phrasings() { + assert!(lacks_tool_surface("Method not found: mcp/tools")); + assert!(lacks_tool_surface("unknown method: mcp/tools")); + assert!(lacks_tool_surface("rpc error: -32601: unknown method: mcp/tools (bridge)")); + assert!(!lacks_tool_surface("connection refused")); + assert!(!lacks_tool_surface("unknown method: mcp/other")); + } + fn connection(id: &str, name: &str, plugin_id: &str) -> OpenPluginConnection { OpenPluginConnection { connection_id: id.to_string(), diff --git a/crates/dbx-mcp/src/backend.rs b/crates/dbx-mcp/src/backend.rs index 1dbf4b097b..a07492c687 100644 --- a/crates/dbx-mcp/src/backend.rs +++ b/crates/dbx-mcp/src/backend.rs @@ -642,6 +642,17 @@ impl WebBackend { } } +/// Whether a sidecar error means "this plugin simply does not expose an MCP surface". +/// +/// `mcp/tools` is an optional host↔plugin bridge method introduced after many plugins were +/// published. A plugin that predates it answers with JSON-RPC `-32601` ("unknown method" / +/// "method not found"), which is the correct response, not a failure. MCP tool discovery must +/// skip such plugins instead of aborting the whole pass. +fn plugin_lacks_mcp_surface(err: &str) -> bool { + let lower = err.to_ascii_lowercase(); + lower.contains("unknown method") || lower.contains("method not found") || lower.contains("-32601") +} + impl LocalBackend { fn spawn_connection_lifecycle_watcher( &self, @@ -771,11 +782,21 @@ impl LocalBackend { if !plugin.compatibility.compatible || plugin.manifest.backend_entrypoint().is_none() { continue; } - let tools: Value = self + let tools: Value = match self .state .plugin_host .invoke(&plugin.manifest.id, "mcp/tools", json!({}), None, Some(std::time::Duration::from_secs(30))) - .await?; + .await + { + Ok(tools) => tools, + // A plugin that predates the optional `mcp/tools` bridge answers -32601; skip it + // instead of failing discovery for every other installed plugin. + Err(err) if plugin_lacks_mcp_surface(&err) => { + log::debug!("[mcp] plugin {} exposes no MCP tool surface: {}", plugin.manifest.id, err); + continue; + } + Err(err) => return Err(err), + }; let tool_list = tools .get("tools") .cloned() @@ -2706,6 +2727,19 @@ mod tests { } } + #[test] + fn plugin_lacks_mcp_surface_skips_unknown_method_but_keeps_real_errors() { + // The exact error a plugin that never implemented the optional mcp/tools bridge returns + // (e.g. com.yiqiui.leetcode-cn's JSON-RPC -32601 fallback). Discovery must skip these. + assert!(plugin_lacks_mcp_surface("unknown method: mcp/tools")); + assert!(plugin_lacks_mcp_surface("JSON-RPC error -32601: Method not found")); + assert!(plugin_lacks_mcp_surface("rpc error: code=-32601")); + // Genuine failures must still abort discovery, not be silently skipped. + assert!(!plugin_lacks_mcp_surface("connection refused")); + assert!(!plugin_lacks_mcp_surface("sidecar panicked")); + assert!(!plugin_lacks_mcp_surface("")); + } + #[test] fn legacy_read_only_overrides_configured_and_unconfigured_policies() { // DBX_MCP_ALLOW_WRITES=0 always forces read_only, even when the