├── .gitignore ├── tsconfig.json ├── .github └── workflows │ └── publish.yml ├── package.json ├── src ├── index.ts ├── update_claude_config.ts └── mcp_server.ts ├── LICENSE ├── README.md └── CODE_OF_CONDUCT.md /.gitignore: -------------------------------------------------------------------------------- 1 | dist 2 | node_modules -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ES2022", 4 | "module": "Node16", 5 | "moduleResolution": "Node16", 6 | "outDir": "./dist", 7 | "rootDir": "./src", 8 | "strict": true, 9 | "esModuleInterop": true, 10 | "skipLibCheck": true, 11 | "forceConsistentCasingInFileNames": true, 12 | "resolveJsonModule": true 13 | }, 14 | "include": ["src/**/*"], 15 | "exclude": ["node_modules", "**/*.spec.ts"] 16 | } -------------------------------------------------------------------------------- /.github/workflows/publish.yml: -------------------------------------------------------------------------------- 1 | name: Publish Package to npmjs 2 | on: 3 | release: 4 | types: [published] 5 | jobs: 6 | build: 7 | runs-on: ubuntu-latest 8 | permissions: 9 | contents: read 10 | id-token: write 11 | steps: 12 | - uses: actions/checkout@v4 13 | # Setup .npmrc file to publish to npm 14 | - uses: actions/setup-node@v4 15 | with: 16 | node-version: "20.x" 17 | registry-url: "https://registry.npmjs.org" 18 | - run: npm ci 19 | - run: npm run build 20 | - run: npm publish --provenance --access public 21 | env: 22 | NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} 23 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mobile-mcp", 3 | "version": "0.0.7", 4 | "description": "A MCP server to control your mobile devices", 5 | "main": "index.ts", 6 | "bin": { 7 | "mobile-mcp": "./dist/index.js" 8 | }, 9 | "scripts": { 10 | "test": "echo \"Error: no test specified\" && exit 1", 11 | "build": "tsc" 12 | }, 13 | "author": "", 14 | "license": "MIT", 15 | "dependencies": { 16 | "@modelcontextprotocol/sdk": "^1.8.0", 17 | "inquirer": "^12.5.0", 18 | "mobile-use": "^0.0.7" 19 | }, 20 | "repository": { 21 | "type": "git", 22 | "url": "https://github.com/runablehq/mobile-mcp.git" 23 | }, 24 | "devDependencies": { 25 | "@types/node": "^22.13.14", 26 | "@types/yargs": "^17.0.33", 27 | "tsconfig": "^7.0.0", 28 | "tsup": "^8.4.0", 29 | "tsx": "^4.19.3", 30 | "typescript": "^5.8.2", 31 | "yargs": "^17.7.2" 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | import { updateClaudeConfig } from "./update_claude_config"; 3 | import { startMCPServer } from "./mcp_server"; 4 | import path from "node:path"; 5 | import yargs from "yargs"; 6 | 7 | yargs 8 | .command({ 9 | command: "install", 10 | describe: "Install mobile-mcp", 11 | handler: () => { 12 | updateClaudeConfig({ 13 | name: "mobile-mcp", 14 | command: "npx", 15 | args: ["mobile-mcp"], 16 | }); 17 | }, 18 | }) 19 | .command({ 20 | command: "dev", 21 | describe: "Install mobile-mcp in development mode", 22 | handler: () => { 23 | updateClaudeConfig({ 24 | name: "mobile-mcp-dev", 25 | command: "node", 26 | args: [path.join(__dirname, "../dist/index.js")], 27 | }); 28 | }, 29 | }) 30 | .command({ 31 | command: "*", 32 | handler: () => { 33 | startMCPServer(); 34 | }, 35 | }) 36 | .help().argv; 37 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2025 cloudycotton 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Mobile MCP 2 | 3 | A Model Context Protocol (MCP) server that provides mobile automation capabilities. This server enables LLMs to interact with mobile devices using structured UI dumps without needing to rely on screenshots or other visual inputs. 4 | 5 | [![MIT License](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE) [![Discord](https://img.shields.io/badge/discord-purple.svg)](https://discord.runable.xyz) 6 | 7 | https://github.com/user-attachments/assets/f6d9c88e-005a-4a99-b073-3308b1fbca12 8 | 9 | ## Installation 10 | 11 | ## Supported Platforms 12 | 13 | Currently, only android phones are supported. iOS support will come soon. 14 | 15 | You need to [install android studio](https://developer.android.com/studio/install) and have platform tools installed. Run the following to command to verify once you have installed all this. 16 | 17 | ```sh 18 | adb 19 | ``` 20 | 21 | You can run an [android device in an emulator](https://developer.android.com/studio/run/emulator) or connect your physical android phone with usb debugging on. 22 | 23 | ### Claude Desktop Configuration 24 | Run the following command to install it automatically 25 | 26 | ```sh 27 | npx mobile-mcp install 28 | ``` 29 | 30 | or add this to your claude desktop config manually. 31 | 32 | ```json 33 | { 34 | "mcpServers": { 35 | "mobile-mcp": { 36 | "command": "npx", 37 | "args": ["mobile-mcp"] 38 | } 39 | } 40 | } 41 | ``` 42 | 43 | ## VScode Installation 44 | 45 | You can install the mobile MCP server using the VS Code CLI: 46 | 47 | ```bash 48 | # For VS Code 49 | code --add-mcp '{"name":"mobile","command":"npx","args":["mobile-mcp"]}' 50 | 51 | # For VS Code Insiders 52 | code-insiders --add-mcp '{"name":"mobile","command":"npx","args":["mobile-mcp"]}' 53 | ``` 54 | 55 | ## 📄 License 56 | 57 | This project is licensed under the [MIT License](LICENSE). 58 | -------------------------------------------------------------------------------- /src/update_claude_config.ts: -------------------------------------------------------------------------------- 1 | import path from "node:path"; 2 | import os from "node:os"; 3 | import fs from "fs/promises"; 4 | import inquirer from "inquirer"; 5 | 6 | function getClaudeConfigDir() { 7 | switch (os.platform()) { 8 | case "darwin": 9 | return path.join( 10 | os.homedir(), 11 | "Library", 12 | "Application Support", 13 | "Claude" 14 | ); 15 | case "win32": 16 | if (!process.env.APPDATA) { 17 | throw new Error("APPDATA environment variable is not set"); 18 | } 19 | return path.join(process.env.APPDATA, "Claude"); 20 | default: 21 | throw new Error( 22 | `Unsupported operating system for Claude configuration: ${os.platform()}` 23 | ); 24 | } 25 | } 26 | 27 | interface MCPConfig { 28 | name: string; 29 | command: string; 30 | args: string[]; 31 | } 32 | 33 | export async function updateClaudeConfig({ name, command, args }: MCPConfig) { 34 | try { 35 | const configFile = path.join( 36 | getClaudeConfigDir(), 37 | "claude_desktop_config.json" 38 | ); 39 | let config; 40 | 41 | try { 42 | config = JSON.parse(await fs.readFile(configFile, "utf-8")); 43 | } catch (err: any) { 44 | if (err.code !== "ENOENT") { 45 | throw err; 46 | } 47 | // File doesn't exist, create initial config 48 | config = {}; 49 | await fs.mkdir(path.dirname(configFile), { recursive: true }); 50 | } 51 | 52 | if (!config.mcpServers) { 53 | config.mcpServers = {}; 54 | } 55 | 56 | if (config.mcpServers[name]) { 57 | const { replace } = await inquirer.prompt([ 58 | { 59 | type: "confirm", 60 | name: "replace", 61 | message: `An MCP server named "${name}" is already configured for Claude.app. Do you want to replace it?`, 62 | default: false, 63 | }, 64 | ]); 65 | if (!replace) { 66 | console.log( 67 | `⚠️ Skipped replacing Claude.app config for existing MCP server "${name}"` 68 | ); 69 | return; 70 | } 71 | } 72 | 73 | config.mcpServers[name] = { 74 | command, 75 | args, 76 | }; 77 | 78 | await fs.writeFile(configFile, JSON.stringify(config, null, 2)); 79 | console.log("✅ Successfully added MCP server to Claude.app configuration"); 80 | } catch { 81 | console.log("⚠️ Note: Could not update Claude.app configuration"); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/mcp_server.ts: -------------------------------------------------------------------------------- 1 | import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; 2 | import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"; 3 | import { z } from "zod"; 4 | import { ADBClient } from "mobile-use"; 5 | 6 | const adb = new ADBClient(); 7 | 8 | // Create an MCP server 9 | const server = new McpServer( 10 | { 11 | name: "Mobile MCP", 12 | version: "0.0.7", 13 | }, 14 | { 15 | instructions: `Before doing anything, you need to initialize the mobile by using mobile_init. 16 | 17 | Use mobile_dump_ui for navigating and interacting with the apps. Use mobile_screenshot as fallback to understand the context. 18 | 19 | `, 20 | } 21 | ); 22 | 23 | // Initialize ADB client 24 | // ADB Tools 25 | server.tool( 26 | "mobile_dump_ui", 27 | "Get a detailed hierarchy of all interactive UI elements on the current screen, including their positions, text, and attributes. Use this when you want to navigate or take actions.", 28 | {}, 29 | async () => { 30 | const ui = await adb.dumpUI(); 31 | return { content: [{ type: "text", text: ui }] }; 32 | } 33 | ); 34 | 35 | server.tool( 36 | "mobile_tap", 37 | "Simulate a tap gesture at specific x,y coordinates on the screen to interact with UI elements", 38 | { x: z.number(), y: z.number() }, 39 | async ({ x, y }) => { 40 | await adb.tap({ x, y }); 41 | return { content: [{ type: "text", text: `Tapped at (${x}, ${y})` }] }; 42 | } 43 | ); 44 | 45 | server.tool( 46 | "mobile_swipe", 47 | "Perform a swipe gesture from one coordinate to another, optionally specifying duration in milliseconds", 48 | { 49 | startX: z.number(), 50 | startY: z.number(), 51 | endX: z.number(), 52 | endY: z.number(), 53 | duration: z.number().optional(), 54 | }, 55 | async ({ startX, startY, endX, endY, duration }) => { 56 | await adb.swipe({ x: startX, y: startY }, { x: endX, y: endY }, duration); 57 | return { 58 | content: [ 59 | { 60 | type: "text", 61 | text: `Swiped from (${startX}, ${startY}) to (${endX}, ${endY})`, 62 | }, 63 | ], 64 | }; 65 | } 66 | ); 67 | 68 | server.tool( 69 | "mobile_type", 70 | "Input text into the currently focused text field or input box", 71 | { text: z.string() }, 72 | async ({ text }) => { 73 | await adb.type(text); 74 | return { content: [{ type: "text", text: `Typed: ${text}` }] }; 75 | } 76 | ); 77 | 78 | server.tool( 79 | "mobile_key_press", 80 | "Simulate pressing a specific key or button (e.g., 'enter', 'back', 'home')", 81 | { key: z.string() }, 82 | async ({ key }) => { 83 | await adb.keyPress(key); 84 | return { content: [{ type: "text", text: `Pressed key: ${key}` }] }; 85 | } 86 | ); 87 | 88 | server.tool( 89 | "mobile_screenshot", 90 | "Capture the current screen state as an image, useful for visual verification or when UI hierarchy is insufficient.", 91 | {}, 92 | async () => { 93 | const screenshot = await adb.screenshot(); 94 | const size = await adb.screenSize(); 95 | return { 96 | content: [ 97 | { 98 | type: "text", 99 | text: `Screenshot captured at width: ${size.width}px and height: ${size.height}px`, 100 | }, 101 | { 102 | data: screenshot.toString("base64"), 103 | mimeType: "image/png", 104 | type: "image", 105 | }, 106 | ], 107 | }; 108 | } 109 | ); 110 | 111 | server.tool( 112 | "mobile_list_packages", 113 | "List all installed packages on the device, optionally filtered by a search term", 114 | { filter: z.string().optional() }, 115 | async ({ filter }) => { 116 | const packages = await adb.listPackages(filter); 117 | return { content: [{ type: "text", text: JSON.stringify(packages) }] }; 118 | } 119 | ); 120 | 121 | server.tool( 122 | "mobile_open_app", 123 | "Open an application using its package name", 124 | { packageName: z.string() }, 125 | async ({ packageName }) => { 126 | await adb.openApp(packageName); 127 | return { content: [{ type: "text", text: `Opened app: ${packageName}` }] }; 128 | } 129 | ); 130 | 131 | server.tool( 132 | "mobile_init", 133 | "Use this command to initalize mobile device.", 134 | {}, 135 | async () => { 136 | try { 137 | await adb.init(); 138 | return { 139 | content: [ 140 | { 141 | type: "text", 142 | text: `Successfully initialized mobile devices.`, 143 | }, 144 | ], 145 | }; 146 | } catch (error: any) { 147 | return { 148 | content: [ 149 | { 150 | type: "text", 151 | text: `Couldn't initalize the device.\n${error.message}`, 152 | }, 153 | ], 154 | }; 155 | } 156 | } 157 | ); 158 | 159 | export async function startMCPServer() { 160 | try { 161 | const transport = new StdioServerTransport(); 162 | await server.connect(transport); 163 | console.error("Mobile use mcp server is running."); 164 | } catch (error) { 165 | console.error("Error starting MCP server:", error); 166 | } 167 | } 168 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | We as members, contributors, and leaders pledge to make participation in our 6 | community a harassment-free experience for everyone, regardless of age, body 7 | size, visible or invisible disability, ethnicity, sex characteristics, gender 8 | identity and expression, level of experience, education, socio-economic status, 9 | nationality, personal appearance, race, caste, color, religion, or sexual 10 | identity and orientation. 11 | 12 | We pledge to act and interact in ways that contribute to an open, welcoming, 13 | diverse, inclusive, and healthy community. 14 | 15 | ## Our Standards 16 | 17 | Examples of behavior that contributes to a positive environment for our 18 | community include: 19 | 20 | - Demonstrating empathy and kindness toward other people 21 | - Being respectful of differing opinions, viewpoints, and experiences 22 | - Giving and gracefully accepting constructive feedback 23 | - Accepting responsibility and apologizing to those affected by our mistakes, 24 | and learning from the experience 25 | - Focusing on what is best not just for us as individuals, but for the overall 26 | community 27 | 28 | Examples of unacceptable behavior include: 29 | 30 | - The use of sexualized language or imagery, and sexual attention or advances of 31 | any kind 32 | - Trolling, insulting or derogatory comments, and personal or political attacks 33 | - Public or private harassment 34 | - Publishing others' private information, such as a physical or email address, 35 | without their explicit permission 36 | - Other conduct which could reasonably be considered inappropriate in a 37 | professional setting 38 | 39 | ## Enforcement Responsibilities 40 | 41 | Community leaders are responsible for clarifying and enforcing our standards of 42 | acceptable behavior and will take appropriate and fair corrective action in 43 | response to any behavior that they deem inappropriate, threatening, offensive, 44 | or harmful. 45 | 46 | Community leaders have the right and responsibility to remove, edit, or reject 47 | comments, commits, code, wiki edits, issues, and other contributions that are 48 | not aligned to this Code of Conduct, and will communicate reasons for moderation 49 | decisions when appropriate. 50 | 51 | ## Scope 52 | 53 | This Code of Conduct applies within all community spaces, and also applies when 54 | an individual is officially representing the community in public spaces. 55 | Examples of representing our community include using an official email address, 56 | posting via an official social media account, or acting as an appointed 57 | representative at an online or offline event. 58 | 59 | ## Enforcement 60 | 61 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 62 | reported to the community leaders responsible for enforcement to @cloudycotton. 63 | All complaints will be reviewed and investigated promptly and fairly. 64 | 65 | All community leaders are obligated to respect the privacy and security of the 66 | reporter of any incident. 67 | 68 | ## Enforcement Guidelines 69 | 70 | Community leaders will follow these Community Impact Guidelines in determining 71 | the consequences for any action they deem in violation of this Code of Conduct: 72 | 73 | ### 1. Correction 74 | 75 | **Community Impact**: Use of inappropriate language or other behavior deemed 76 | unprofessional or unwelcome in the community. 77 | 78 | **Consequence**: A private, written warning from community leaders, providing 79 | clarity around the nature of the violation and an explanation of why the 80 | behavior was inappropriate. A public apology may be requested. 81 | 82 | ### 2. Warning 83 | 84 | **Community Impact**: A violation through a single incident or series of 85 | actions. 86 | 87 | **Consequence**: A warning with consequences for continued behavior. No 88 | interaction with the people involved, including unsolicited interaction with 89 | those enforcing the Code of Conduct, for a specified period of time. This 90 | includes avoiding interactions in community spaces as well as external channels 91 | like social media. Violating these terms may lead to a temporary or permanent 92 | ban. 93 | 94 | ### 3. Temporary Ban 95 | 96 | **Community Impact**: A serious violation of community standards, including 97 | sustained inappropriate behavior. 98 | 99 | **Consequence**: A temporary ban from any sort of interaction or public 100 | communication with the community for a specified period of time. No public or 101 | private interaction with the people involved, including unsolicited interaction 102 | with those enforcing the Code of Conduct, is allowed during this period. 103 | Violating these terms may lead to a permanent ban. 104 | 105 | ### 4. Permanent Ban 106 | 107 | **Community Impact**: Demonstrating a pattern of violation of community 108 | standards, including sustained inappropriate behavior, harassment of an 109 | individual, or aggression toward or disparagement of classes of individuals. 110 | 111 | **Consequence**: A permanent ban from any sort of public interaction within the 112 | community. 113 | 114 | ## Attribution 115 | 116 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 117 | version 2.1, available at 118 | [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1]. 119 | 120 | Community Impact Guidelines were inspired by 121 | [Mozilla's code of conduct enforcement ladder][Mozilla CoC]. 122 | 123 | For answers to common questions about this code of conduct, see the FAQ at 124 | [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at 125 | [https://www.contributor-covenant.org/translations][translations]. 126 | 127 | [homepage]: https://www.contributor-covenant.org 128 | [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html 129 | [Mozilla CoC]: https://github.com/mozilla/diversity 130 | [FAQ]: https://www.contributor-covenant.org/faq 131 | [translations]: https://www.contributor-covenant.org/translations 132 | --------------------------------------------------------------------------------