From 2d7df693681d47bbd5c09eae7dee45e07b3c8e1e Mon Sep 17 00:00:00 2001 From: Dustin Healy <54083382+dustinhealy@users.noreply.github.com> Date: Wed, 18 Nov 2026 13:07:29 -0800 Subject: [PATCH] fix: Observe MCP Tools in the Visible Agent Builder (#17534) --- .../Agents/AgentPanelSwitch.spec.tsx | 5 +- .../SidePanel/Agents/AgentPanelSwitch.tsx | 4 +- e2e/config/librechat.e2e.yaml | 7 +++ e2e/specs/mock/mcp.spec.ts | 50 +++++++++++++++++++ 4 files changed, 61 insertions(+), 5 deletions(-) diff --git a/client/src/components/SidePanel/Agents/AgentPanelSwitch.spec.tsx b/client/src/components/SidePanel/Agents/AgentPanelSwitch.spec.tsx index 1c4fc6947d..4395727ac2 100644 --- a/client/src/components/SidePanel/Agents/AgentPanelSwitch.spec.tsx +++ b/client/src/components/SidePanel/Agents/AgentPanelSwitch.spec.tsx @@ -60,12 +60,13 @@ describe('AgentPanelSwitch authorization observers', () => { expect(mockObserveToolAuthorization).toHaveBeenLastCalledWith(true); }); - it('keeps observers disabled for a hydrated ephemeral agent', () => { + it('enables builder observers while chatting with an ephemeral agent', () => { renderWithConversation({ conversationId: 'new', endpoint: EModelEndpoint.agents, agent_id: 'ephemeral', } as TConversation); - expect(mockObserveToolAuthorization).toHaveBeenLastCalledWith(false); + expect(mockObserveToolAuthorization).toHaveBeenLastCalledWith(true); + expect(mockSetCurrentAgentId).not.toHaveBeenCalled(); }); }); diff --git a/client/src/components/SidePanel/Agents/AgentPanelSwitch.tsx b/client/src/components/SidePanel/Agents/AgentPanelSwitch.tsx index da67bae3a5..9f6354ea81 100644 --- a/client/src/components/SidePanel/Agents/AgentPanelSwitch.tsx +++ b/client/src/components/SidePanel/Agents/AgentPanelSwitch.tsx @@ -10,9 +10,7 @@ export default function AgentPanelSwitch() { const conversation = useRecoilValue(store.conversationByIndex(0)); const agentId = conversation?.agent_id ?? null; return ( - + ); diff --git a/e2e/config/librechat.e2e.yaml b/e2e/config/librechat.e2e.yaml index 14c49333a8..06cb615a98 100644 --- a/e2e/config/librechat.e2e.yaml +++ b/e2e/config/librechat.e2e.yaml @@ -436,6 +436,13 @@ modelSpecs: endpoint: 'Mock Provider B' model: 'mock-model-b' + - name: 'e2e-builder-mcp' + label: 'E2E Builder MCP' + hideBadgeRow: true + preset: + endpoint: 'Mock Provider C' + model: 'mock-model-c' + - name: 'e2e-icon-spec' label: 'E2E Icon Spec' iconURL: '/assets/openai.svg' diff --git a/e2e/specs/mock/mcp.spec.ts b/e2e/specs/mock/mcp.spec.ts index 9f74f0f26a..b6784f22f4 100644 --- a/e2e/specs/mock/mcp.spec.ts +++ b/e2e/specs/mock/mcp.spec.ts @@ -13,6 +13,7 @@ import { fetchJson, getAccessToken, mockReply, + selectModelSpec, sendMessageAndWaitForCompletion, } from './helpers'; @@ -85,6 +86,55 @@ async function expectSelectedMCPServerTools(form: Locator) { } test.describe('agent builder MCP tools', () => { + test('discovers builder tools while the current chat uses an ephemeral agent', async ({ + page, + }) => { + await page.goto('/c/new'); + await selectModelSpec(page, 'E2E Builder MCP'); + // Start with a cold query cache and a model spec whose composer does not observe tools. + await page.reload(); + await expect(page.getByRole('button', { name: 'Select a model' }).first()).toContainText( + 'E2E Builder MCP', + ); + + const toolResponses: string[] = []; + page.on('response', (response) => { + const pathname = new URL(response.url()).pathname; + if (pathname === '/api/mcp/tools' || pathname === '/api/mcp/connection/status') { + toolResponses.push(pathname); + } + }); + const form = await openAgentBuilder(page, { navigate: false }); + await form.getByRole('button', { name: 'Add tools' }).click(); + const dialog = page.getByRole('dialog', { name: 'Tool Library' }); + await dialog.getByRole('textbox', { name: 'Search tools…' }).fill(MCP_SERVER_NAME); + const serverCard = dialog.getByRole('button', { name: new RegExp(MCP_SERVER_TITLE) }).first(); + await expect(serverCard).toBeVisible(); + + await serverCard.locator('..').getByRole('button', { name: 'Configure', exact: true }).click(); + const details = page.getByRole('dialog', { name: MCP_SERVER_TITLE, exact: true }); + await expect(details).toBeVisible(); + await expect.soft(details.getByText('Connected', { exact: true })).toBeVisible(); + await test.info().attach('builder-status', { + body: await page.screenshot({ + path: test.info().outputPath('builder-status.png'), + animations: 'disabled', + }), + contentType: 'image/png', + }); + + // This must be populated by the builder itself; prefetching the catalog through the + // test API or selecting a persistent chat agent would hide the regression. + await expect + .poll(() => toolResponses) + .toEqual(expect.arrayContaining(['/api/mcp/tools', '/api/mcp/connection/status'])); + await details.getByRole('button', { name: /^Close( dialog)?$/ }).click(); + await serverCard.click(); + await expect(serverCard).toHaveAttribute('aria-pressed', 'true'); + await dialog.getByRole('button', { name: /^Close( dialog)?$/ }).click(); + await expect(form.getByText(MCP_SERVER_TITLE, { exact: true })).toBeVisible(); + }); + test('creates an agent with MCP server tools and persists the selection', async ({ page }) => { test.setTimeout(120000);