Skip to content

Commit 51b7a8b

Browse files
committed
fix(ui): scope MCP discovery notices to the viewed connector
1 parent d32a110 commit 51b7a8b

8 files changed

Lines changed: 96 additions & 14 deletions

File tree

‎apps/shared/OpenClawKit/Sources/OpenClawProtocol/GatewayModels.swift‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12452,21 +12452,25 @@ public struct ToolsEffectiveNotice: Codable, Sendable {
1245212452
public let id: String
1245312453
public let severity: AnyCodable
1245412454
public let message: String
12455+
public let servers: [String]?
1245512456

1245612457
public init(
1245712458
id: String,
1245812459
severity: AnyCodable,
12459-
message: String)
12460+
message: String,
12461+
servers: [String]? = nil)
1246012462
{
1246112463
self.id = id
1246212464
self.severity = severity
1246312465
self.message = message
12466+
self.servers = servers
1246412467
}
1246512468

1246612469
private enum CodingKeys: String, CodingKey {
1246712470
case id
1246812471
case severity
1246912472
case message
12473+
case servers
1247012474
}
1247112475
}
1247212476

‎packages/gateway-protocol/src/schema/agents-models-skills.test.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,22 @@ describe("ToolsEffectiveResultSchema", () => {
266266
expect(Value.Check(ToolsEffectiveResultSchema, result)).toBe(true);
267267
});
268268

269+
it("accepts server-scoped inventory notices", () => {
270+
const result = {
271+
...toolsEffectiveResult(),
272+
notices: [
273+
{
274+
id: "mcp-not-yet-connected",
275+
severity: "info",
276+
message: "MCP tools are not available yet.",
277+
servers: ["github", "notion"],
278+
},
279+
],
280+
};
281+
282+
expect(Value.Check(ToolsEffectiveResultSchema, result)).toBe(true);
283+
});
284+
269285
it("keeps tool quarantine notices strict", () => {
270286
const result = {
271287
...toolsEffectiveResult(),

‎packages/gateway-protocol/src/schema/agents-models-skills.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,6 +1042,7 @@ export const ToolsEffectiveNoticeSchema = closedObject({
10421042
id: NonEmptyString,
10431043
severity: Type.Union([Type.Literal("info"), Type.Literal("warning")]),
10441044
message: Type.String(),
1045+
servers: Type.Optional(Type.Array(NonEmptyString)),
10451046
});
10461047

10471048
/** Effective tool set for a session, including profile and filtering notices. */

‎src/agents/tools-effective-inventory.types.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export type EffectiveToolInventoryNotice = {
3838
id: string;
3939
severity: "info" | "warning";
4040
message: string;
41+
servers?: string[];
4142
};
4243

4344
/** Effective tool inventory result for one agent/profile. */

‎src/gateway/server-methods/tools-effective.test.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ type RespondCall = [boolean, unknown?, { code: number; message: string }?];
8585
type ToolsEffectivePayload = {
8686
agentId?: string;
8787
profile?: string;
88-
notices?: Array<{ id?: string; severity?: string; message?: string }>;
88+
notices?: Array<{ id?: string; severity?: string; message?: string; servers?: string[] }>;
8989
groups?: Array<{
9090
id?: string;
9191
label?: string;
@@ -485,12 +485,14 @@ describe("tools.effective handler", () => {
485485
});
486486

487487
it("reports configured MCP servers as not connected without starting them", async () => {
488-
mockMcpConfigSummary();
488+
mockMcpConfigSummary({ serverNames: ["zeta", "alpha"] });
489489
const { respond, invoke } = createInvokeParams({ sessionKey: "main:abc" });
490490
await invoke();
491491

492492
expectPayloadGroupIds(respond, ["core"]);
493-
expect(expectPayloadNotice(respond, "mcp-not-yet-connected")?.message).toContain("reproProbe");
493+
const notice = expectPayloadNotice(respond, "mcp-not-yet-connected");
494+
expect(notice?.message).toContain('"alpha", "zeta"');
495+
expect(notice?.servers).toEqual(["alpha", "zeta"]);
494496
});
495497

496498
it("projects MCP tools from an already-populated session runtime catalog", async () => {

‎src/gateway/server-methods/tools-effective.ts‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -307,25 +307,29 @@ function mcpDiscoveryNotice(
307307
if (mcpServerNames.length === 0) {
308308
return undefined;
309309
}
310-
const servers = formatMcpServerNames(mcpServerNames);
310+
const servers = mcpServerNames.toSorted((a, b) => a.localeCompare(b));
311+
const formattedServers = formatMcpServerNames(servers);
311312
switch (reason) {
312313
case "stale-config":
313314
return {
314315
id: "mcp-stale-catalog",
315316
severity: "info",
316-
message: `MCP servers ${servers} changed since the current runtime catalog was discovered. MCP tools will appear here after the next agent run discovers them.`,
317+
message: `MCP servers ${formattedServers} changed since the current runtime catalog was discovered. MCP tools will appear here after the next agent run discovers them.`,
318+
servers,
317319
};
318320
case "not-listed":
319321
return {
320322
id: "mcp-not-yet-listed",
321323
severity: "info",
322-
message: `MCP servers ${servers} are connected but have not finished listing tools yet. MCP tools will appear here after the session discovers them.`,
324+
message: `MCP servers ${formattedServers} are connected but have not finished listing tools yet. MCP tools will appear here after the session discovers them.`,
325+
servers,
323326
};
324327
case "not-connected":
325328
return {
326329
id: "mcp-not-yet-connected",
327330
severity: "info",
328-
message: `MCP servers ${servers} are configured but not connected for this session yet. MCP tools will appear here after an agent run discovers them.`,
331+
message: `MCP servers ${formattedServers} are configured but not connected for this session yet. MCP tools will appear here after an agent run discovers them.`,
332+
servers,
329333
};
330334
default:
331335
// Exhaustiveness guard for oxlint's consistent-return rule.

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

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ function effectiveToolsResponse(serverName = "github") {
140140
};
141141
}
142142

143-
function undiscoveredMcpToolsResponse(serverName = "github") {
143+
function undiscoveredMcpToolsResponse(serverName = "github", scoped = true) {
144144
return {
145145
agentId: "main",
146146
profile: "full",
@@ -150,6 +150,7 @@ function undiscoveredMcpToolsResponse(serverName = "github") {
150150
id: "mcp-not-yet-connected",
151151
severity: "info",
152152
message: `MCP servers "${serverName}" are configured but not connected for this session yet. MCP tools will appear here after an agent run discovers them.`,
153+
...(scoped ? { servers: [serverName] } : {}),
153154
},
154155
],
155156
};
@@ -467,14 +468,15 @@ describeControlUiE2e("Control UI composer capability menu", () => {
467468
}
468469
});
469470

470-
it("shows the effective-tools discovery notice while an MCP catalog has no rows", async () => {
471+
it("scopes effective-tools discovery notices to their connector", async () => {
471472
const context = await browser.newContext({ viewport: { width: 1280, height: 900 } });
472473
const page = await context.newPage();
473474
await installMockGateway(page, {
474475
featureMethods: ["chat.metadata", "chat.startup", "tools.effective"],
475476
methodResponses: {
476477
"config.get": configResponse({
477478
github: { url: "https://mcp.example.test", enabled: true },
479+
notion: { command: "notion-mcp", enabled: true },
478480
}),
479481
"sessions.list": sessionsList(),
480482
"tools.effective": undiscoveredMcpToolsResponse(),
@@ -486,7 +488,7 @@ describeControlUiE2e("Control UI composer capability menu", () => {
486488
const composer = await openMenu(page);
487489
const menu = composer.locator("wa-dropdown.agent-chat__capability-menu");
488490
await menu.getByRole("menuitem", { name: /^Connectors/ }).click();
489-
await menu.getByRole("menuitem", { name: "Tool access" }).click();
491+
await menu.getByRole("menuitem", { name: "Tool access" }).first().click();
490492

491493
await expect.poll(() => menu.getAttribute("data-view")).toBe("tools:github");
492494
await expect
@@ -500,6 +502,55 @@ describeControlUiE2e("Control UI composer capability menu", () => {
500502
.poll(() => menu.getByText("No tools available for this connector.").count())
501503
.toBe(0);
502504
await expect.poll(() => menu.getByText("0 of 0 tools on").count()).toBe(0);
505+
506+
await menu.getByRole("menuitem", { name: "Back" }).click();
507+
await menu.getByRole("menuitem", { name: "Tool access" }).nth(1).click();
508+
await expect.poll(() => menu.getAttribute("data-view")).toBe("tools:notion");
509+
await expect
510+
.poll(() =>
511+
menu.getByText("MCP tools will appear here after an agent run discovers them.").count(),
512+
)
513+
.toBe(0);
514+
await expect
515+
.poll(() => menu.getByText("No tools available for this connector.").isVisible())
516+
.toBe(true);
517+
await expect.poll(() => menu.getByText("0 of 0 tools on").count()).toBe(0);
518+
} finally {
519+
await context.close();
520+
}
521+
});
522+
523+
it("uses the generic empty state for an unscoped discovery notice", async () => {
524+
const context = await browser.newContext({ viewport: { width: 1280, height: 900 } });
525+
const page = await context.newPage();
526+
await installMockGateway(page, {
527+
featureMethods: ["chat.metadata", "chat.startup", "tools.effective"],
528+
methodResponses: {
529+
"config.get": configResponse({
530+
github: { url: "https://mcp.example.test", enabled: true },
531+
}),
532+
"sessions.list": sessionsList(),
533+
"tools.effective": undiscoveredMcpToolsResponse("github", false),
534+
},
535+
});
536+
537+
try {
538+
await page.goto(`${server.baseUrl}chat`);
539+
const composer = await openMenu(page);
540+
const menu = composer.locator("wa-dropdown.agent-chat__capability-menu");
541+
await menu.getByRole("menuitem", { name: /^Connectors/ }).click();
542+
await menu.getByRole("menuitem", { name: "Tool access" }).click();
543+
544+
await expect.poll(() => menu.getAttribute("data-view")).toBe("tools:github");
545+
await expect
546+
.poll(() => menu.getByText("No tools available for this connector.").isVisible())
547+
.toBe(true);
548+
await expect
549+
.poll(() =>
550+
menu.getByText("MCP tools will appear here after an agent run discovers them.").count(),
551+
)
552+
.toBe(0);
553+
await expect.poll(() => menu.getByText("0 of 0 tools on").count()).toBe(0);
503554
} finally {
504555
await context.close();
505556
}

‎ui/src/pages/chat/components/chat-composer-plus-menu.ts‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,11 @@ const MCP_DISCOVERY_NOTICE_IDS = new Set([
324324
"mcp-stale-catalog",
325325
]);
326326

327-
function mcpDiscoveryNotice(result: ToolsEffectiveResult | null) {
328-
return result?.notices?.find((notice) => MCP_DISCOVERY_NOTICE_IDS.has(notice.id));
327+
function mcpDiscoveryNotice(result: ToolsEffectiveResult | null, serverName: string) {
328+
return result?.notices?.find(
329+
(notice) =>
330+
MCP_DISCOVERY_NOTICE_IDS.has(notice.id) && notice.servers?.includes(serverName) === true,
331+
);
329332
}
330333

331334
function isToolDenied(props: ChatComposerPlusMenuProps, tool: ToolsEffectiveEntry): boolean {
@@ -345,7 +348,7 @@ function isToolDenied(props: ChatComposerPlusMenuProps, tool: ToolsEffectiveEntr
345348
function renderToolAccessView(props: ChatComposerPlusMenuProps, serverName: string) {
346349
const tools = toolsForServer(props.toolsEffectiveResult, serverName);
347350
const discoveryNotice =
348-
tools.length === 0 ? mcpDiscoveryNotice(props.toolsEffectiveResult) : null;
351+
tools.length === 0 ? mcpDiscoveryNotice(props.toolsEffectiveResult, serverName) : null;
349352
const enabledCount = tools.filter((tool) => !isToolDenied(props, tool)).length;
350353
const summary = t(
351354
tools.length === 1

0 commit comments

Comments
 (0)