Mobile MCP: let AI agents drive your iOS and Android apps. MCP server for simulators, emulators and real devices. Works with Claude Code, Codex, Cursor and any MCP client.
TypeScript agentandroidandroid-automationappium-alternativeclaude-codecodexcursoremulatoriosios-automationmcpmcp-servermobilemobile-automationmobile-testingreal-devicesimulatorskills
feat: add install command that configures detected MCP clients (#531)
Gil Megidishc79d9470527b
diff --git a/README.ja.md b/README.ja.mdindex e2e805a..dbffd58 100644--- a/README.ja.md+++ b/README.ja.md@@ -34,6 +34,18 @@https://github.com/user-attachments/assets/bb084777-beb3-4930-ae6f-8d3fe694ddde+## 🚀 クイックスタート++**クイックインストール**: このマシン上の MCP クライアント(Claude Code、Codex、Cursor、VS Code、Gemini CLI など)を検出し、設定するクライアントを選択できます:++```bash+npx @mobilenext/mobile-mcp@latest install+```++`--yes` を付けると、確認なしで検出されたすべてのクライアントを設定します。++クライアントごとの手動設定: [インストールと設定](#インストールと設定)+<p align="center"><a href="https://github.com/mobile-next/">@@ -144,7 +156,7 @@ MCP をエージェントおよびモバイルデバイスに接続するため## インストールと設定-**標準設定** はほとんどのツールで動作します:+ほとんどのツールで動作する **標準設定**:```json{diff --git a/README.md b/README.mdindex e4468ad..f19da1a 100644--- a/README.md+++ b/README.md@@ -43,6 +43,18 @@ Run it against devices on your own machine, or against real iOS and Android devihttps://github.com/user-attachments/assets/bb084777-beb3-4930-ae6f-8d3fe694ddde+## 🚀 Quick start++**Quick install** detects the MCP clients on this machine (Claude Code, Codex, Cursor, VS Code, Gemini CLI and more) and lets you pick which ones to configure:++```bash+npx @mobilenext/mobile-mcp@latest install+```++Add `--yes` to configure every detected client without asking.++Manual setup per client: [Installation and configuration](#installation-and-configuration)+<p align="center"><a href="https://github.com/mobile-next/">@@ -154,7 +166,7 @@ What you will need to connect MCP with your agent and mobile devices:## Installation and configuration-**Standard config** works in most of the tools:+To configure it by hand, this **standard config** works in most of the tools:```json{diff --git a/README.zh-CN.md b/README.zh-CN.mdindex 9456169..5edb796 100644--- a/README.zh-CN.md+++ b/README.zh-CN.md@@ -34,6 +34,18 @@https://github.com/user-attachments/assets/bb084777-beb3-4930-ae6f-8d3fe694ddde+## 🚀 快速开始++**快速安装**:自动检测本机上的 MCP 客户端(Claude Code、Codex、Cursor、VS Code、Gemini CLI 等),并让你选择要配置哪些:++```bash+npx @mobilenext/mobile-mcp@latest install+```++加上 `--yes` 可不经询问直接配置所有检测到的客户端。++各客户端的手动配置: [安装与配置](#安装与配置)+<p align="center"><a href="https://github.com/mobile-next/">@@ -144,7 +156,7 @@ https://github.com/user-attachments/assets/bb084777-beb3-4930-ae6f-8d3fe694ddde## 安装与配置-**标准配置** 适用于大多数工具:+适用于大多数工具的 **标准配置**:```json{diff --git a/package-lock.json b/package-lock.jsonindex b0411a0..fa921b9 100644--- a/package-lock.json+++ b/package-lock.json@@ -9,9 +9,11 @@"version": "0.0.1","license": "Apache-2.0","dependencies": {+ "@clack/prompts": "^0.9.1","@modelcontextprotocol/express": "2.0.2","@modelcontextprotocol/node": "2.0.0","@modelcontextprotocol/server": "2.4.0",+ "add-mcp": "^2.6.0","ajv": "^8.18.0","commander": "14.0.0","express": "5.1.0",@@ -58,6 +60,27 @@"node": ">=18"}},+ "node_modules/@clack/core": {+ "version": "0.4.1",+ "resolved": "https://registry.npmjs.org/@clack/core/-/core-0.4.1.tgz",+ "integrity": "sha512-Pxhij4UXg8KSr7rPek6Zowm+5M22rbd2g1nfojHJkxp5YkFqiZ2+YLEM/XGVIzvGOcM0nqjIFxrpDwWRZYWYjA==",+ "license": "MIT",+ "dependencies": {+ "picocolors": "^1.0.0",+ "sisteransi": "^1.0.5"+ }+ },+ "node_modules/@clack/prompts": {+ "version": "0.9.1",+ "resolved": "https://registry.npmjs.org/@clack/prompts/-/prompts-0.9.1.tgz",+ "integrity": "sha512-JIpyaboYZeWYlyP0H+OoPPxd6nqueG/CmN6ixBiNFsIDHREevjIf0n0Ohh5gr5C8pEDknzgvz+pIJ8dMhzWIeg==",+ "license": "MIT",+ "dependencies": {+ "@clack/core": "0.4.1",+ "picocolors": "^1.0.0",+ "sisteransi": "^1.0.5"+ }+ },"node_modules/@eslint-community/eslint-utils": {"version": "4.10.1","resolved": "https://registry.npmjs.org/@eslint-community/eslint-utils/-/eslint-utils-4.10.1.tgz",@@ -304,6 +327,12 @@"url": "https://github.com/sponsors/nzakas"}},+ "node_modules/@iarna/toml": {+ "version": "2.2.5",+ "resolved": "https://registry.npmjs.org/@iarna/toml/-/toml-2.2.5.tgz",+ "integrity": "sha512-trnsAYxU3xnS1gPHPyU961coFyLkh4gAD/0zQ5mymY4yOZ+CYvsPqUbOFSw0aDM4y0tV7tiFxL/1XfXPNC6IPg==",+ "license": "ISC"+ },"node_modules/@isaacs/cliui": {"version": "8.0.2","resolved": "https://registry.npmjs.org/@isaacs/cliui/-/cliui-8.0.2.tgz",@@ -1202,6 +1231,47 @@"acorn": "^6.0.0 || ^7.0.0 || ^8.0.0"}},+ "node_modules/add-mcp": {+ "version": "2.6.0",+ "resolved": "https://registry.npmjs.org/add-mcp/-/add-mcp-2.6.0.tgz",+ "integrity": "sha512-Gc6L0YfX9c2wrN/jg49N1A8QrXxlDvdHlz9zsK3XXbuRJrDXV2znMMAmLdwh7AVnGxT24Vltc3MFYIK81PNABQ==",+ "license": "Apache-2.0",+ "dependencies": {+ "@clack/prompts": "^0.9.1",+ "@iarna/toml": "^2.2.5",+ "chalk": "^5.4.1",+ "commander": "^13.1.0",+ "jsonc-parser": "^3.3.1",+ "yaml": "^2.9.1"+ },+ "bin": {+ "add-mcp": "dist/index.js"+ },+ "engines": {+ "node": ">=18"+ }+ },+ "node_modules/add-mcp/node_modules/chalk": {+ "version": "5.6.2",+ "resolved": "https://registry.npmjs.org/chalk/-/chalk-5.6.2.tgz",+ "integrity": "sha512-7NzBL0rN6fMUW+f7A6Io4h40qQlG+xGmtMxfbnH/K7TAtt8JQWVQK+6g0UXKMeVJoyV5EkkNsErQ8pVD3bLHbA==",+ "license": "MIT",+ "engines": {+ "node": "^12.17.0 || ^14.13 || >=16.0.0"+ },+ "funding": {+ "url": "https://github.com/chalk/chalk?sponsor=1"+ }+ },+ "node_modules/add-mcp/node_modules/commander": {+ "version": "13.1.0",+ "resolved": "https://registry.npmjs.org/commander/-/commander-13.1.0.tgz",+ "integrity": "sha512-/rFeCpNJQbhSZjGVwO9RFV3xPqbnERS8MmIQzCtD/zl6gpJuV/bMLuN92oG3F7d8oDEHHRrujSXNUr8fpjntKw==",+ "license": "MIT",+ "engines": {+ "node": ">=18"+ }+ },"node_modules/ajv": {"version": "8.20.0","resolved": "https://registry.npmjs.org/ajv/-/ajv-8.20.0.tgz",@@ -3894,6 +3964,12 @@"json5": "lib/cli.js"}},+ "node_modules/jsonc-parser": {+ "version": "3.3.1",+ "resolved": "https://registry.npmjs.org/jsonc-parser/-/jsonc-parser-3.3.1.tgz",+ "integrity": "sha512-HUgH65KyejrUFPvHFPbqOY0rsFip3Bo5wb4ngvdi1EpCYWUQDC5V+Y7mZws+DLkr4M//zQJoanu1SP+87Dv1oQ==",+ "license": "MIT"+ },"node_modules/keyv": {"version": "4.5.4","resolved": "https://registry.npmjs.org/keyv/-/keyv-4.5.4.tgz",@@ -4545,6 +4621,12 @@"url": "https://opencollective.com/express"}},+ "node_modules/picocolors": {+ "version": "1.1.1",+ "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz",+ "integrity": "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==",+ "license": "ISC"+ },"node_modules/picomatch": {"version": "4.0.7","resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.7.tgz",@@ -5108,6 +5190,12 @@"url": "https://github.com/sponsors/isaacs"}},+ "node_modules/sisteransi": {+ "version": "1.0.5",+ "resolved": "https://registry.npmjs.org/sisteransi/-/sisteransi-1.0.5.tgz",+ "integrity": "sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg==",+ "license": "MIT"+ },"node_modules/statuses": {"version": "2.0.2","resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.2.tgz",@@ -5947,6 +6035,21 @@"node": ">=10"}},+ "node_modules/yaml": {+ "version": "2.9.1",+ "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.9.1.tgz",+ "integrity": "sha512-3NxN8+78OdzbT7C/WjGsyfPAtJaN3FNDsWxv7Y7mcDsT/oOmgW8BpyQQFFBnvZE3j9Y2Sdz1ULFLezL7Eb2yFw==",+ "license": "ISC",+ "bin": {+ "yaml": "bin.mjs"+ },+ "engines": {+ "node": ">= 14.6"+ },+ "funding": {+ "url": "https://github.com/sponsors/eemeli"+ }+ },"node_modules/yargs": {"version": "17.7.3","resolved": "https://registry.npmjs.org/yargs/-/yargs-17.7.3.tgz",diff --git a/package.json b/package.jsonindex e083e23..65b7b4f 100644--- a/package.json+++ b/package.json@@ -25,9 +25,11 @@"lib"],"dependencies": {+ "@clack/prompts": "^0.9.1","@modelcontextprotocol/express": "2.0.2","@modelcontextprotocol/node": "2.0.0","@modelcontextprotocol/server": "2.4.0",+ "add-mcp": "^2.6.0","ajv": "^8.18.0","commander": "14.0.0","express": "5.1.0",diff --git a/src/index.ts b/src/index.tsindex 9d1165b..f6df8df 100644--- a/src/index.ts+++ b/src/index.ts@@ -8,6 +8,8 @@ import { error } from "./logger";import { Request, Response } from "express";import { program } from "commander";+type InstallOptions = { yes?: boolean };+const logMcpError = (err: Error) => {error("Error handling MCP request: " + (err.stack ?? String(err)));};@@ -110,13 +112,46 @@ const startStdioServer = async () => {}};-const main = async () => {- program- .version(getAgentVersion())- .option("--listen <listen>", "Start Streamable HTTP server on [host:]port")- .option("--stdio", "Start stdio server (default)")- .parse(process.argv);+const installIntoDetectedClients = async (options: InstallOptions) => {+ // add-mcp is ESM-only, loaded lazily so a normal server start does not pay for it+ const { agents, detectGlobalAgents, upsertServer } = await import("add-mcp");+ const prompts = await import("@clack/prompts");+ const config = { command: "npx", args: ["-y", "@mobilenext/mobile-mcp@latest"] };+ const detected = await detectGlobalAgents();+ if (detected.length === 0) {+ console.log("No MCP clients detected. See https://github.com/mobile-next/mobile-mcp#installation-and-configuration");+ return;+ }+ // no terminal to draw checkboxes on (e.g. an agent ran us), so behave like --yes+ let selected = detected;+ if (!options.yes && process.stdin.isTTY) {+ const answer = await prompts.multiselect({+ message: "Install mobile-mcp into which clients?",+ options: detected.map(agent => ({ value: agent, label: agents[agent].displayName })),+ initialValues: detected,+ required: false,+ });+ if (prompts.isCancel(answer)) {+ prompts.cancel("Installation cancelled.");+ return;+ }++ selected = answer;+ }++ for (const agent of selected) {+ const result = upsertServer(agent, "mobile-mcp", config);+ if (result.success) {+ console.log(`✓ ${agents[agent].displayName}: ${result.path}`);+ } else {+ console.log(`✗ ${agents[agent].displayName}: ${result.error}`);+ process.exitCode = 1;+ }+ }+};++const startServer = async () => {const options = program.opts();if (options.listen) {@@ -144,4 +179,20 @@ const main = async () => {}};+const main = async () => {+ program+ .version(getAgentVersion())+ .option("--listen <listen>", "Start Streamable HTTP server on [host:]port")+ .option("--stdio", "Start stdio server (default)")+ .action(startServer);++ program+ .command("install")+ .description("Add mobile-mcp to the MCP clients detected on this machine")+ .option("-y, --yes", "Install into every detected client without asking")+ .action(installIntoDetectedClients);++ await program.parseAsync(process.argv);+};+main().then();diff --git a/tsconfig.json b/tsconfig.jsonindex 04116e1..96cfdc4 100644--- a/tsconfig.json+++ b/tsconfig.json@@ -3,9 +3,9 @@"target": "ESNext","skipLibCheck": true,"esModuleInterop": true,- "moduleResolution": "node",+ "moduleResolution": "node16","strict": true,- "module": "CommonJS",+ "module": "node16","outDir": "./lib"},"include": [