fix(mcp): skip plugins without an mcp/tools surface
This commit is contained in:
2 files changed
+50
-4
No files matched your search
@@ -510,9 +510,12 @@ pub async fn preview_plugin_tools(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// A plugin that implements no `mcp/tools` simply has no AI tools. Both
|
/// 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 {
|
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
|
/// 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 {
|
mod tests {
|
||||||
use super::*;
|
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 {
|
fn connection(id: &str, name: &str, plugin_id: &str) -> OpenPluginConnection {
|
||||||
OpenPluginConnection {
|
OpenPluginConnection {
|
||||||
connection_id: id.to_string(),
|
connection_id: id.to_string(),
|
||||||
|
|||||||
@@ -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 {
|
impl LocalBackend {
|
||||||
fn spawn_connection_lifecycle_watcher(
|
fn spawn_connection_lifecycle_watcher(
|
||||||
&self,
|
&self,
|
||||||
@@ -771,11 +782,21 @@ impl LocalBackend {
|
|||||||
if !plugin.compatibility.compatible || plugin.manifest.backend_entrypoint().is_none() {
|
if !plugin.compatibility.compatible || plugin.manifest.backend_entrypoint().is_none() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let tools: Value = self
|
let tools: Value = match self
|
||||||
.state
|
.state
|
||||||
.plugin_host
|
.plugin_host
|
||||||
.invoke(&plugin.manifest.id, "mcp/tools", json!({}), None, Some(std::time::Duration::from_secs(30)))
|
.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
|
let tool_list = tools
|
||||||
.get("tools")
|
.get("tools")
|
||||||
.cloned()
|
.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]
|
#[test]
|
||||||
fn legacy_read_only_overrides_configured_and_unconfigured_policies() {
|
fn legacy_read_only_overrides_configured_and_unconfigured_policies() {
|
||||||
// DBX_MCP_ALLOW_WRITES=0 always forces read_only, even when the
|
// DBX_MCP_ALLOW_WRITES=0 always forces read_only, even when the
|
||||||
|
|||||||
Reference in new issue
Block a user