feat: friendly display for MCP tool names in frontend (#715)
- Format MCP tool names from "mcp_my_server_search_docs" to "My Server Search Docs" in the agent stream UI - Apply same formatting in sanitizeForDisplay for inline text - Update tool-icons.ts getToolDisplayName with MCP support
This commit is contained in:
@@ -69,6 +69,14 @@ const toolDisplayNameKeys: Record<string, string> = {
|
|||||||
// Get tool display name (user-friendly, localized)
|
// Get tool display name (user-friendly, localized)
|
||||||
export function getToolDisplayName(toolName: string): string {
|
export function getToolDisplayName(toolName: string): string {
|
||||||
const key = toolDisplayNameKeys[toolName];
|
const key = toolDisplayNameKeys[toolName];
|
||||||
return key ? t(key) : toolName;
|
if (key) return t(key);
|
||||||
|
|
||||||
|
// Format MCP tool names: "mcp_service_tool" → "Service Tool"
|
||||||
|
if (toolName.startsWith('mcp_')) {
|
||||||
|
const parts = toolName.slice(4).split('_');
|
||||||
|
return parts.map(p => p.charAt(0).toUpperCase() + p.slice(1)).join(' ');
|
||||||
|
}
|
||||||
|
|
||||||
|
return toolName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -423,7 +423,37 @@ const TOOL_NAME_KEYS: Record<string, string> = {
|
|||||||
const getLocalizedToolName = (toolName?: string | null): string => {
|
const getLocalizedToolName = (toolName?: string | null): string => {
|
||||||
if (!toolName) return t('agent.toolFallback');
|
if (!toolName) return t('agent.toolFallback');
|
||||||
const key = TOOL_NAME_KEYS[toolName];
|
const key = TOOL_NAME_KEYS[toolName];
|
||||||
return key ? t(key) : toolName;
|
if (key) return t(key);
|
||||||
|
|
||||||
|
// Format MCP tool names: "mcp_my_server_search_docs" → "My Server: search docs"
|
||||||
|
if (toolName.startsWith('mcp_')) {
|
||||||
|
return formatMCPToolName(toolName);
|
||||||
|
}
|
||||||
|
|
||||||
|
return toolName;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Format MCP tool name for friendly display.
|
||||||
|
* Input: "mcp_{service_name}_{tool_name}" (all lowercase, underscores)
|
||||||
|
* Output: "Service Name: tool name"
|
||||||
|
*/
|
||||||
|
const formatMCPToolName = (rawName: string): string => {
|
||||||
|
// Strip "mcp_" prefix
|
||||||
|
const rest = rawName.slice(4);
|
||||||
|
|
||||||
|
// Try to find the tool's original name from the event's tool_data or description.
|
||||||
|
// Since we only have the sanitized composite name, split heuristically:
|
||||||
|
// The service name comes first, tool name second, separated by "_".
|
||||||
|
// We look for common MCP tool name patterns at the end.
|
||||||
|
const parts = rest.split('_');
|
||||||
|
if (parts.length <= 1) return rest;
|
||||||
|
|
||||||
|
// Heuristic: tool names from MCP servers are typically 1-3 words like
|
||||||
|
// "search", "get_weather", "list_bugs". We try to find a reasonable split.
|
||||||
|
// For now, treat everything as a readable phrase.
|
||||||
|
const humanized = parts.map(p => p.charAt(0).toUpperCase() + p.slice(1)).join(' ');
|
||||||
|
return humanized;
|
||||||
};
|
};
|
||||||
|
|
||||||
const TOOL_NAME_DISPLAY: Record<string, string> = {
|
const TOOL_NAME_DISPLAY: Record<string, string> = {
|
||||||
@@ -455,6 +485,11 @@ const sanitizeForDisplay = (text: string): string => {
|
|||||||
for (const [name, display] of Object.entries(TOOL_NAME_DISPLAY)) {
|
for (const [name, display] of Object.entries(TOOL_NAME_DISPLAY)) {
|
||||||
result = result.replaceAll(name, display);
|
result = result.replaceAll(name, display);
|
||||||
}
|
}
|
||||||
|
// Format any remaining mcp_ tool names inline
|
||||||
|
result = result.replace(/\bmcp_([a-z0-9_]+)/g, (_match, rest) => {
|
||||||
|
const parts = rest.split('_');
|
||||||
|
return parts.map((p: string) => p.charAt(0).toUpperCase() + p.slice(1)).join(' ');
|
||||||
|
});
|
||||||
result = result.replace(ID_LABEL_RE, '');
|
result = result.replace(ID_LABEL_RE, '');
|
||||||
result = result.replace(UUID_RE, '');
|
result = result.replace(UUID_RE, '');
|
||||||
result = result.replace(/`\s*`/g, '');
|
result = result.replace(/`\s*`/g, '');
|
||||||
@@ -1566,6 +1601,8 @@ const getToolIcon = (toolName: string): string => {
|
|||||||
return fileAddIcon;
|
return fileAddIcon;
|
||||||
} else if (toolName === 'image_analysis') {
|
} else if (toolName === 'image_analysis') {
|
||||||
return thinkingIcon;
|
return thinkingIcon;
|
||||||
|
} else if (toolName.startsWith('mcp_')) {
|
||||||
|
return documentIcon; // MCP external tool icon
|
||||||
} else {
|
} else {
|
||||||
return documentIcon; // default icon
|
return documentIcon; // default icon
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user