Skip to content

Commit b8534d4

Browse files
ochafikclaude
andcommitted
feat(swift-host): Add teardown pattern when removing tool calls
Call sendResourceTeardown() and close() on AppBridge before removing a tool call card, matching the recommended pattern from the web host. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 13cf904 commit b8534d4

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,9 @@ class McpHostViewModel: ObservableObject {
240240
}
241241

242242
func removeToolCall(_ toolCall: ToolCallInfo) {
243+
Task {
244+
await toolCall.teardown()
245+
}
243246
activeToolCalls.removeAll { $0.id == toolCall.id }
244247
}
245248
}
@@ -482,6 +485,19 @@ class ToolCallInfo: ObservableObject, Identifiable {
482485
"isError": AnyCodable(result.isError ?? false)
483486
])
484487
}
488+
489+
/// Teardown the app bridge before removing the tool call
490+
func teardown() async {
491+
if let bridge = appBridge {
492+
do {
493+
_ = try await bridge.sendResourceTeardown()
494+
} catch {
495+
print("[Host] Teardown failed: \(error)")
496+
}
497+
await bridge.close()
498+
}
499+
appBridge = nil
500+
}
485501
}
486502

487503
// MARK: - Execution State

0 commit comments

Comments
 (0)