-
Notifications
You must be signed in to change notification settings - Fork 41
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
Draft
ochafik
wants to merge
17
commits into
main
Choose a base branch
from
ochafik/swift-sdk
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 <noreply@anthropic.com>
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 <noreply@anthropic.com>
- 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 <noreply@anthropic.com>
- 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 <noreply@anthropic.com>
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 <noreply@anthropic.com>
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 <noreply@anthropic.com>
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 <noreply@anthropic.com>
- 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 <noreply@anthropic.com>
- 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 <noreply@anthropic.com>
- 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 <noreply@anthropic.com>
- 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 <noreply@anthropic.com>
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 <noreply@anthropic.com>
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 <noreply@anthropic.com>
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 <noreply@anthropic.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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