Skip to content

Commit bbf73c2

Browse files
committed
fix(settings): 调整MCP循环默认值
说明: - 将 MCP 工具循环默认上限从 10 提升到 100,降低复杂任务误触发 loop exceeded 的概率。 - 前后端共用默认值常量,空值回退保持与设置默认一致。 操作: - 已手动配置过最大循环次数的用户不会被覆盖。 Closes #104
1 parent 8c1e57e commit bbf73c2

6 files changed

Lines changed: 20 additions & 13 deletions

File tree

src-tauri/crates/core/src/types.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ where
1010
Option::<T>::deserialize(deserializer).map(Some)
1111
}
1212

13+
pub const DEFAULT_MCP_TOOL_LOOP_MAX_ITERATIONS: u32 = 100;
14+
1315
// === Provider System ===
1416

1517
#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -847,7 +849,7 @@ impl Default for AppSettings {
847849
inherit_conversation_preferences_on_create: true,
848850
chat_stream_first_packet_timeout_secs: 180,
849851
chat_stream_idle_timeout_secs: 90,
850-
mcp_tool_loop_max_iterations: 10,
852+
mcp_tool_loop_max_iterations: DEFAULT_MCP_TOOL_LOOP_MAX_ITERATIONS,
851853
document_attachment_reading_enabled: false,
852854
show_image_models_in_model_selector: false,
853855
multi_model_display_mode: "tabs".to_string(),
@@ -907,9 +909,9 @@ mod app_settings_tests {
907909
}
908910

909911
#[test]
910-
fn mcp_tool_loop_max_iterations_defaults_to_10_and_roundtrips() {
912+
fn mcp_tool_loop_max_iterations_defaults_to_100_and_roundtrips() {
911913
let settings = AppSettings::default();
912-
assert_eq!(settings.mcp_tool_loop_max_iterations, 10);
914+
assert_eq!(settings.mcp_tool_loop_max_iterations, 100);
913915

914916
let settings: AppSettings = serde_json::from_value(json!({
915917
"mcp_tool_loop_max_iterations": 25
@@ -920,7 +922,7 @@ mod app_settings_tests {
920922

921923
let settings: AppSettings =
922924
serde_json::from_value(json!({})).expect("settings should default missing fields");
923-
assert_eq!(settings.mcp_tool_loop_max_iterations, 10);
925+
assert_eq!(settings.mcp_tool_loop_max_iterations, 100);
924926
}
925927

926928
#[test]

src-tauri/src/commands/conversations.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5170,7 +5170,7 @@ mod tests {
51705170
#[test]
51715171
fn mcp_tool_loop_limit_clamps_global_settings() {
51725172
let mut settings = AppSettings::default();
5173-
assert_eq!(mcp_tool_loop_max_iterations_from_settings(&settings), 10);
5173+
assert_eq!(mcp_tool_loop_max_iterations_from_settings(&settings), 100);
51745174

51755175
settings.mcp_tool_loop_max_iterations = 0;
51765176
assert_eq!(mcp_tool_loop_max_iterations_from_settings(&settings), 1);

src/components/settings/ConversationSettings.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Divider, Input, InputNumber, Switch, theme } from 'antd';
22
import { useTranslation } from 'react-i18next';
33
import { useSettingsStore } from '@/stores';
4+
import { DEFAULT_MCP_TOOL_LOOP_MAX_ITERATIONS } from '@/types';
45
import { SettingsGroup } from './SettingsGroup';
56
import { SettingsSelect } from './SettingsSelect';
67

@@ -13,8 +14,10 @@ function normalizeTimeoutSeconds(value: number | string | null) {
1314
}
1415

1516
function normalizeMcpToolLoopMaxIterations(value: number | string | null) {
16-
const numericValue = typeof value === 'number' ? value : Number(value ?? 10);
17-
if (!Number.isFinite(numericValue)) return 10;
17+
const numericValue = typeof value === 'number'
18+
? value
19+
: Number(value ?? DEFAULT_MCP_TOOL_LOOP_MAX_ITERATIONS);
20+
if (!Number.isFinite(numericValue)) return DEFAULT_MCP_TOOL_LOOP_MAX_ITERATIONS;
1821
return Math.min(100, Math.max(1, Math.floor(numericValue)));
1922
}
2023

@@ -219,7 +222,7 @@ export function ConversationSettings() {
219222
min={1}
220223
max={100}
221224
step={1}
222-
value={settings.mcp_tool_loop_max_iterations ?? 10}
225+
value={settings.mcp_tool_loop_max_iterations ?? DEFAULT_MCP_TOOL_LOOP_MAX_ITERATIONS}
223226
onChange={(value) => saveSettings({
224227
mcp_tool_loop_max_iterations: normalizeMcpToolLoopMaxIterations(value),
225228
})}

src/components/settings/__tests__/ConversationSettings.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ describe('ConversationSettings', () => {
132132
show_image_models_in_model_selector: false,
133133
chat_stream_first_packet_timeout_secs: 180,
134134
chat_stream_idle_timeout_secs: 90,
135-
mcp_tool_loop_max_iterations: 10,
135+
mcp_tool_loop_max_iterations: 100,
136136
chat_sidebar_collapsed: false,
137137
};
138138
});
@@ -230,7 +230,7 @@ describe('ConversationSettings', () => {
230230

231231
fireEvent.change(screen.getByLabelText('MCP 工具调用最大轮次'), { target: { value: '' } });
232232
expect(mocks.saveSettings).toHaveBeenCalledWith({
233-
mcp_tool_loop_max_iterations: 10,
233+
mcp_tool_loop_max_iterations: 100,
234234
});
235235

236236
fireEvent.change(screen.getByLabelText('MCP 工具调用最大轮次'), { target: { value: '1000' } });

src/stores/settingsStore.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { create } from 'zustand';
22
import { invoke } from '@/lib/invoke';
3-
import type { AppSettings } from '@/types';
3+
import { DEFAULT_MCP_TOOL_LOOP_MAX_ITERATIONS, type AppSettings } from '@/types';
44
import { DEFAULT_SHORTCUT_BINDINGS } from '@/lib/shortcuts';
55

66
const DEFAULT_SETTINGS: AppSettings = {
@@ -89,7 +89,7 @@ const DEFAULT_SETTINGS: AppSettings = {
8989
inherit_conversation_preferences_on_create: true,
9090
chat_stream_first_packet_timeout_secs: 180,
9191
chat_stream_idle_timeout_secs: 90,
92-
mcp_tool_loop_max_iterations: 10,
92+
mcp_tool_loop_max_iterations: DEFAULT_MCP_TOOL_LOOP_MAX_ITERATIONS,
9393
document_attachment_reading_enabled: false,
9494
show_image_models_in_model_selector: false,
9595
multi_model_display_mode: 'tabs',

src/types/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,8 @@ export interface GatewaySettings {
456456
}
457457

458458
// === Settings ===
459+
export const DEFAULT_MCP_TOOL_LOOP_MAX_ITERATIONS = 100;
460+
459461
export interface AppSettings {
460462
language: string;
461463
theme_mode: string;
@@ -571,7 +573,7 @@ export interface AppSettings {
571573
chat_stream_first_packet_timeout_secs?: number;
572574
/** Timeout between chat stream packets in seconds. 0 disables. */
573575
chat_stream_idle_timeout_secs?: number;
574-
/** Maximum provider/tool iterations in one MCP tool loop. Default: 10. */
576+
/** Maximum provider/tool iterations in one MCP tool loop. Default: 100. */
575577
mcp_tool_loop_max_iterations?: number;
576578
/** Parse PDF/DOC/DOCX attachments and send extracted text to the model. Default: false */
577579
document_attachment_reading_enabled?: boolean;

0 commit comments

Comments
 (0)