只需 5 分钟,让你的 Android App 快速接入 MCP 协议,打通 LLM 的调度

一个专门针对 Android 平台的 MCP 协议实现,让原生的 Android App 快速接入,从而实现 LLM 的能力调度。实现一个 App 就是一个 MCP Server 的快速接入。

立足于官方 MCP 协议之上,以 AIDL 为纽带,让 AI 代理与 Android App 从此再无壁垒,融为一体。可以助力构建 AI App 和被 AI 使用的 App。

github.com/AnswerZhao/...

项目中有使用 OpenAI SDK + android-mcp-sdk 的接入示例,期望快速验证和体验 AI 调度的小伙伴值得一试。

🎯 适用对象

  • 🤖 AI 应用开发者:构建能够控制整个 Android 生态系统的 LLM 助手
  • 📱 Android 开发者:将您的应用能力暴露给不断增长的 AI 助手市场
  • 🏢 企业团队:为内部 Android 应用套件创建统一的 AI 接口
  • 🔬 研究人员:原型开发跨应用 AI 交互和自动化工作流

💡 解决的问题

当前状态:您的 LLM 被困在单一应用中

  • ❌ 无法访问其他 Android 应用的功能
  • ❌ 每个应用各自孤立存在
  • ❌ 仅限于内置函数功能
  • ❌ 应用暴露 AI 可调用函数没有标准方式

使用 Android MCP SDK:您的 LLM 成为系统级 AI 助手

  • ✅ 跨应用通信:调用任何启用 MCP 的 Android 应用中的函数
  • ✅ 自动发现:在整个系统中查找可用工具
  • ✅ 安全设计:Android 原生权限系统,具有灵活策略
  • ✅ 生产就绪:基于 Android 强大的 AIDL/Binder IPC 架构
  • ✅ 零应用更改:现有应用可以在不改变架构的情况下添加 MCP 支持

🚀 快速开始

服务端应用集成(工具提供者)

1. 添加依赖

scss 复制代码
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. 创建您的 MCP 服务

kotlin 复制代码
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 = "获取指定位置的当前天气"
        ) { request ->
            val location = request.arguments["location"]?.jsonPrimitive?.content
            CallToolResult(content = listOf(TextContent("$location 的天气:晴朗,25°C")))
        }
    }
}

3. 在 AndroidManifest.xml 中声明,参考示例配置 mcp_tools.json

ini 复制代码
<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="天气工具服务" />
    <meta-data android:name="mcp.tools" android:resource="@raw/mcp_tools" />
</service>

客户端应用集成(LLM 消费者)

1. 添加依赖

scss 复制代码
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. 从 LLM 中调用工具

java 复制代码
val mcpApi = MCPApi.getInstance(context)

// 发现可用工具
val tools = mcpApi.getAllAvailableTools()

// 调用特定工具
val result = mcpApi.callTool(
    "com.example.weather/.WeatherMCPService#get_current_weather",
    buildJsonObject { put("location", JsonPrimitive("旧金山,加州")) }
)

3. 添加权限

xml 复制代码
<uses-permission android:name="zwdroid.mcp.sdk.permission.ACCESS_MCP_SERVICES" />
<queries>
    <intent>
        <action android:name="zwdroid.mcp.sdk.TOOLS_SERVICE" />
    </intent>
</queries>
相关推荐
wflynn4 小时前
GitHub 日榜趋势速报 | 2026-11-03
开源·github
u1301304 小时前
GitHub 热榜项目:日榜(2026-11-03)
人工智能·github
三少爷的鞋6 小时前
Android 架构七条铁律:架构师真正设计的不是代码,而是秩序
android
xiangxiongfly9157 小时前
Android GsonFactory总结
android·gson·gsonfactory
WythePlus9 小时前
Android 14 SELinux策略深度解析
android·安全策略·selinux策略
GoGeekBaird10 小时前
别再给每个 AI 做自我介绍了:我做了一个「个人上下文」管理系统
后端·github·agent
莫晓燚11 小时前
Ansible 13 个常用模块---企业实战
git·github
程序员柒叔12 小时前
Diagram Design 解构:45 种图型如何用语义路由与 SVG 质量门交付
人工智能·github·agent·skills
逛逛GitHub12 小时前
9 个神级 GitHub 项目助你蹭上抖音、小红书 Vibe 知识大赏热点。
github
俩个逗号。。13 小时前
Kotlin flow 详解
android·开发语言·kotlin