Skip to content

Commit af717db

Browse files
authored
feat(ui): add per-connector tool access to composer (#115907)
* feat(ui): per-connector tool access in composer menu * fix(ui): harden tool access loading and dynamic keys * fix(ui): harden tool access reads and catalog freshness * fix(ui): invalidate tool catalog on connector edits * test(ui): fix composer capability checks
1 parent 68a3ca7 commit af717db

8 files changed

Lines changed: 729 additions & 23 deletions

‎ui/src/e2e/chat-composer-capability-menu.e2e.test.ts‎

Lines changed: 232 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,20 @@ function skill(
4141
};
4242
}
4343

44-
function sessionsList(toolOverrides?: Record<string, unknown>) {
44+
function sessionsList(
45+
toolOverrides?: Record<string, unknown>,
46+
model: { id: string; provider: string } = { id: "gpt-5.5", provider: "openai" },
47+
) {
4548
return {
4649
count: 1,
47-
defaults: { contextTokens: 200_000, model: "gpt-5.5", modelProvider: "openai" },
50+
defaults: { contextTokens: 200_000, model: model.id, modelProvider: model.provider },
4851
path: "",
4952
sessions: [
5053
{
5154
key: "main",
5255
kind: "direct",
53-
model: "gpt-5.5",
54-
modelProvider: "openai",
56+
model: model.id,
57+
modelProvider: model.provider,
5558
status: "done",
5659
updatedAt: Date.now(),
5760
...(toolOverrides ? { toolOverrides } : {}),
@@ -84,6 +87,59 @@ function configResponse(
8487
};
8588
}
8689

90+
function effectiveToolsResponse(serverName = "github") {
91+
return {
92+
agentId: "main",
93+
profile: "full",
94+
groups: [
95+
{
96+
id: "mcp",
97+
label: "MCP",
98+
source: "mcp",
99+
tools: [
100+
{
101+
id: "mcp_github_list_issues",
102+
label: "list_issues",
103+
description: "List issues",
104+
rawDescription: "List issues",
105+
source: "mcp",
106+
mcpServer: serverName,
107+
mcpToolName: "list-issues",
108+
},
109+
{
110+
id: "mcp_github_search_items_dash",
111+
label: "search_items",
112+
description: "Search items",
113+
rawDescription: "Search items",
114+
source: "mcp",
115+
mcpServer: serverName,
116+
mcpToolName: "search-items",
117+
},
118+
{
119+
id: "mcp_github_search_items_underscore",
120+
label: "search_items",
121+
description: "Search items",
122+
rawDescription: "Search items",
123+
source: "mcp",
124+
mcpServer: serverName,
125+
mcpToolName: "search_items",
126+
deniedBySession: true,
127+
},
128+
{
129+
id: "mcp_notion_delete_page",
130+
label: "delete_page",
131+
description: "Delete a page",
132+
rawDescription: "Delete a page",
133+
source: "mcp",
134+
mcpServer: "notion",
135+
mcpToolName: "delete_page",
136+
},
137+
],
138+
},
139+
],
140+
};
141+
}
142+
87143
async function latestToolOverrides(gateway: MockGatewayControls) {
88144
const requests = await gateway.getRequests("sessions.patch");
89145
return (requests.at(-1)?.params as { toolOverrides?: unknown } | undefined)?.toolOverrides;
@@ -99,9 +155,19 @@ function configPatchRaw(request: { params?: unknown }) {
99155

100156
async function openMenu(page: Page) {
101157
const composer = page.locator(".agent-chat__input");
102-
await composer.getByRole("button", { name: "Add attachment" }).click();
158+
const dropdown = composer.locator("wa-dropdown.agent-chat__capability-menu");
159+
const skills = composer.getByRole("menuitem", { name: "Skills" });
160+
const isOpen = await dropdown.evaluate((node) => (node as HTMLElement & { open: boolean }).open);
161+
if (!isOpen) {
162+
await composer.getByRole("button", { name: "Add attachment" }).click();
163+
}
103164
await expect
104-
.poll(() => composer.getByRole("menuitem", { name: "Skills" }).isVisible())
165+
.poll(async () => {
166+
const open = await dropdown.evaluate(
167+
(node) => (node as HTMLElement & { open: boolean }).open,
168+
);
169+
return open && (await skills.isVisible());
170+
})
105171
.toBe(true);
106172
return composer;
107173
}
@@ -277,6 +343,166 @@ describeControlUiE2e("Control UI composer capability menu", () => {
277343
}
278344
});
279345

346+
it("shows per-connector tool access and preserves raw MCP tool identity", async () => {
347+
const context = await browser.newContext({ viewport: { width: 1280, height: 900 } });
348+
const page = await context.newPage();
349+
const gateway = await installMockGateway(page, {
350+
featureMethods: ["chat.metadata", "chat.startup", "tools.effective"],
351+
methodResponses: {
352+
"config.get": configResponse({
353+
github: { url: "https://mcp.example.test", enabled: true },
354+
notion: { command: "notion-mcp", enabled: true },
355+
}),
356+
"sessions.list": sessionsList({
357+
mcpToolsDeny: { github: ["search_items"] },
358+
}),
359+
"tools.effective": effectiveToolsResponse(),
360+
},
361+
});
362+
363+
try {
364+
await page.goto(`${server.baseUrl}chat`);
365+
const composer = await openMenu(page);
366+
const menu = composer.locator("wa-dropdown.agent-chat__capability-menu");
367+
await menu.getByRole("menuitem", { name: /^Connectors/ }).click();
368+
await menu.getByRole("menuitem", { name: "Tool access" }).first().click();
369+
await expect.poll(() => menu.getAttribute("data-view")).toBe("tools:github");
370+
await expect.poll(() => menu.getByText("2 of 3 tools on").isVisible()).toBe(true);
371+
await expect.poll(() => menu.getByRole("menuitem", { name: "delete_page" }).count()).toBe(0);
372+
373+
const toolRows = menu.locator('wa-dropdown-item[value^="mcp-tool:"]');
374+
const rawToolNames = toolRows.locator(
375+
".agent-chat__capability-menu-label > span:first-child",
376+
);
377+
await expect
378+
.poll(() => rawToolNames.allTextContents())
379+
.toEqual(["list-issues", "search-items", "search_items"]);
380+
await expect
381+
.poll(async () => [
382+
await rawToolNames.nth(1).isVisible(),
383+
await rawToolNames.nth(2).isVisible(),
384+
])
385+
.toEqual([true, true]);
386+
await expect
387+
.poll(() =>
388+
toolRows
389+
.nth(2)
390+
.locator("wa-switch")
391+
.evaluate((node) => (node as HTMLElement & { checked: boolean }).checked),
392+
)
393+
.toBe(false);
394+
395+
await gateway.deferNext("tools.effective");
396+
await gateway.setMethodResponse(
397+
"sessions.list",
398+
sessionsList(
399+
{ mcpToolsDeny: { github: ["search_items"] } },
400+
{ id: "gpt-5.6", provider: "openai" },
401+
),
402+
);
403+
await gateway.emitGatewayEvent("sessions.changed", { sessionKey: "main" });
404+
await expect.poll(async () => (await gateway.getRequests("tools.effective")).length).toBe(2);
405+
await expect.poll(() => menu.getByText("Loading tools…").isVisible()).toBe(true);
406+
await gateway.resolveDeferred("tools.effective", effectiveToolsResponse());
407+
await expect
408+
.poll(() => rawToolNames.allTextContents())
409+
.toEqual(["list-issues", "search-items", "search_items"]);
410+
411+
await toolRows.nth(1).click();
412+
await expect
413+
.poll(() => latestToolOverrides(gateway))
414+
.toEqual({ mcpToolsDeny: { github: ["search-items", "search_items"] } });
415+
await expect.poll(() => menu.getAttribute("data-view")).toBe("tools:github");
416+
417+
await menu.getByRole("menuitem", { name: "Back" }).click();
418+
await expect.poll(() => menu.getAttribute("data-view")).toBe("connectors");
419+
} finally {
420+
await context.close();
421+
}
422+
});
423+
424+
it('renders tool access for a server named "constructor"', async () => {
425+
const context = await browser.newContext({ viewport: { width: 1280, height: 900 } });
426+
const page = await context.newPage();
427+
await installMockGateway(page, {
428+
featureMethods: ["chat.metadata", "chat.startup", "tools.effective"],
429+
methodResponses: {
430+
"config.get": configResponse({
431+
constructor: { url: "https://mcp.example.test", enabled: true },
432+
}),
433+
"sessions.list": sessionsList({
434+
mcpToolsDeny: { github: ["search_items"] },
435+
}),
436+
"tools.effective": effectiveToolsResponse("constructor"),
437+
},
438+
});
439+
440+
try {
441+
await page.goto(`${server.baseUrl}chat`);
442+
const composer = await openMenu(page);
443+
const menu = composer.locator("wa-dropdown.agent-chat__capability-menu");
444+
await menu.getByRole("menuitem", { name: /^Connectors/ }).click();
445+
await menu.getByRole("menuitem", { name: "Tool access" }).click();
446+
447+
await expect.poll(() => menu.getAttribute("data-view")).toBe("tools:constructor");
448+
await expect.poll(() => menu.getByText("3 of 3 tools on").isVisible()).toBe(true);
449+
await expect.poll(() => menu.locator('wa-dropdown-item[value^="mcp-tool:"]').count()).toBe(3);
450+
} finally {
451+
await context.close();
452+
}
453+
});
454+
455+
it("blocks tool mutations until the session, runtime config, and catalog are ready", async () => {
456+
const context = await browser.newContext({ viewport: { width: 1280, height: 900 } });
457+
const page = await context.newPage();
458+
const gateway = await installMockGateway(page, {
459+
featureMethods: ["chat.metadata", "chat.startup", "tools.effective"],
460+
deferredMethods: ["sessions.list", "tools.effective"],
461+
methodResponses: {
462+
"config.get": configResponse({
463+
github: { url: "https://mcp.example.test", enabled: true },
464+
}),
465+
"tools.effective": effectiveToolsResponse(),
466+
},
467+
});
468+
469+
try {
470+
await page.goto(`${server.baseUrl}chat`);
471+
await gateway.waitForRequest("sessions.list");
472+
const composer = await openMenu(page);
473+
const menu = composer.locator("wa-dropdown.agent-chat__capability-menu");
474+
await menu.getByRole("menuitem", { name: /^Connectors/ }).click();
475+
await menu.getByRole("menuitem", { name: "Tool access" }).click();
476+
await gateway.waitForRequest("tools.effective");
477+
await expect.poll(() => menu.getByText("Loading tools…").isVisible()).toBe(true);
478+
expect(await gateway.getRequests("sessions.patch")).toHaveLength(0);
479+
480+
await gateway.resolveDeferred("tools.effective", effectiveToolsResponse());
481+
const listIssues = menu.locator('wa-dropdown-item[value="mcp-tool:0"]');
482+
await expect.poll(() => listIssues.isDisabled()).toBe(true);
483+
await expect.poll(() => listIssues.getAttribute("title")).toBe("Loading…");
484+
await listIssues.evaluate((item) => {
485+
item
486+
.closest("wa-dropdown")
487+
?.dispatchEvent(new CustomEvent("wa-select", { bubbles: true, detail: { item } }));
488+
});
489+
expect(await gateway.getRequests("sessions.patch")).toHaveLength(0);
490+
491+
await gateway.resolveDeferred("sessions.list", sessionsList());
492+
await expect.poll(() => menu.getAttribute("data-view")).toBe("tools:github");
493+
await menu.getByRole("menuitem", { name: "Back" }).click();
494+
await menu.getByRole("menuitem", { name: "Tool access" }).click();
495+
const readyListIssues = menu.locator('wa-dropdown-item[value="mcp-tool:0"]');
496+
await expect.poll(() => readyListIssues.isDisabled()).toBe(false);
497+
await readyListIssues.click();
498+
await expect
499+
.poll(() => latestToolOverrides(gateway))
500+
.toEqual({ mcpToolsDeny: { github: ["list-issues"] } });
501+
} finally {
502+
await context.close();
503+
}
504+
});
505+
280506
it("disables capability mutations and admin rows for a read-only operator", async () => {
281507
const context = await browser.newContext({ viewport: { width: 1280, height: 900 } });
282508
const page = await context.newPage();

‎ui/src/i18n/locales/en.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5015,7 +5015,14 @@ export const en: TranslationMap = {
50155015
scopeSessionHint:
50165016
"The server is saved globally disabled and enabled only for this session.",
50175017
scopeEverywhereHint: "The server is saved and enabled for every session.",
5018-
toolAccess: "Tool access",
5018+
toolAccess: {
5019+
label: "Tool access",
5020+
loading: "Loading tools…",
5021+
loadFailed: "Couldn’t load tools.",
5022+
noTools: "No tools available for this connector.",
5023+
summary: "{enabled} of {total} tools on",
5024+
summaryOne: "{enabled} of {total} tool on",
5025+
},
50195026
enabledCount: "{count} on",
50205027
loadingSkills: "Loading skills…",
50215028
skillsLoadFailed: "Couldn’t load skills.",

‎ui/src/lib/sessions/tool-overrides.test.ts‎

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import { describe, expect, it } from "vitest";
22
import {
33
countSessionToolOverrides,
44
nextBooleanToolOverrides,
5+
nextMcpToolsDenyOverrides,
56
nextWebSearchToolOverrides,
7+
readOwnEntry,
68
resolveToolOverrideState,
79
sessionToolOverrideNames,
810
} from "./tool-overrides.ts";
@@ -15,6 +17,11 @@ describe("session tool overrides", () => {
1517
expect(resolveToolOverrideState(false, true)).toBe(true);
1618
});
1719

20+
it("reads only own dynamic-key entries", () => {
21+
expect(readOwnEntry({ github: false }, "constructor")).toBeUndefined();
22+
expect(readOwnEntry({ constructor: false }, "constructor")).toBe(false);
23+
});
24+
1825
it("adds and removes named overrides without disturbing sibling groups", () => {
1926
const current = {
2027
mcpServers: { github: false },
@@ -44,6 +51,59 @@ describe("session tool overrides", () => {
4451
expect(nextWebSearchToolOverrides({ webSearch: true }, false, false)).toEqual({});
4552
});
4653

54+
it("adds sorted MCP tool denials without mutating sibling overrides", () => {
55+
const current = {
56+
mcpToolsDeny: { github: ["zebra"], notion: ["delete_page"] },
57+
webSearch: false,
58+
};
59+
expect(nextMcpToolsDenyOverrides(current, "github", "alpha", true)).toEqual({
60+
mcpToolsDeny: { github: ["alpha", "zebra"], notion: ["delete_page"] },
61+
webSearch: false,
62+
});
63+
expect(current.mcpToolsDeny.github).toEqual(["zebra"]);
64+
});
65+
66+
it("removes MCP tool denials and keeps the map sparse", () => {
67+
expect(
68+
nextMcpToolsDenyOverrides(
69+
{ mcpToolsDeny: { github: ["read", "write"], notion: ["delete_page"] } },
70+
"github",
71+
"read",
72+
false,
73+
),
74+
).toEqual({ mcpToolsDeny: { github: ["write"], notion: ["delete_page"] } });
75+
expect(
76+
nextMcpToolsDenyOverrides(
77+
{ mcpToolsDeny: { github: ["write"], notion: ["delete_page"] } },
78+
"github",
79+
"write",
80+
false,
81+
),
82+
).toEqual({ mcpToolsDeny: { notion: ["delete_page"] } });
83+
expect(
84+
nextMcpToolsDenyOverrides({ mcpToolsDeny: { github: ["write"] } }, "github", "write", false),
85+
).toEqual({});
86+
});
87+
88+
it("treats constructor as an own MCP server key", () => {
89+
expect(
90+
nextMcpToolsDenyOverrides(
91+
{ mcpToolsDeny: { github: ["read"] } },
92+
"constructor",
93+
"inspect",
94+
true,
95+
),
96+
).toEqual({
97+
mcpToolsDeny: { constructor: ["inspect"], github: ["read"] },
98+
});
99+
});
100+
101+
it.each(["mcpServers", "skills"] as const)("treats hasOwnProperty as an own %s key", (group) => {
102+
expect(nextBooleanToolOverrides({}, group, "hasOwnProperty", false, true)).toEqual({
103+
[group]: { hasOwnProperty: false },
104+
});
105+
});
106+
47107
it("counts override categories and returns deterministic tooltip names", () => {
48108
const overrides = {
49109
mcpServers: { zeta: false, alpha: true },

0 commit comments

Comments
 (0)