mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-11-17 05:20:55 +00:00
🏷️ fix: Show MCP Server Titles in the Tool Library (#17883)
* fix: Show MCP Server Titles in the Tool Library and Search by Them Tool Library cards and agent tool rows showed the MCP server's config key because buildCatalog named each item after it, and search could only match that key. Name items from the resolved title in server.metadata, falling back to the key. Search also matches the key through the item id, as the MCP Servers panel does, so existing key searches keep working. * test: Cover MCP Server Titles in the Tool Library and Agent Tool Rows * test: Find the E2E Memory Card and Row by Title in MCP Specs
This commit is contained in:
parent
ce35dc25e1
commit
99a7ded295
7 changed files with 136 additions and 6 deletions
|
|
@ -123,6 +123,26 @@ describe('buildCatalog', () => {
|
|||
}
|
||||
});
|
||||
|
||||
test('names MCP items by their resolved title while keeping the key as id', () => {
|
||||
const map = new Map();
|
||||
map.set('gh-tools-v2', {
|
||||
serverName: 'gh-tools-v2',
|
||||
isConfigured: true,
|
||||
tools: [],
|
||||
metadata: { name: 'GitHub', pluginKey: 'gh-tools-v2' },
|
||||
});
|
||||
const mcp = buildCatalog({ ...emptyInputs, mcpServersMap: map }).find((i) => i.kind === 'mcp');
|
||||
expect(mcp?.name).toBe('GitHub');
|
||||
expect(mcp?.id).toBe('gh-tools-v2');
|
||||
});
|
||||
|
||||
test('falls back to the server key when an MCP server has no metadata', () => {
|
||||
const map = new Map();
|
||||
map.set('everything', { serverName: 'everything', isConfigured: true, tools: [] });
|
||||
const mcp = buildCatalog({ ...emptyInputs, mcpServersMap: map }).find((i) => i.kind === 'mcp');
|
||||
expect(mcp?.name).toBe('everything');
|
||||
});
|
||||
|
||||
test('excludes consume-only MCP servers from the catalog', () => {
|
||||
const map = new Map();
|
||||
map.set('attachable', { serverName: 'attachable', isConfigured: true, tools: [] });
|
||||
|
|
|
|||
|
|
@ -43,6 +43,36 @@ describe('applyFilter', () => {
|
|||
expect(applyFilter(items, {}).length).toBe(4);
|
||||
});
|
||||
|
||||
describe('MCP servers', () => {
|
||||
const server: AgentItem = {
|
||||
kind: 'mcp',
|
||||
id: 'gh-tools-v2',
|
||||
name: 'GitHub',
|
||||
description: 'Repositories and issues',
|
||||
iconKey: 'mcp',
|
||||
server: {
|
||||
serverName: 'gh-tools-v2',
|
||||
tools: [],
|
||||
isConfigured: true,
|
||||
isConnected: false,
|
||||
metadata: makePlugin({ name: 'GitHub', pluginKey: 'gh-tools-v2' }),
|
||||
},
|
||||
toolCount: 0,
|
||||
};
|
||||
|
||||
test('search matches the title', () => {
|
||||
expect(applyFilter([server], { search: 'github' })).toEqual([server]);
|
||||
});
|
||||
|
||||
test('search still matches the server key', () => {
|
||||
expect(applyFilter([server], { search: 'gh-tools' })).toEqual([server]);
|
||||
});
|
||||
|
||||
test('search does not match the id of other item kinds', () => {
|
||||
expect(applyFilter(items, { search: 's2' })).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
test('search filters by name', () => {
|
||||
const result = applyFilter(items, { search: 'code' });
|
||||
expect(result.map((i) => i.id)).toEqual(['execute_code', 's1']);
|
||||
|
|
|
|||
|
|
@ -200,7 +200,7 @@ export function buildCatalog(inputs: BuildCatalogInputs): AgentItem[] {
|
|||
items.push({
|
||||
kind: 'mcp',
|
||||
id: name,
|
||||
name,
|
||||
name: server.metadata?.name ?? name,
|
||||
description: server.metadata?.description ?? '',
|
||||
iconKey: 'mcp',
|
||||
server,
|
||||
|
|
|
|||
|
|
@ -25,7 +25,11 @@ function getCategory(item: AgentItem): string | undefined {
|
|||
function matchesSearch(item: AgentItem, search: string): boolean {
|
||||
if (!search) return true;
|
||||
const term = search.toLowerCase();
|
||||
return item.name.toLowerCase().includes(term) || item.description.toLowerCase().includes(term);
|
||||
if (item.name.toLowerCase().includes(term) || item.description.toLowerCase().includes(term)) {
|
||||
return true;
|
||||
}
|
||||
/** An MCP item's name is its title, so its config key is only reachable through the id. */
|
||||
return item.kind === 'mcp' && item.id.toLowerCase().includes(term);
|
||||
}
|
||||
|
||||
function matchesKind(item: AgentItem, kind: ItemFilter['kind']): boolean {
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@ import {
|
|||
} from './helpers';
|
||||
|
||||
const MCP_SERVER_NAME = 'e2e-memory';
|
||||
/** The Tool Library and the agent's tool rows label the server by its config `title`. */
|
||||
const MCP_SERVER_TITLE = 'E2E Memory';
|
||||
const MCP_TOOL_NAME = 'remember_fact';
|
||||
const MCP_SERVER_TOOL_ID = `sys__server__sys_mcp_${MCP_SERVER_NAME}`;
|
||||
const MCP_TOOL_ID = `${MCP_TOOL_NAME}_mcp_${MCP_SERVER_NAME}`;
|
||||
|
|
@ -65,7 +67,9 @@ async function addMCPServerTools(page: Page, form: Locator) {
|
|||
await expect(dialog).toBeVisible();
|
||||
|
||||
await dialog.getByRole('textbox', { name: 'Search tools…' }).fill(MCP_SERVER_NAME);
|
||||
const serverCard = dialog.getByRole('button', { name: new RegExp(MCP_SERVER_NAME) }).first();
|
||||
const serverCard = dialog
|
||||
.getByRole('button', { name: new RegExp(`^${MCP_SERVER_TITLE}\\b`) })
|
||||
.first();
|
||||
await expect(serverCard).toBeVisible();
|
||||
|
||||
await serverCard.click();
|
||||
|
|
@ -73,11 +77,11 @@ async function addMCPServerTools(page: Page, form: Locator) {
|
|||
|
||||
await dialog.getByRole('button', { name: /^Close( dialog)?$/ }).click();
|
||||
await expect(dialog).toBeHidden();
|
||||
await expect(form.getByText(MCP_SERVER_NAME, { exact: true })).toBeVisible();
|
||||
await expect(form.getByText(MCP_SERVER_TITLE, { exact: true })).toBeVisible();
|
||||
}
|
||||
|
||||
async function expectSelectedMCPServerTools(form: Locator) {
|
||||
await expect(form.getByText(MCP_SERVER_NAME, { exact: true })).toBeVisible();
|
||||
await expect(form.getByText(MCP_SERVER_TITLE, { exact: true })).toBeVisible();
|
||||
}
|
||||
|
||||
test.describe('agent builder MCP tools', () => {
|
||||
|
|
|
|||
68
e2e/specs/mock/scenarios/mcp-server-titles.spec.ts
Normal file
68
e2e/specs/mock/scenarios/mcp-server-titles.spec.ts
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
import { expect, test } from '@playwright/test';
|
||||
import type { Locator, Page } from '@playwright/test';
|
||||
import { openAgentBuilder } from '../agents.helpers';
|
||||
|
||||
/** `librechat.e2e.yaml` gives this server a `title` that differs from its key. */
|
||||
const SERVER_KEY = 'e2e-memory';
|
||||
const SERVER_TITLE = 'E2E Memory';
|
||||
|
||||
async function openToolLibrary(page: Page): Promise<{ form: Locator; library: Locator }> {
|
||||
const form = await openAgentBuilder(page);
|
||||
await form.getByRole('button', { name: 'Add tools', exact: true }).click();
|
||||
const library = page.getByRole('dialog', { name: 'Tool Library', exact: true });
|
||||
await expect(library).toBeVisible();
|
||||
return { form, library };
|
||||
}
|
||||
|
||||
/** A card is a toggle button whose accessible name starts with the item's label. */
|
||||
function card(library: Locator, label: string): Locator {
|
||||
return library.getByRole('button', { name: new RegExp(`^${label}`) });
|
||||
}
|
||||
|
||||
function search(library: Locator): Locator {
|
||||
return library.getByRole('textbox', { name: 'Search tools…' });
|
||||
}
|
||||
|
||||
test.describe('MCP server titles in the Tool Library', () => {
|
||||
test('@scenario:tool-library-card-shows-mcp-title an MCP card is labelled with the server title, not its key', async ({
|
||||
page,
|
||||
}) => {
|
||||
test.setTimeout(120000);
|
||||
const { library } = await openToolLibrary(page);
|
||||
|
||||
await expect(card(library, SERVER_TITLE)).toBeVisible();
|
||||
await expect(card(library, SERVER_KEY)).toHaveCount(0);
|
||||
});
|
||||
|
||||
test('@scenario:tool-library-search-matches-mcp-title-and-key searching by the title or the key finds the server', async ({
|
||||
page,
|
||||
}) => {
|
||||
test.setTimeout(120000);
|
||||
const { library } = await openToolLibrary(page);
|
||||
|
||||
await search(library).fill(SERVER_TITLE);
|
||||
await expect(card(library, SERVER_TITLE)).toBeVisible();
|
||||
|
||||
await search(library).fill(SERVER_KEY);
|
||||
await expect(card(library, SERVER_TITLE)).toBeVisible();
|
||||
});
|
||||
|
||||
test('@scenario:agent-tool-row-shows-mcp-title an added MCP server is listed on the agent by its title', async ({
|
||||
page,
|
||||
}) => {
|
||||
test.setTimeout(120000);
|
||||
const { form, library } = await openToolLibrary(page);
|
||||
|
||||
const server = card(library, SERVER_TITLE);
|
||||
await server.click();
|
||||
await expect(server).toHaveAttribute('aria-pressed', 'true');
|
||||
await library.getByRole('button', { name: 'Close', exact: true }).click();
|
||||
await expect(library).toBeHidden();
|
||||
|
||||
const row = form
|
||||
.getByRole('listitem')
|
||||
.filter({ has: page.getByText(SERVER_TITLE, { exact: true }) });
|
||||
await expect(row).toBeVisible();
|
||||
await expect(form.getByText(SERVER_KEY, { exact: true })).toHaveCount(0);
|
||||
});
|
||||
});
|
||||
|
|
@ -4,6 +4,8 @@ import { openAgentBuilder } from '../agents.helpers';
|
|||
import { NEW_CHAT_PATH, fetchJson, getAccessToken } from '../helpers';
|
||||
|
||||
const MCP_SERVER_NAME = 'e2e-memory';
|
||||
/** The Tool Library labels the server by its config `title`. */
|
||||
const MCP_SERVER_TITLE = 'E2E Memory';
|
||||
const MCP_TOOL_ID = `remember_fact_mcp_${MCP_SERVER_NAME}`;
|
||||
/** WCAG 1.4.11: a graphical object owes 3:1 against what it sits on. */
|
||||
const MARK_FLOOR = 3;
|
||||
|
|
@ -179,7 +181,9 @@ test.describe('native tool verified mark', () => {
|
|||
const dialog = await openToolLibrary(page);
|
||||
await dialog.getByRole('textbox', { name: 'Search tools…' }).fill(MCP_SERVER_NAME);
|
||||
|
||||
const serverCard = dialog.getByRole('button', { name: new RegExp(MCP_SERVER_NAME) }).first();
|
||||
const serverCard = dialog
|
||||
.getByRole('button', { name: new RegExp(`^${MCP_SERVER_TITLE}\\b`) })
|
||||
.first();
|
||||
await expect(serverCard).toBeVisible();
|
||||
await expect(serverCard.locator('svg[aria-label="Native"]')).toHaveCount(0);
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue