Soften short-intent gates and add tool-result refs plus MCP wire invalidate.

Prefer report tools without hard-hiding CLI, keep soft CLI budgets, store compact+result_ref for the model, and clear frozen wire after MCP sync.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
oliver 2026-08-12 21:48:05 +08:00
parent 3785e78a72
commit 605751b6a6
13 changed files with 636 additions and 65 deletions

View file

@ -85,6 +85,12 @@ def sync_mcp_server_tools(store: Any, row: dict[str, Any]) -> dict[str, Any] | N
store.replace_mcp_server_tools(server_id=sid, tools=tools)
detail = {"synced_tools": len(tools), "compat_mode": "bailian_webparser"}
store.set_mcp_server_health(server_id=sid, status="ok", detail=detail)
try:
from runtime.direct_loop import invalidate_tool_wire_cache
invalidate_tool_wire_cache(reason=f"mcp_sync:{sid}")
except Exception:
pass
return {"server_id": sid, "ok": True, "health": detail, "tools_synced": len(tools)}
rt = mcp_runtime_for_row(row, store=store)
@ -128,6 +134,12 @@ def sync_mcp_server_tools(store: Any, row: dict[str, Any]) -> dict[str, Any] | N
"health": health,
},
)
try:
from runtime.direct_loop import invalidate_tool_wire_cache
invalidate_tool_wire_cache(reason=f"mcp_sync:{sid}")
except Exception:
pass
return {
"server_id": sid,
"ok": True,

View file

@ -0,0 +1,56 @@
from __future__ import annotations
from typing import Any
from runtime.chat.tool_invocation_context import current_tool_lane_sessions
from runtime.chat.tool_result_store import load_tool_result_blob
from runtime.tools.base import ToolSpec
def fetch_tool_result_tool() -> ToolSpec:
def handler(args: dict[str, Any]) -> dict[str, Any]:
ref = str(args.get("result_ref") or "").strip()
if not ref:
return {"ok": False, "error_code": "result_ref_required", "error": "result_ref_required"}
owner, sid = current_tool_lane_sessions()
session_id = str(sid or owner or "").strip()
max_chars = args.get("max_chars")
try:
max_i = int(max_chars) if max_chars is not None else None
except Exception:
max_i = None
return load_tool_result_blob(ref, session_id=session_id, max_chars=max_i)
return ToolSpec(
name="fetch_tool_result",
description=(
"Fetch a previously truncated/guarded tool result by result_ref. "
"Use when a tool payload includes result_ref / _truncated_for_llm / _tool_result_guarded "
"and you need more detail than the compact preview."
),
parameters={
"type": "object",
"properties": {
"result_ref": {
"type": "string",
"description": "Opaque ref from a prior tool message (e.g. tr:…).",
},
"max_chars": {
"type": "integer",
"minimum": 4000,
"maximum": 500000,
"description": "Optional cap for returned JSON size (default ~120k).",
},
},
"required": ["result_ref"],
"additionalProperties": False,
},
handler=handler,
tags=frozenset({"system", "read", "tool_result"}),
read_only=True,
risk_level="low",
timeout_s=8.0,
)
__all__ = ["fetch_tool_result_tool"]