Make tool failures actionable with suggestions and scope hints.

Unregistered tools now suggest close matches; MCP insufficient_scope is rewritten with fallbacks so ops agents stop blind-retrying SQL without sql:query.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
oliver 2026-08-10 22:42:37 +08:00
parent 229e8b1368
commit d245e463c0
6 changed files with 159 additions and 4 deletions

View file

@ -534,8 +534,14 @@ class ToolExecutor:
tool = ctx.tools.get(tc.name)
if not tool:
msg = f"Unregistered tool: {tc.name}" if ctx.lang.startswith("en") else f"未注册的工具: {tc.name}"
return {"ok": False, "error_code": "tool_not_registered", "error": msg}, int((time.perf_counter() - t0) * 1000)
from runtime.tools.tool_error_hints import format_unregistered_tool_error
available = [t.name for t in ctx.tools.list()] if hasattr(ctx.tools, "list") else []
return format_unregistered_tool_error(
str(tc.name or ""),
available,
lang=str(ctx.lang or "zh"),
), int((time.perf_counter() - t0) * 1000)
from runtime.tools.context_inject import enrich_tool_arguments
from runtime.tools.tool_validation import filter_arguments_to_schema