-
Notifications
You must be signed in to change notification settings - Fork 44
feat: Add Kotlin SDK for MCP Apps #134
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
23
commits into
main
Choose a base branch
from
ochafik/kotlin-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
Kotlin SDK for hosting MCP Apps in Android applications. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Kotlin SDK for hosting MCP Apps in Android applications. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Kotlin SDK for hosting MCP Apps in Android applications: SDK (kotlin/): - AppBridge: Host-side protocol handler - Transport abstraction (McpAppsTransport interface) - Generated types from schema.json - Full MCP Apps protocol support Example App (examples/basic-host-kotlin/): - Jetpack Compose app demonstrating SDK usage - Bottom toolbar UI (server/tool pickers) - WebViewTransport for Android WebView - Tool forwarding to MCP servers - Server name displayed in tool call cards - Toast notifications for messages/logs Type Generator: - scripts/generate-kotlin-types.ts - Generates Kotlin data classes from JSON Schema CI: - Kotlin job with JDK 21 on ubuntu-latest - Builds and tests SDK 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
commit: |
01fdb96 to
66fc58c
Compare
…rotocol/ext-apps into ochafik/kotlin-sdk
…rotocol/ext-apps into ochafik/kotlin-sdk
3 tasks
Apply the same two-phase close pattern introduced in basic-host: - Add isDestroying state to ToolCallState for tracking teardown phase - Implement requestClose() and completeClose() for two-phase teardown - Send ui/resource-teardown request when closing apps - Wait for app response before removing (with 3s timeout) - Dim card and show "Closing" status during teardown - Non-app results close immediately This follows the spec: "Host SHOULD wait for a response before tearing down the resource (to prevent data loss)." 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Removed the basic-host-swift example app and the Swift type generation script as they are no longer needed for this branch. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
The swift job referenced a swift/ directory that doesn't exist. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
…cture Add testable protocol handler and comprehensive test coverage: - McpAppBridgeProtocol: Extracted protocol logic into testable class - Handles JSON-RPC message parsing and dispatch - Manages protocol state (initialization, teardown) - Provides callbacks for all protocol events - Unit tests (17 tests, all passing): - Initialization handshake (initialize, initialized) - App→Host: size-changed, message, open-link, logging, tools/call - Host→App: tool-input, tool-result, tool-cancelled - Teardown flow with request/response tracking - Edge cases: unknown methods, malformed JSON - Test HTML app (test-app.html): - Implements full MCP Apps protocol - Visual protocol log for debugging - Buttons to trigger App→Host messages - Can be used for manual testing and instrumentation tests - Android instrumentation test skeleton: - Loads test app in WebView - Verifies protocol handshake - Tests two-way communication 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
- Add link to basic-host-kotlin in top-level README examples section - Add collapsible Mac installation instructions for Android SDK/emulator - Fix stale ext-apps2 references to ext-apps 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
…rotocol/ext-apps into ochafik/kotlin-sdk
The size-changed notification from Apps was being logged but not applied. Now the WebView properly resizes when the App requests a different height. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Changed from a fixed 3-second delay to polling every 50ms with a 500ms max timeout. This makes card dismissal feel much snappier while still giving apps time to respond to teardown requests. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Expose an optional timeout parameter with a sensible 500ms default. This allows hosts to control how long to wait for the App to complete cleanup. `sendResourceTeardown(timeout: Duration = 500.milliseconds)` 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
- Add DisposableEffect to handle WebView cleanup on composable disposal - Add LifecycleEventObserver to pause/resume WebView on activity lifecycle changes - Properly clean up WebView reference when composable is disposed - Add update lambda to sync WebView state with lifecycle This fixes the issue where WebView content was killed when going out of view (e.g., scrolled off in LazyColumn) and failed to reload because the lifecycle wasn't properly managed. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
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
Kotlin low-level SDK (AppBridge) for hosting MCP Apps in Android applications, and basic example Android app.
To test, ensure you have an Android emulator & run:
Show commands to install an Android emulator on Mac
What's included
SDK (
kotlin/)McpAppsTransportinterface for different transport implementationsscripts/generate-kotlin-types.tsExample App (
examples/basic-host-kotlin/)CI
Architecture Note
The
WebViewTransportis in the example app rather than the SDK because:WKWebViewTransportbecause Swift compiles natively for iOSHow to test
🤖 Generated with Claude Code