Fix(mcp): make terminal busy and cancel semantics usable by an agent
exec_command answered -32003 "device busy" with no way forward: the message named neither the occupying session nor how to free it, and mcp_cancel_session could only target in-flight calls, so a persistent terminal left behind by an earlier session blocked the host until its idle timer expired. An agent had no route back to a working state. Build the busy text from the live session table: terminal sessions now report parent session_id, idle and elapsed seconds, and point at terminal_exec (or terminal_close with id and session_id) when a persistent session holds the host, or at mcp_cancel_session(request_id) when the occupier is a running exec_command. exec_command sweeps idle terminals before it begins a pending wait, so a session abandoned after 300s does not require a terminal_* call first; SweepIdleTerminals now requires started so it cannot reclaim a session that is still in BeginTermPending and hand the device to a second caller. Cancel becomes addressable and honest. id=0 is rejected with -32602 instead of being treated as "all hosts", the calling request is excluded from matched and released (previously the poll saw itself and released was never true), rows carry cancellable, and when nothing was cancelled the reply lists what matched and which close tool takes it. Instructions, tool description, inputSchema (anyOf request_id/id/session_id) and the released description now agree: kind=call only, persistent sessions close by id+session_id, pending and file_transfer entries are released by cancelling the call that owns them. tools.json is regenerated for the schema and description changes. Debug server builds, check_platform_table.py and gen_go_tools.py --check pass; the Release instance was not rebuilt or restarted. Co-Authored-By: deepseek-flash
This commit is contained in:
1 parent
3d18b2119a
commit
42dd70fe20
2 files changed
+109
-12
No files matched your search
+19
-2
@@ -1255,7 +1255,7 @@
|
||||
},
|
||||
{
|
||||
"name": "mcp_cancel_session",
|
||||
"description": "取消在飞请求并尽快释放主机占用。给 request_id(tools/call 的 JSON-RPC id,类型要与调用时一致)精确取消一次调用,或按 id(主机)与 session_id 取消匹配的调用(两个都给则必须同时匹配)。工具层的等待在 ≤500ms 内退出并走既有清理路径;本工具最多等 2s,返回 cancelled(取消个数)、released(是否已释放占用)、waited_ms 与 matched(匹配到的会话)。被取消的请求以 -32800 结束。等价于对 SSE 流发 notifications/cancelled。",
|
||||
"description": "取消在飞请求并尽快释放主机占用。只能取消 kind=call 的在飞调用:给 request_id(tools/call 的 JSON-RPC id,类型要与调用时一致)精确取消一次,或按 id(主机,必须非 0)/ session_id 取消匹配的调用(两个都给则必须同时匹配)。取消一次卡住的调用会连带释放它持有的 pending / file_transfer 等待;持久会话本身不会被关闭,terminal / remote_control / chat 分别用 terminal_close / remote_close / chat_close(两者都要同时给 id 与 session_id)。工具层的等待在 ≤500ms 内退出并走既有清理路径;本工具最多等 2s,返回 cancelled(真正取消的调用个数,不含本工具自身)、released(这些调用是否已释放占用)、waited_ms 与 matched(匹配到的所有会话,每项带 cancellable)。被取消的请求以 -32800 结束。等价于对 SSE 流发 notifications/cancelled。",
|
||||
"gate": null,
|
||||
"platforms": [
|
||||
"win",
|
||||
@@ -1265,6 +1265,23 @@
|
||||
],
|
||||
"impl": "mfc",
|
||||
"inputSchema": {
|
||||
"anyOf": [
|
||||
{
|
||||
"required": [
|
||||
"request_id"
|
||||
]
|
||||
},
|
||||
{
|
||||
"required": [
|
||||
"id"
|
||||
]
|
||||
},
|
||||
{
|
||||
"required": [
|
||||
"session_id"
|
||||
]
|
||||
}
|
||||
],
|
||||
"properties": {
|
||||
"id": {
|
||||
"description": "主机 id:取消该主机上所有在飞请求",
|
||||
@@ -1296,7 +1313,7 @@
|
||||
"type": "array"
|
||||
},
|
||||
"released": {
|
||||
"description": "2s 内匹配的会话是否已从服务端表中消失(主机已松开)",
|
||||
"description": "2s 内被取消的在飞调用(kind=call,不含本工具自身)是否已从服务端表中消失(主机已松开)",
|
||||
"type": "boolean"
|
||||
},
|
||||
"waited_ms": {
|
||||
|
||||
Reference in new issue
Block a user