-
Notifications
You must be signed in to change notification settings - Fork 39
feat: Add Swift SDK for MCP Apps #132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Swift SDK for hosting MCP Apps in iOS/macOS applications: SDK (swift/): - AppBridge: Host-side protocol handler - WKWebViewTransport: WebView communication - Generated types from schema.json - Full MCP Apps protocol support Example App (examples/basic-host-swift/): - SwiftUI app demonstrating SDK usage - Bottom toolbar UI (server/tool pickers) - WebView with AppBridge integration - Tool forwarding to MCP servers - Server name displayed in tool call cards Type Generator: - scripts/generate-swift-types.ts - Generates Swift types from JSON Schema CI: - Swift job on macos-latest - Builds and tests SDK 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
commit: |
Removed kotlin job from CI and kotlin paths from .prettierignore as they reference directories that don't exist. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
| runs-on: macos-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Build Swift SDK | ||
| working-directory: swift | ||
| run: swift build | ||
|
|
||
| - name: Test Swift SDK | ||
| working-directory: swift | ||
| run: swift test |
Check warning
Code scanning / CodeQL
Workflow does not contain permissions Medium
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 1 day ago
The best way to fix this problem is to add an explicit permissions block to the workflow to restrict the GITHUB_TOKEN's privileges. Since none of the jobs in this workflow (build, swift) seem to require write access (i.e., they're just checking out code, compiling, running tests, verifying schemas and formatting), the minimal permission of contents: read should be sufficient. This can be set at the workflow level (top-level, after the name: and before jobs:) so that all jobs inherit it; alternatively, it could be set per job, but top-level is simpler and cleaner. No additional imports, methods, or definitions are required—just a configuration change in .github/workflows/ci.yml.
-
Copy modified lines R3-R5
| @@ -1,5 +1,8 @@ | ||
| name: CI | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main] |
- Use EmptyCapability() instead of Bool for capabilities - Use McpUiToolInputNotificationParams instead of removed type - Use McpUiResourceMetaCsp for resource meta tests - Add @mainactor to WKWebViewTransport tests - Use actor-based state capture for Sendable closure compliance - Extract async values before XCTAssert calls 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
- 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]>
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]>
The previous implementation spawned a Task but removed the card immediately without waiting. Now properly awaits the teardown. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Resolved conflict in examples/basic-host/src/index.tsx: - Keep toolCallInfo parameter for hostContext.toolInfo - Keep appBridgeRef.current assignment for teardown support 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
- Show spinner with "Closing..." text when tearing down - Dim card to 50% opacity during teardown - Hide close button while teardown is in progress 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
- Move isTearingDown to ToolCallInfo (observable state) - Remove local @State that caused desync issues - Add 5-second timeout to prevent stuck cards - Guard against double-tap with early return - Card observes model state via @ObservedObject 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
- Send params: [:] instead of nil (TS SDK expects object, not undefined) - Use strong reference for WebView in transport to prevent premature dealloc - Add guard for nil transport with proper error - Add debug logging to sendRequest 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
- Add toastMessage property and showToast() method to ViewModel - Add toast overlay at bottom of screen (auto-dismiss after 3s) - Change teardown() to return optional error message - Show toast when teardown fails or times out - Add OSLog-based logging for debugging - Improve logs.sh script for better log filtering 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
SDK changes: - Add timeout parameter to sendRequest (default 30s) - sendResourceTeardown uses 5s timeout - Add failPendingRequest helper for clean timeout handling Host changes: - Check isReady() before sending teardown - Skip teardown if bridge not yet initialized (no data to save) - Simplified logic since SDK handles timeout internally This prevents cards from getting stuck when closed before initialization. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Changed from 5 seconds to 0.5 seconds for a snappier user experience. Added documentation comment explaining the timeout parameter. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Updated McpHostViewModel to use the new typed params API: - onMessage, onOpenLink, onLoggingMessage, onSizeChange now take typed params - sendToolInput now takes McpUiToolInputParams - sendToolResult now takes McpUiToolResultParams with proper content items 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Summary
Swift low-level SDK (AppBridge) for hosting MCP Apps in iOS/macOS applications, and basic example iOS app.
To test, ensure you have XCode + an iOS Simulator & run:
What's included
SDK (
swift/)scripts/generate-swift-types.tsExample App (
examples/basic-host-swift/)example/basic-host)CI
How to test
cd examples/basic-host-swift ./scripts/run.shScreenshots
The example app displays MCP App UIs in a WebView with full protocol support.
🤖 Generated with Claude Code