Skip to content

Commit 13cf904

Browse files
ochafikclaude
andcommitted
feat: Display server name above tool name in cards
- Swift host: Add serverName to ToolCallInfo and display it in ToolCallCard header - JS host: Pass toolInfo with tool definition to hostContext when creating AppBridge 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 4961d00 commit 13cf904

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

examples/basic-host-swift/Sources/BasicHostApp/ContentView.swift

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,14 @@ struct ToolCallCard: View {
188188
VStack(alignment: .leading, spacing: 8) {
189189
// Header
190190
HStack {
191-
Text(toolCallInfo.tool.name)
192-
.font(.subheadline.bold())
193-
.foregroundColor(.primary)
191+
VStack(alignment: .leading, spacing: 2) {
192+
Text(toolCallInfo.serverName)
193+
.font(.caption)
194+
.foregroundColor(.secondary)
195+
Text(toolCallInfo.tool.name)
196+
.font(.subheadline.bold())
197+
.foregroundColor(.primary)
198+
}
194199

195200
Spacer()
196201

examples/basic-host-swift/Sources/BasicHostApp/McpHostViewModel.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,12 @@ class McpHostViewModel: ObservableObject {
134134
throw ToolCallError.invalidJson
135135
}
136136

137+
let serverName = selectedServerIndex >= 0 && selectedServerIndex < Self.knownServers.count
138+
? Self.knownServers[selectedServerIndex].0
139+
: "Custom Server"
140+
137141
let toolCallInfo = ToolCallInfo(
142+
serverName: serverName,
138143
tool: tool,
139144
input: inputDict,
140145
client: client,
@@ -268,6 +273,7 @@ struct ToolResult {
268273
@MainActor
269274
class ToolCallInfo: ObservableObject, Identifiable {
270275
let id = UUID()
276+
let serverName: String
271277
let tool: Tool
272278
let input: [String: Any]
273279
let client: Client
@@ -283,12 +289,14 @@ class ToolCallInfo: ObservableObject, Identifiable {
283289
@Published var error: String?
284290

285291
init(
292+
serverName: String,
286293
tool: Tool,
287294
input: [String: Any],
288295
client: Client,
289296
hostInfo: Implementation,
290297
hostCapabilities: McpUiHostCapabilities
291298
) {
299+
self.serverName = serverName
292300
self.tool = tool
293301
self.input = input
294302
self.client = client

examples/basic-host/src/implementation.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,12 +209,19 @@ function hookInitializedCallback(appBridge: AppBridge): Promise<void> {
209209
}
210210

211211

212-
export function newAppBridge(serverInfo: ServerInfo, iframe: HTMLIFrameElement): AppBridge {
212+
export function newAppBridge(serverInfo: ServerInfo, toolCallInfo: ToolCallInfo, iframe: HTMLIFrameElement): AppBridge {
213213
const serverCapabilities = serverInfo.client.getServerCapabilities();
214214
const appBridge = new AppBridge(serverInfo.client, IMPLEMENTATION, {
215215
openLinks: {},
216216
serverTools: serverCapabilities?.tools,
217217
serverResources: serverCapabilities?.resources,
218+
}, {
219+
hostContext: {
220+
toolInfo: {
221+
id: crypto.randomUUID(), // We don't have the actual request ID, use a random one
222+
tool: toolCallInfo.tool,
223+
},
224+
},
218225
});
219226

220227
// Register all handlers before calling connect(). The Guest UI can start

examples/basic-host/src/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ function AppIFramePanel({ toolCallInfo }: AppIFramePanelProps) {
185185
// Outside of Strict Mode, this `useEffect` runs only once per
186186
// `toolCallInfo`.
187187
if (firstTime) {
188-
const appBridge = newAppBridge(toolCallInfo.serverInfo, iframe);
188+
const appBridge = newAppBridge(toolCallInfo.serverInfo, toolCallInfo, iframe);
189189
initializeApp(iframe, appBridge, toolCallInfo);
190190
}
191191
});

0 commit comments

Comments
 (0)