fix(mcp): skip plugins without an mcp/tools surface

This commit is contained in:
弈秋 authored and GitHub committed 2026-09-26 02:07:58 +08:00
1 parent 55a4b9f450
commit ea3cb4f38a
2 files changed
+50 -4

No files matched your search

+14 -2
View File
@@ -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(),