Open-source LLM knowledge platform: turn raw documents into a queryable RAG, an autonomous reasoning agent, and a self-maintaining Wiki.
Go agentagenticaichatbotdsh-pluginembeddingsevaluationgenerative-aigolangknowledge-basellmmulti-tenantollamaopenaiquestion-answeringragrerankingsemantic-searchvector-searchwiki
fix(agent): show legacy empty MCP config as all in editor (#4558)
杰尼龟43068f0a9d2e
diff --git a/frontend/src/views/agent/AgentEditorModal.test.mjs b/frontend/src/views/agent/AgentEditorModal.test.mjsindex f6f635ed4..45f23cdd9 100644--- a/frontend/src/views/agent/AgentEditorModal.test.mjs+++ b/frontend/src/views/agent/AgentEditorModal.test.mjs@@ -1,6 +1,8 @@import assert from 'node:assert/strict'import { readFileSync } from 'node:fs'import test from 'node:test'+import { runInNewContext } from 'node:vm'+import { effectScope, nextTick, ref, watch } from 'vue'const source = readFileSync(new URL('./AgentEditorModal.vue', import.meta.url), 'utf8')@@ -185,3 +187,73 @@ test('retrieval strategy settings are hidden in agent mode, where search_knowledconst modeWatch = source.match(/watch\(isAgentMode, \(isAgent\) => \{([\s\S]*?)^\}\);/m)?.[1] ?? ''assert.match(modeWatch, /isAgent && \([^)]*currentSection\.value === 'retrieval'/)})++async function mcpFixture(t, config) {+ const init = source.match(/const initMcpSelectionMode = \(\) => \{[\s\S]*?^\};/m)?.[0]+ const start = source.indexOf('watch(mcpSelectionMode,')+ const end = source.indexOf('watch(() => formData.value.config.sandbox_config_id', start)+ assert.ok(init && start >= 0 && end > start, 'expected MCP initialization and watchers')+ const state = {+ watch,+ formData: ref({ config: { mcp_selection_mode: 'none', mcp_services: [] } }),+ loadedConfig: structuredClone(config),+ mcpSelectionMode: ref('none'),+ isInitializing: ref(true),+ }+ const scope = effectScope()+ t.after(() => scope.stop())+ // Run the component's actual initialization and watchers with Vue's scheduler.+ scope.run(() => runInNewContext(`${source.slice(start, end)}\n${init}\nformData.value = { config: loadedConfig };\ninitMcpSelectionMode();`, state))+ await nextTick(() => { state.isInitializing.value = false })+ return state+}++test('legacy empty MCP config opens as all without rewriting persisted config', async t => {+ const config = { mcp_selection_mode: '', mcp_services: [] }+ const state = await mcpFixture(t, config)+ assert.equal(state.mcpSelectionMode.value, 'all')+ assert.deepEqual(state.formData.value.config, config)+})++test('MCP hydration preserves saved modes and legacy service lists', async t => {+ for (const mode of ['', 'none', 'selected', 'all']) {+ const config = { mcp_selection_mode: mode, mcp_services: ['service-a'] }+ const state = await mcpFixture(t, config)+ assert.equal(state.mcpSelectionMode.value, mode || 'selected')+ assert.deepEqual(state.formData.value.config, config)+ }+})++test('editing a legacy service list persists selected mode without toggling the radio', async t => {+ const state = await mcpFixture(t, { mcp_selection_mode: '', mcp_services: ['service-a'] })+ assert.equal(state.mcpSelectionMode.value, 'selected')+ // t-select replaces the v-model array while leaving the radio unchanged.+ state.formData.value.config.mcp_services = ['service-b']+ await nextTick()+ assert.deepEqual(state.formData.value.config, {+ mcp_selection_mode: 'selected', mcp_services: ['service-b'],+ })+})++test('clearing a legacy service list persists selected with no services', async t => {+ const state = await mcpFixture(t, { mcp_selection_mode: '', mcp_services: ['service-a'] })+ state.formData.value.config.mcp_services.splice(0)+ await nextTick()+ assert.equal(state.formData.value.config.mcp_selection_mode, 'selected')+ assert.deepEqual(state.formData.value.config.mcp_services, [])+})++test('switching MCP modes still clears lists only for all and none', async t => {+ const state = await mcpFixture(t, { mcp_selection_mode: '', mcp_services: ['service-a'] })+ for (const mode of ['all', 'selected', 'none']) {+ state.mcpSelectionMode.value = mode+ await nextTick()+ assert.equal(state.formData.value.config.mcp_selection_mode, mode)+ assert.equal(state.formData.value.config.mcp_services.length, 0)+ if (mode === 'selected') {+ state.formData.value.config.mcp_services = ['service-b']+ await nextTick()+ assert.deepEqual(state.formData.value.config.mcp_services, ['service-b'])+ }+ }+})diff --git a/frontend/src/views/agent/AgentEditorModal.vue b/frontend/src/views/agent/AgentEditorModal.vueindex c3b5c98a0..60b24a181 100644--- a/frontend/src/views/agent/AgentEditorModal.vue+++ b/frontend/src/views/agent/AgentEditorModal.vue@@ -3820,7 +3820,10 @@ const initMcpSelectionMode = () => {// 有指定 MCP 服务mcpSelectionMode.value = 'selected';} else {- mcpSelectionMode.value = 'none';+ // Legacy configs with no mode run with every enabled MCP service for the+ // owner (registerMCPTools treats "" as "all"). Show that actual runtime+ // behaviour so the editor matches what the agent can call.+ mcpSelectionMode.value = 'all';}};@@ -3888,6 +3891,10 @@ watch(kbSelectionMode, (mode) => {// 监听 MCP 选择模式变化watch(mcpSelectionMode, (mode) => {+ // Hydration may map a legacy empty mode to "all" for display only; do not+ // persist that translation or clear the stored service list until the user+ // actually edits the MCP selection.+ if (isInitializing.value) return;formData.value.config.mcp_selection_mode = mode;if (mode === 'none') {// 不使用 MCP,清空相关配置@@ -3899,6 +3906,14 @@ watch(mcpSelectionMode, (mode) => {// selected 模式保持 mcp_services 不变});+// Editing a legacy list is an explicit selection even if the radio was+// already displayed as "selected". An empty list must also stay selected,+// since an unset mode would allow every enabled service at runtime.+watch(() => formData.value.config.mcp_services, () => {+ if (isInitializing.value || mcpSelectionMode.value !== 'selected') return;+ formData.value.config.mcp_selection_mode = 'selected';+}, { deep: true });+watch(() => formData.value.config.sandbox_config_id, async () => {if (!props.visible) returnawait syncInstalledSkills()