Skip to content

AnswerZhao/android-mcp-sdk

Repository files navigation

Android MCP SDK Logo

Android MCP SDK

Android Kotlin License API JitPack

πŸš€ Android-MCP SDK: The Bridge Between LLMs and the Android App Ecosystem.

Extending the official MCP and using AIDL for transport, this SDK breaks down the isolation between AI agents and native Android applications. Whether you're building an LLM to orchestrate tools or an app to be invoked by AI, this SDK is your essential toolkit.

δΈ­ζ–‡η‰ˆREADME | πŸš€ Quick Start

✨ What Makes This Special

Transform Your Android Ecosystem into LLM Superpowers

// Your LLM can now do this across ANY Android app:
val result = mcpApi.callTool(
    "com.weather.app/.WeatherService#get_forecast",
    buildJsonObject { put("location", JsonPrimitive("Tokyo")) }
)

// And this:
mcpApi.callTool("com.calendar.app/.CalendarService#add_event", eventData)

// And this:
mcpApi.callTool("com.camera.app/.PhotoService#take_picture", cameraSettings)

🎯 Perfect For

  • πŸ€– AI App Developers: Build LLM assistants that control the entire Android ecosystem
  • πŸ“± Android Developers: Expose your app's capabilities to the growing AI assistant market
  • 🏒 Enterprise Teams: Create unified AI interfaces for internal Android app suites
  • πŸ”¬ Researchers: Prototype cross-app AI interactions and automation workflows

πŸ’‘ The Problem We Solve

Current State: Your LLM is trapped in a single app

  • ❌ Cannot access other Android apps' capabilities
  • ❌ Each app exists in isolation
  • ❌ Limited to built-in functions only
  • ❌ No standard way for apps to expose AI-callable functions

With Android MCP SDK: Your LLM becomes a system-wide AI assistant

  • βœ… Cross-App Communication: Call functions from any MCP-enabled Android app
  • βœ… Automatic Discovery: Find available tools across the entire system
  • βœ… Secure by Design: Android-native permission system with flexible policies
  • βœ… Production Ready: Built on Android's robust AIDL/Binder IPC architecture
  • βœ… Zero App Changes: Existing apps can add MCP support without architectural changes

πŸš€ Quick Start

Server App Integration (Tool Provider)

1. Add Dependency

dependencies {
    implementation("com.github.AnswerZhao:android-mcp-sdk:v0.0.1")
    implementation("io.modelcontextprotocol:kotlin-sdk:0.6.0")
}

maven { url = uri("https://jitpack.io") }

2. Create Your MCP Service

class WeatherMCPService : MCPService() {
    override fun getImplementation() = Implementation("weather-service", "1.0.0")
    
    override fun getServerOptions() = ServerOptions(
        capabilities = ServerCapabilities(tools = ServerCapabilities.Tools(listChanged = true))
    )

    override fun registerTools(server: Server) {
        server.addTool(
            name = "get_current_weather",
            description = "Get current weather for a location"
        ) { request ->
            val location = request.arguments["location"]?.jsonPrimitive?.content
            CallToolResult(content = listOf(TextContent("Weather in $location: Sunny, 25Β°C")))
        }
    }
}

3. Declare in AndroidManifest.xml

<service android:name=".WeatherMCPService" android:exported="true" android:permission="zwdroid.mcp.sdk.permission.ACCESS_MCP_SERVICES">
    <intent-filter>
        <action android:name="zwdroid.mcp.sdk.TOOLS_SERVICE" />
    </intent-filter>
    <meta-data android:name="mcp.description" android:value="Weather tools service" />
    <meta-data android:name="mcp.tools" android:resource="@raw/mcp_tools" />
</service>

Client App Integration (LLM Consumer)

1. Add Dependency

dependencies {
    implementation("com.github.AnswerZhao:android-mcp-sdk:v0.0.1")
    implementation("io.modelcontextprotocol:kotlin-sdk:0.6.0")
}

maven { url = uri("https://jitpack.io") }

2. Call Tools from Your LLM

val mcpApi = MCPApi.getInstance(context)

// Discover available tools
val tools = mcpApi.getAllAvailableTools()

// Call a specific tool
val result = mcpApi.callTool(
    "com.example.weather/.WeatherMCPService#get_current_weather",
    buildJsonObject { put("location", JsonPrimitive("San Francisco, CA")) }
)

3. Add Permissions

<uses-permission android:name="zwdroid.mcp.sdk.permission.ACCESS_MCP_SERVICES" />
<queries>
    <intent>
        <action android:name="zwdroid.mcp.sdk.TOOLS_SERVICE" />
    </intent>
</queries>

πŸ“± Sample Apps

This repository includes two fully functional demo apps:

🌀️ Weather Server App (android-mcp-server)

  • Provides weather tools (get_current_weather, get_weather_forecast)
  • Demonstrates flexible security policies
  • Shows proper tool registration and error handling

πŸ€– LLM Client App (android-mcp-client)

  • OpenAI GPT integration example
  • Real-time tool discovery and calling
  • Clean MVVM architecture with Jetpack Compose UI

Server App Client App Client App LLM

Try it yourself:

./gradlew :android-mcp-server:installDebug
./gradlew :android-mcp-client:installDebug

πŸ—οΈ How It Works

Simple Concept

Imagine a voice assistant app that can control your entire phone:

🎀 "Hey Assistant, what's the weather in San Francisco?"
   ↓
πŸ€– Voice App β†’ calls β†’ 🌀️ Weather App (via MCP) β†’ returns weather data

🎀 "Add a meeting for tomorrow at 3 PM"  
   ↓
πŸ€– Voice App β†’ calls β†’ πŸ“… Calendar App (via MCP) β†’ creates event

🎀 "Take a photo and set it as wallpaper"
   ↓  
πŸ€– Voice App β†’ calls β†’ πŸ“Έ Camera App (via MCP) β†’ captures photo
             β†’ calls β†’ 🎨 Settings App (via MCP) β†’ sets wallpaper

Before Android MCP SDK: Each app works in isolation With Android MCP SDK: One AI assistant can control all your apps

Technical Foundation

Built on proven Android technologies:

  • Model Context Protocol - Industry standard for LLM-tool communication
  • Official MCP Kotlin SDK - We extend this with Android capabilities
  • Android AIDL/Binder IPC - System-level, secure cross-process communication
  • Android Service Architecture - Standard Android patterns you already know

Architecture Overview

πŸ€– LLM Application
    ↓ (MCPApi)
πŸ“± MCPClientManager β†’ Discovers Services
    ↓ (AIDL/Binder IPC)
πŸ”§ MCPService (Your App) β†’ Exposes Tools
    ↓ (Standard MCP)
βš™οΈ Your App Functions

Key Benefits:

  • πŸš€ 5-minute integration - Add MCP support to existing Android apps
  • πŸ”’ Production security - Built-in permission system with 5 security policies
  • ⚑ High performance - Efficient Binder IPC with async coroutines
  • πŸ› οΈ Zero dependencies - Apps only need the lightweight SDK

Core Design Principles

  • Security-First: Android-native permission system with flexible access control
  • Performance-Optimized: Coroutines-based async operations, efficient resource management
  • Developer-Friendly: Intuitive APIs, extensive documentation, working examples
  • Production-Ready: Comprehensive error handling, lifecycle management, memory leak prevention
LLM Application β†’ MCPApi β†’ MCPClientManager β†’ MCPClient β†’ BinderClientTransport 
                                                              ↓
                                                          AIDL/Binder IPC
                                                              ↓
BinderServerTransport β†’ MCPServer β†’ MCPService ← Your Implementation

Core Design Principles

  • πŸ”’ Security-First: Configurable permission policies (Open, Permission-based, Signature-based, Whitelist, Custom)
  • ⚑ Performance-Optimized: Coroutines-based async operations, efficient resource management
  • 🧩 Modular Design: Clean separation between transport, client, server, and common components
  • πŸ›‘οΈ Production-Ready: Comprehensive error handling, lifecycle management, memory leak prevention
  • 🎯 Developer Experience: Intuitive APIs, extensive documentation, working examples

Technology Stack

  • MCP Kotlin SDK 0.6.0 - Official MCP protocol implementation
  • Android AIDL/Binder IPC - Cross-process communication foundation
  • Kotlin 2.2.0 with Coroutines for async operations
  • Kotlinx Serialization for efficient JSON handling

πŸ“– Documentation

🀝 Community & Contribution

We welcome contributions from the community! Here's how you can get involved:

πŸ› Issues

  • Report bugs using our issue template
  • Request features or enhancements
  • Ask questions about usage or implementation

πŸ”§ Pull Requests

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“– Documentation

  • Improve existing documentation
  • Add code examples and tutorials
  • Translate documentation to other languages

🎯 Development Setup

git clone https://github.com/your-username/android-mcp-sdk.git
cd android-mcp-sdk
./gradlew build

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments


Built with ❀️ for the Android & AI community
Extending the official MCP Kotlin SDK with Android AIDL/Binder support

About

An SDK implementing the MCP with Binder for LLM-to-app communication on Android.

Resources

License

Stars

Watchers

Forks

Packages

No packages published