Skip to content

Commit 21f05dc

Browse files
committed
fix: align MCP tool display and search behavior in dashboard
- move quote import in MCPTool to module scope - use origin instead of name parsing for MCP tool icons - centralize tool display-name resolution in shared helper - centralize tool search matching for persona and component views - remove stale MCP-specific frontend search reference
1 parent 6ccecfd commit 21f05dc

6 files changed

Lines changed: 36 additions & 18 deletions

File tree

astrbot/core/agent/mcp_client.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from contextlib import AsyncExitStack
44
from datetime import timedelta
55
from typing import Generic
6+
from urllib.parse import quote
67

78
from tenacity import (
89
before_sleep_log,
@@ -381,8 +382,6 @@ def __init__(
381382
) -> None:
382383
# Add namespace prefix to avoid conflicts with plugin tools
383384
# URL-encode the server name to create a safe and unique identifier part
384-
from urllib.parse import quote
385-
386385
normalized_server_name = quote(mcp_server_name, safe="")
387386
# Format: mcp_<normalized_server_name>__<tool_name>
388387
namespaced_name = f"mcp_{normalized_server_name}__{mcp_tool.name}"

dashboard/src/components/extension/componentPanel/components/ToolTable.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const parameterEntries = (tool: ToolItem) => Object.entries(tool.parameters?.pro
4141
<template #item.name="{ item }">
4242
<div class="d-flex align-center py-2">
4343
<v-icon color="primary" class="mr-2" size="18">
44-
{{ item.name.includes(':') ? 'mdi-server-network' : 'mdi-function-variant' }}
44+
{{ item.origin === 'mcp' ? 'mdi-server-network' : 'mdi-function-variant' }}
4545
</v-icon>
4646
<div>
4747
<div class="text-subtitle-1 font-weight-medium">{{ item.display_name || item.name }}</div>

dashboard/src/components/extension/componentPanel/index.vue

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import { computed, onActivated, onMounted, ref, watch} from 'vue';
1616
import axios from 'axios';
1717
import { useModuleI18n } from '@/i18n/composables';
18+
import { matchesToolSearch } from '@/utils/toolDisplayName';
1819
1920
// Composables
2021
import { useComponentData } from './composables/useComponentData';
@@ -85,10 +86,7 @@ const {
8586
const filteredTools = computed(() => {
8687
const query = toolSearch.value.trim().toLowerCase();
8788
if (!query) return tools.value;
88-
return tools.value.filter(tool =>
89-
tool.name?.toLowerCase().includes(query) ||
90-
tool.description?.toLowerCase().includes(query)
91-
);
89+
return tools.value.filter(tool => matchesToolSearch(tool, query));
9290
});
9391
9492
// 处理切换指令状态

dashboard/src/components/shared/PersonaForm.vue

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ import {
329329
askForConfirmation as askForConfirmationDialog,
330330
useConfirmDialog
331331
} from '@/utils/confirmDialog';
332+
import { matchesToolSearch, resolveToolDisplayName } from '@/utils/toolDisplayName';
332333
333334
export default {
334335
name: 'PersonaForm',
@@ -405,12 +406,7 @@ export default {
405406
if (!this.toolSearch) {
406407
return this.availableTools;
407408
}
408-
const search = this.toolSearch.toLowerCase();
409-
return this.availableTools.filter(tool =>
410-
tool.name.toLowerCase().includes(search) ||
411-
(tool.description && tool.description.toLowerCase().includes(search)) ||
412-
(tool.mcp_server_name && tool.mcp_server_name.toLowerCase().includes(search))
413-
);
409+
return this.availableTools.filter(tool => matchesToolSearch(tool, this.toolSearch));
414410
},
415411
filteredSkills() {
416412
if (!this.skillSearch) {
@@ -821,9 +817,7 @@ export default {
821817
},
822818
823819
getToolDisplayName(toolName) {
824-
// Find tool in availableTools and return display_name if available
825-
const tool = this.availableTools.find(t => t.name === toolName);
826-
return tool?.display_name || toolName;
820+
return resolveToolDisplayName(toolName, this.availableTools);
827821
}
828822
}
829823
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import type { ToolItem } from '@/components/extension/componentPanel/types';
2+
3+
type ToolDisplayNameSource = Pick<ToolItem, 'name' | 'display_name'>;
4+
type ToolSearchSource = Pick<ToolItem, 'name' | 'display_name' | 'description' | 'origin' | 'origin_name'>;
5+
6+
export function resolveToolDisplayName(
7+
toolName: string,
8+
availableTools: ToolDisplayNameSource[] = []
9+
): string {
10+
const tool = availableTools.find(item => item.name === toolName);
11+
return tool?.display_name || toolName;
12+
}
13+
14+
export function matchesToolSearch(tool: ToolSearchSource, rawQuery: string): boolean {
15+
const query = rawQuery.trim().toLowerCase();
16+
if (!query) {
17+
return true;
18+
}
19+
20+
return [
21+
tool.display_name,
22+
tool.name,
23+
tool.description,
24+
tool.origin,
25+
tool.origin_name,
26+
].some(value => value?.toLowerCase().includes(query));
27+
}

dashboard/src/views/persona/PersonaManager.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ import {
281281
askForConfirmation as askForConfirmationDialog,
282282
useConfirmDialog
283283
} from '@/utils/confirmDialog';
284+
import { resolveToolDisplayName } from '@/utils/toolDisplayName';
284285
285286
import type { Folder, FolderTreeNode } from '@/components/folder/types';
286287
@@ -432,8 +433,7 @@ export default defineComponent({
432433
},
433434
434435
getToolDisplayName(toolName: string): string {
435-
const tool = this.availableTools.find(t => t.name === toolName);
436-
return tool?.display_name || toolName;
436+
return resolveToolDisplayName(toolName, this.availableTools);
437437
},
438438
439439
// Persona 操作

0 commit comments

Comments
 (0)