Skip to content

Commit 9e7924a

Browse files
committed
fix(server): preserve MCP logos on tool activity
1 parent dd68436 commit 9e7924a

9 files changed

Lines changed: 131 additions & 22 deletions

File tree

‎apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts‎

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,11 +1081,33 @@ describe("AcpAdapterV2", () => {
10811081
title: "Check weather",
10821082
status: "completed",
10831083
rawInput: { server: "weather", tool: "get_weather", city: "Berlin" },
1084+
rawOutput: {
1085+
result: {
1086+
_meta: {
1087+
source: { name: "Weather", logoUrl: "https://example.com/weather.png" },
1088+
},
1089+
content: [{ type: "text", text: "Sunny" }],
1090+
},
1091+
},
10841092
_meta: {
10851093
is_mcp_tool_call: true,
10861094
"cognition.ai/subagent_context": { parentAgentId: "child-a" },
10871095
},
10881096
},
1097+
{
1098+
sessionUpdate: "tool_call",
1099+
toolCallId: "parent-weather",
1100+
title: "Check weather",
1101+
status: "completed",
1102+
rawInput: { server: "weather", tool: "get_weather", city: "Berlin" },
1103+
rawOutput: {
1104+
_meta: {
1105+
source: { name: "Weather", logoUrl: "https://example.com/weather.png" },
1106+
},
1107+
content: [{ type: "text", text: "Sunny" }],
1108+
},
1109+
_meta: { is_mcp_tool_call: true },
1110+
},
10891111
{
10901112
sessionUpdate: "agent_message_chunk",
10911113
content: { type: "text", text: " → decider → event)." },
@@ -1209,12 +1231,22 @@ describe("AcpAdapterV2", () => {
12091231
item.type === "dynamic_tool" &&
12101232
item.toolName === "weather.get_weather",
12111233
);
1212-
assert.equal(childMcp?.title, "get weather");
1213-
assert.deepEqual(childMcp?.toolSource, {
1214-
key: "mcp:weather",
1215-
name: "weather",
1216-
kind: "integration",
1217-
});
1234+
const parentMcp = items.find(
1235+
(item) =>
1236+
item.threadId === threadId &&
1237+
item.type === "dynamic_tool" &&
1238+
item.toolName === "weather.get_weather",
1239+
);
1240+
for (const item of [parentMcp, childMcp]) {
1241+
assert.equal(item?.title, "get weather");
1242+
assert.deepEqual(item?.toolSource, {
1243+
key: "mcp:weather",
1244+
name: "Weather",
1245+
kind: "integration",
1246+
icon: { _tag: "themed-logo", logoUrl: "https://example.com/weather.png" },
1247+
});
1248+
assert.deepEqual(item?.toolIcon, item?.toolSource?.icon);
1249+
}
12181250
assert.isTrue(
12191251
items.some(
12201252
(item) =>
@@ -1239,7 +1271,7 @@ describe("AcpAdapterV2", () => {
12391271
const parentTools = items.filter(
12401272
(item) => item.threadId === threadId && item.type === "dynamic_tool",
12411273
);
1242-
assert.equal(parentTools.length, 1);
1274+
assert.equal(parentTools.length, 2);
12431275
assert.equal(parentTools[0]?.title, "Parent tool finished");
12441276
}).pipe(Effect.provide(testLayer), Effect.scoped),
12451277
);

‎apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3263,6 +3263,9 @@ export function makeAcpAdapterV2(
32633263
...mcpToolPresentation({
32643264
serverName: mcpIdentity.server,
32653265
toolName: mcpIdentity.tool,
3266+
source: unknownRecord(
3267+
(unknownRecord(rawOutputRecord?.result) ?? rawOutputRecord)?._meta,
3268+
)?.source,
32663269
}),
32673270
type: "dynamic_tool",
32683271
toolName: `${mcpIdentity.server}.${mcpIdentity.tool}`,
@@ -4318,6 +4321,12 @@ export function makeAcpAdapterV2(
43184321
: mcpToolPresentation({
43194322
serverName: mcpIdentity.server,
43204323
toolName: mcpIdentity.tool,
4324+
source: unknownRecord(
4325+
(
4326+
unknownRecord(unknownRecord(merged.data.rawOutput)?.result) ??
4327+
unknownRecord(merged.data.rawOutput)
4328+
)?._meta,
4329+
)?.source,
43214330
})),
43224331
toolName:
43234332
mcpIdentity === undefined

‎apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2223,6 +2223,10 @@ describe("ClaudeAdapterV2 background wake turns", () => {
22232223
assert.isNull(items[0]?.title);
22242224
for (const item of items.slice(1)) {
22252225
assert.equal(item.title, title ?? "get weather");
2226+
assert.deepEqual(item.toolIcon, {
2227+
_tag: "themed-logo",
2228+
logoUrl: "https://example.com/weather.png",
2229+
});
22262230
assert.deepEqual(item.toolSource, {
22272231
key: "mcp:weather",
22282232
name: "Weather",

‎apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3760,6 +3760,9 @@ export function makeClaudeAdapterV2(
37603760
: {
37613761
...itemBase,
37623762
type: "dynamic_tool",
3763+
...(input.presentation?.toolIcon === undefined
3764+
? {}
3765+
: { toolIcon: input.presentation.toolIcon }),
37633766
...(input.presentation?.toolSource === undefined
37643767
? {}
37653768
: { toolSource: input.presentation.toolSource }),

‎apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.ts‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -860,10 +860,23 @@ describe("CodexAdapterV2 dynamic tool projection", () => {
860860
tool: "connector_get_weather",
861861
status: "completed",
862862
arguments: { title: "Argument, not display metadata" },
863-
appContext: { connectorId: "weather-app", appName: "Weather", actionName: "Check weather" },
863+
appContext: {
864+
connectorId: "weather-app",
865+
appName: "Weather",
866+
actionName: "Check weather",
867+
},
868+
result: {
869+
content: [],
870+
_meta: { source: { logoUrl: "https://example.com/weather.png" } },
871+
},
864872
});
865873
assert.equal(projection.title, "Check weather");
866874
assert.equal(projection.toolSource?.name, "Weather");
875+
assert.deepEqual(projection.toolIcon, {
876+
_tag: "themed-logo",
877+
logoUrl: "https://example.com/weather.png",
878+
});
879+
assert.deepEqual(projection.toolSource?.icon, projection.toolIcon);
867880
});
868881

869882
it("preserves native browser and app icons alongside MCP tool output", () => {

‎apps/server/src/orchestration-v2/testkit/fixtures/claude_mcp_tool_presentation/output.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export function assertClaudeMcpToolPresentationOutput(
3535

3636
assert.equal(scrape?.status, "completed");
3737
assert.equal(scrape?.title, "Firecrawl scrape");
38+
assert.deepEqual(scrape?.toolIcon, scrape?.toolSource?.icon);
3839
assert.deepEqual(scrape?.toolSource, {
3940
key: "mcp:firecrawl",
4041
name: "Firecrawl",

‎apps/server/src/provider/CodexToolPresentation.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,8 @@ export function mcpToolPresentation(
219219
serverName: appContext?.connectorId ?? item.server,
220220
toolName: item.tool,
221221
title: appContext?.actionName,
222-
serverDisplayName: appContext?.appName ?? sourceMetadata?.name,
222+
serverDisplayName: appContext?.appName,
223+
source: sourceMetadata,
223224
iconUrl: sourceLogo?._tag === "themed-logo" ? sourceLogo.logoUrl : undefined,
224225
iconUrlDark: sourceLogo?._tag === "themed-logo" ? sourceLogo.logoUrlDark : undefined,
225226
});

‎apps/server/src/provider/McpToolPresentation.test.ts‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ describe("mcpToolPresentation", () => {
1414
}),
1515
).toEqual({
1616
title: "Scrape page",
17+
toolIcon: {
18+
_tag: "themed-logo",
19+
logoUrl: "https://example.com/icon.png",
20+
logoUrlDark: "https://example.com/dark.png",
21+
},
1722
toolSource: {
1823
key: "mcp:firecrawl-local",
1924
name: "Firecrawl",
@@ -27,6 +32,25 @@ describe("mcpToolPresentation", () => {
2732
});
2833
});
2934

35+
it("uses MCP result source metadata for the tool and its integration", () => {
36+
const presentation = mcpToolPresentation({
37+
serverName: "firecrawl-local",
38+
toolName: "firecrawl_scrape",
39+
source: {
40+
name: "Firecrawl",
41+
logoUrl: "https://example.com/firecrawl.png",
42+
logoUrlDark: "https://example.com/firecrawl-dark.png",
43+
},
44+
});
45+
expect(presentation.toolSource?.name).toBe("Firecrawl");
46+
expect(presentation.toolIcon).toEqual({
47+
_tag: "themed-logo",
48+
logoUrl: "https://example.com/firecrawl.png",
49+
logoUrlDark: "https://example.com/firecrawl-dark.png",
50+
});
51+
expect(presentation.toolSource?.icon).toEqual(presentation.toolIcon);
52+
});
53+
3054
it("uses readable fallback names without a guessed logo", () => {
3155
expect(mcpToolPresentation({ toolName: "mcp__my_server__get_weather" })).toEqual({
3256
title: "get weather",
@@ -62,4 +86,18 @@ describe("mcpToolPresentation", () => {
6286
);
6387
expect(mcpToolPresentation({ title: "Tool title" })).toEqual({ title: "Tool title" });
6488
});
89+
90+
it.each([
91+
null,
92+
"logo",
93+
{ logoUrl: "file:///tmp/logo.png" },
94+
{ logoUrlDark: "https://example.com/dark.png" },
95+
])("ignores source metadata without a valid logo: %j", (source) => {
96+
expect(mcpToolPresentation({ serverName: "weather", toolName: "get_weather", source })).toEqual(
97+
{
98+
title: "get weather",
99+
toolSource: { key: "mcp:weather", name: "weather", kind: "integration" },
100+
},
101+
);
102+
});
65103
});

‎apps/server/src/provider/McpToolPresentation.ts‎

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { ToolActivitySource } from "@t3tools/contracts";
1+
import type { ToolActivityIcon, ToolActivitySource } from "@t3tools/contracts";
22
import { resolveT3McpToolDefinition } from "@t3tools/shared/t3McpToolPresentation";
33

44
export function normalizeMcpText(value: unknown, maxLength = 160): string | undefined {
@@ -26,7 +26,14 @@ export function mcpToolPresentation(input: {
2626
readonly serverDisplayName?: unknown;
2727
readonly iconUrl?: unknown;
2828
readonly iconUrlDark?: unknown;
29-
}): { readonly title?: string; readonly toolSource?: ToolActivitySource } {
29+
readonly source?: unknown;
30+
}): {
31+
readonly title?: string;
32+
readonly toolIcon?: ToolActivityIcon;
33+
readonly toolSource?: ToolActivitySource;
34+
} {
35+
const source =
36+
typeof input.source === "object" && input.source !== null ? input.source : undefined;
3037
const qualified =
3138
typeof input.toolName === "string" ? /^mcp__(.+?)__(.+)$/i.exec(input.toolName) : null;
3239
const server = normalizeMcpText(input.serverName ?? qualified?.[1] ?? input.serverDisplayName);
@@ -38,25 +45,26 @@ export function mcpToolPresentation(input: {
3845
if (!server) return title ? { title } : {};
3946
const name =
4047
normalizeMcpText(input.serverDisplayName) ??
48+
normalizeMcpText(source && Reflect.get(source, "name")) ??
4149
normalizeMcpText(server.replace(/[_-]+/gu, " ")) ??
4250
server;
43-
const logoUrl = normalizeMcpHttpUrl(input.iconUrl);
44-
const logoUrlDark = normalizeMcpHttpUrl(input.iconUrlDark);
51+
const logoUrl =
52+
normalizeMcpHttpUrl(input.iconUrl) ??
53+
normalizeMcpHttpUrl(source && Reflect.get(source, "logoUrl"));
54+
const logoUrlDark =
55+
normalizeMcpHttpUrl(input.iconUrlDark) ??
56+
normalizeMcpHttpUrl(source && Reflect.get(source, "logoUrlDark"));
57+
const icon = logoUrl
58+
? { _tag: "themed-logo" as const, logoUrl, ...(logoUrlDark ? { logoUrlDark } : {}) }
59+
: undefined;
4560
return {
4661
...(title ? { title } : {}),
62+
...(icon ? { toolIcon: icon } : {}),
4763
toolSource: {
4864
key: `mcp:${server.toLowerCase()}`,
4965
name,
5066
kind: "integration",
51-
...(logoUrl
52-
? {
53-
icon: {
54-
_tag: "themed-logo",
55-
logoUrl,
56-
...(logoUrlDark ? { logoUrlDark } : {}),
57-
} as const,
58-
}
59-
: {}),
67+
...(icon ? { icon } : {}),
6068
},
6169
};
6270
}

0 commit comments

Comments
 (0)