From 8492607faea0f6d4098a7e3d1672d5f26094c8f0 Mon Sep 17 00:00:00 2001 From: "lilong.129" Date: Fri, 4 Jul 2025 21:01:40 +0800 Subject: [PATCH] fix: do not return error when timeout/timelimit for sleep tool --- examples/game/sudoku/game_sudoku.json | 2 +- examples/game/sudoku/main_test.go | 1 + uixt/mcp_tools_utility.go | 12 ++++++------ 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/examples/game/sudoku/game_sudoku.json b/examples/game/sudoku/game_sudoku.json index 01e0f53f..39c01329 100644 --- a/examples/game/sudoku/game_sudoku.json +++ b/examples/game/sudoku/game_sudoku.json @@ -63,7 +63,7 @@ "actions": [ { "method": "start_to_goal", - "params": "每天数独是一款逻辑推理游戏,玩家需要通过推理来确定黄色方块的所在位置,以下是游戏的基本规则说明:\n1、方块外面的数字代表所在那一行或一列的黄色方块数量。\n2、初始状态为白色方块,选择正确后变为黄色方块,选择错误后变为红底的 X。\n3、如果同一行或列有两个数字,则至少需要一个白底 X 分割它们作为间隔。\n4、如果数字与格子最大数相同时,该列或行必然全都是黄色方块。\n5、只能点击白色方块,不要重复点击同一个方块。\n\n请严格按照以上游戏规则,开始游戏\n", + "params": "每天数独是一款逻辑推理游戏,玩家需要通过推理来确定黄色方块的所在位置,以下是游戏的基本规则说明:\n1、方块外面的数字代表所在那一行或一列的黄色方块数量。\n2、初始状态为白色方块,选择正确后变为黄色方块,选择错误后变为红底的 X。\n3、如果同一行或列有两个数字,则至少需要一个白底 X 分割它们作为间隔。\n4、如果数字与格子最大数相同时,该列或行必然全都是黄色方块。\n5、只能点击白色方块,不要重复点击同一个方块。\n6、若出现「桌面入口」弹窗则直接关闭。\n\n请严格按照以上游戏规则,开始游戏\n", "options": { "time_limit": 300, "pre_mark_operation": true diff --git a/examples/game/sudoku/main_test.go b/examples/game/sudoku/main_test.go index a8830dae..9c68c2b7 100644 --- a/examples/game/sudoku/main_test.go +++ b/examples/game/sudoku/main_test.go @@ -16,6 +16,7 @@ func TestGameSudoku(t *testing.T) { 3、如果同一行或列有两个数字,则至少需要一个白底 X 分割它们作为间隔。 4、如果数字与格子最大数相同时,该列或行必然全都是黄色方块。 5、只能点击白色方块,不要重复点击同一个方块。 +6、若出现「桌面入口」弹窗则直接关闭。 请严格按照以上游戏规则,开始游戏 ` diff --git a/uixt/mcp_tools_utility.go b/uixt/mcp_tools_utility.go index e95a6907..4515edf4 100644 --- a/uixt/mcp_tools_utility.go +++ b/uixt/mcp_tools_utility.go @@ -75,9 +75,9 @@ func (t *ToolSleep) Implement() server.ToolHandlerFunc { case <-time.After(duration): // Normal completion case <-ctx.Done(): - // Interrupted by context cancellation (e.g., CTRL+C) - log.Warn().Msg("sleep interrupted by cancellation") - return nil, fmt.Errorf("sleep interrupted: %w", ctx.Err()) + // Interrupted by context cancellation (interrupt signal, timeout, time limit) + log.Info().Msg("sleep interrupted by context cancellation") + // Don't return error - let the upper layer handle timeout/time limit logic } message := fmt.Sprintf("Successfully slept for %v seconds", actualSeconds) @@ -157,9 +157,9 @@ func (t *ToolSleepMS) Implement() server.ToolHandlerFunc { case <-time.After(duration): // Normal completion case <-ctx.Done(): - // Interrupted by context cancellation (e.g., CTRL+C) - log.Warn().Msg("sleep interrupted by cancellation") - return nil, fmt.Errorf("sleep interrupted: %w", ctx.Err()) + // Interrupted by context cancellation (interrupt signal, timeout, time limit) + log.Info().Msg("sleep interrupted by context cancellation") + // Don't return error - let the upper layer handle timeout/time limit logic } message := fmt.Sprintf("Successfully slept for %d milliseconds", actualMilliseconds)