@mobilenext/mobile-mcp 1.0.5 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/lib/index.js +28 -39
- package/lib/mobile-device.js +9 -1
- package/lib/server.js +22 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -75,6 +75,7 @@ How we help to scale mobile automation:
|
|
|
75
75
|
- **`mobile_get_screen_size`** - Get the screen size of the mobile device in pixels
|
|
76
76
|
- **`mobile_get_orientation`** - Get the current screen orientation of the device
|
|
77
77
|
- **`mobile_set_orientation`** - Change the screen orientation (portrait/landscape)
|
|
78
|
+
- **`mobile_fold_device`** - Fold or unfold a foldable device (iPhone Duo simulators, foldable Android emulators)
|
|
78
79
|
- **`mobile_set_location`** - Override the GPS location reported by the device, or clear the override
|
|
79
80
|
- **`mobile_clipboard`** - Read or replace the device clipboard
|
|
80
81
|
|
package/lib/index.js
CHANGED
|
@@ -2,11 +2,15 @@
|
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
const express_1 = require("@modelcontextprotocol/express");
|
|
5
|
-
const stdio_1 = require("@modelcontextprotocol/server/stdio");
|
|
6
5
|
const node_1 = require("@modelcontextprotocol/node");
|
|
7
|
-
const server_1 = require("
|
|
6
|
+
const server_1 = require("@modelcontextprotocol/server");
|
|
7
|
+
const stdio_1 = require("@modelcontextprotocol/server/stdio");
|
|
8
|
+
const server_2 = require("./server");
|
|
8
9
|
const logger_1 = require("./logger");
|
|
9
10
|
const commander_1 = require("commander");
|
|
11
|
+
const logMcpError = (err) => {
|
|
12
|
+
(0, logger_1.error)("Error handling MCP request: " + (err.stack ?? String(err)));
|
|
13
|
+
};
|
|
10
14
|
const startHttpServer = async (host, port) => {
|
|
11
15
|
// createMcpExpressApp applies express.json() and Host-header DNS rebinding
|
|
12
16
|
// protection automatically when binding to localhost / 127.0.0.1 / ::1.
|
|
@@ -36,37 +40,18 @@ const startHttpServer = async (host, port) => {
|
|
|
36
40
|
next();
|
|
37
41
|
});
|
|
38
42
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
});
|
|
52
|
-
await server.connect(transport);
|
|
53
|
-
await transport.handleRequest(req, res, req.body);
|
|
54
|
-
}
|
|
55
|
-
catch (err) {
|
|
56
|
-
(0, logger_1.error)("Error handling MCP request: " + (err instanceof Error ? err.stack : String(err)));
|
|
57
|
-
if (!res.headersSent) {
|
|
58
|
-
res.status(500).json({
|
|
59
|
-
jsonrpc: "2.0",
|
|
60
|
-
error: {
|
|
61
|
-
code: -32603,
|
|
62
|
-
message: "Internal server error",
|
|
63
|
-
},
|
|
64
|
-
id: null,
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
app.post("/mcp", handleMcpRequest);
|
|
43
|
+
// createMcpHandler serves both protocol eras from one factory: requests
|
|
44
|
+
// carrying the per-request `_meta` envelope (revision 2026-07-28, answered
|
|
45
|
+
// with `server/discover` and the modern result vocabulary) get a fresh
|
|
46
|
+
// era-marked instance, and legacy `initialize` traffic is served stateless
|
|
47
|
+
// from the same factory — the same per-request model as before.
|
|
48
|
+
// onerror keeps request-handling and transport failures in the application
|
|
49
|
+
// log (the SDK otherwise answers HTTP 500 silently).
|
|
50
|
+
const handler = (0, server_1.createMcpHandler)(() => (0, server_2.createMcpServer)(), { onerror: logMcpError });
|
|
51
|
+
const node = (0, node_1.toNodeHandler)(handler, { onerror: logMcpError });
|
|
52
|
+
app.post("/mcp", (req, res) => {
|
|
53
|
+
void node(req, res, req.body);
|
|
54
|
+
});
|
|
70
55
|
// Stateless mode has no long-lived sessions; GET (SSE stream) and DELETE
|
|
71
56
|
// (session teardown) are not applicable. Return 405 per SDK guidance.
|
|
72
57
|
const methodNotAllowed = (_req, res) => {
|
|
@@ -82,14 +67,18 @@ const startHttpServer = async (host, port) => {
|
|
|
82
67
|
app.get("/mcp", methodNotAllowed);
|
|
83
68
|
app.delete("/mcp", methodNotAllowed);
|
|
84
69
|
app.listen(port, host, () => {
|
|
85
|
-
(0, logger_1.error)(`mobile-mcp ${(0,
|
|
70
|
+
(0, logger_1.error)(`mobile-mcp ${(0, server_2.getAgentVersion)()} streamable http server listening on http://${host}:${port}/mcp`);
|
|
86
71
|
});
|
|
87
72
|
};
|
|
88
73
|
const startStdioServer = async () => {
|
|
89
74
|
try {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
75
|
+
// serveStdio owns the transport and the era decision for the
|
|
76
|
+
// connection: a `server/discover` probe (revision 2026-07-28) pins
|
|
77
|
+
// the connection modern, while an `initialize` handshake keeps
|
|
78
|
+
// serving the 2025-era protocol exactly as before. The factory runs
|
|
79
|
+
// lazily on the first message, so a failing createMcpServer() surfaces
|
|
80
|
+
// through onerror rather than the catch below.
|
|
81
|
+
(0, stdio_1.serveStdio)(() => (0, server_2.createMcpServer)(), { onerror: logMcpError });
|
|
93
82
|
// Exit cleanly on termination signals so node flushes pending work
|
|
94
83
|
// (including NODE_V8_COVERAGE output). Node's default SIGINT/SIGTERM
|
|
95
84
|
// handling terminates the process without writing the coverage file,
|
|
@@ -99,7 +88,7 @@ const startStdioServer = async () => {
|
|
|
99
88
|
};
|
|
100
89
|
process.on("SIGINT", shutdown);
|
|
101
90
|
process.on("SIGTERM", shutdown);
|
|
102
|
-
(0, logger_1.error)(`mobile-mcp ${(0,
|
|
91
|
+
(0, logger_1.error)(`mobile-mcp ${(0, server_2.getAgentVersion)()} (mcp sdk ${(0, server_2.getSdkVersion)()}) server running on stdio`);
|
|
103
92
|
}
|
|
104
93
|
catch (err) {
|
|
105
94
|
console.error("Fatal error in main():", err);
|
|
@@ -109,7 +98,7 @@ const startStdioServer = async () => {
|
|
|
109
98
|
};
|
|
110
99
|
const main = async () => {
|
|
111
100
|
commander_1.program
|
|
112
|
-
.version((0,
|
|
101
|
+
.version((0, server_2.getAgentVersion)())
|
|
113
102
|
.option("--listen <listen>", "Start Streamable HTTP server on [host:]port")
|
|
114
103
|
.option("--stdio", "Start stdio server (default)")
|
|
115
104
|
.parse(process.argv);
|
package/lib/mobile-device.js
CHANGED
|
@@ -169,7 +169,11 @@ class MobileDevice {
|
|
|
169
169
|
}
|
|
170
170
|
async getElementsOnScreen() {
|
|
171
171
|
const response = this.runJsonCommand(["dump", "ui"]);
|
|
172
|
-
|
|
172
|
+
const elements = response.data?.elements;
|
|
173
|
+
if (!elements) {
|
|
174
|
+
throw new robot_1.ActionableError("No UI hierarchy was returned for this device - its screen is most likely off or locked. Wake it up (for example with mobile_press_button using HOME, or POWER when that is supported) and try again");
|
|
175
|
+
}
|
|
176
|
+
return elements.flatMap(element => flattenUIElement(element));
|
|
173
177
|
}
|
|
174
178
|
async setOrientation(orientation) {
|
|
175
179
|
this.runCommand(["device", "orientation", "set", orientation]);
|
|
@@ -178,6 +182,10 @@ class MobileDevice {
|
|
|
178
182
|
const response = this.runJsonCommand(["device", "orientation", "get"]);
|
|
179
183
|
return response.data.orientation;
|
|
180
184
|
}
|
|
185
|
+
async fold(posture) {
|
|
186
|
+
// parse the response, older mobilecli versions print help and exit 0 on unknown commands
|
|
187
|
+
this.runJsonCommand(["device", "fold", `${posture}`]);
|
|
188
|
+
}
|
|
181
189
|
async setLocation(latitude, longitude) {
|
|
182
190
|
this.runCommand(["device", "location", "set", `${latitude},${longitude}`]);
|
|
183
191
|
}
|
package/lib/server.js
CHANGED
|
@@ -671,6 +671,28 @@ const createMcpServer = () => {
|
|
|
671
671
|
await robot.setOrientation(orientation);
|
|
672
672
|
return `Changed device orientation to ${orientation}`;
|
|
673
673
|
});
|
|
674
|
+
tool("mobile_fold_device", "Fold Device", "Fold or unfold a foldable device, such as iPhone Duo simulators and foldable Android emulators. Provide either posture or angle.", {
|
|
675
|
+
device: zod_1.z.string().describe("The device identifier to use. Use mobile_list_available_devices to find which devices are available to you."),
|
|
676
|
+
posture: zod_1.z.enum(["folded", "half-open", "open"]).optional().describe("The desired hinge posture: folded (0 degrees), half-open (90 degrees) or open (180 degrees)"),
|
|
677
|
+
angle: zod_1.z.number().min(0).max(180).optional().describe("The desired hinge angle in degrees, between 0 (folded) and 180 (open). iOS only, e.g. iPhone Duo. Use instead of posture."),
|
|
678
|
+
}, { readOnlyHint: false, destructiveHint: false, openWorldHint: false }, async ({ device, posture, angle }) => {
|
|
679
|
+
const robot = getRobotFromDevice(device);
|
|
680
|
+
if (!robot.fold) {
|
|
681
|
+
throw new robot_1.ActionableError("Folding the device is not supported in legacy robot mode");
|
|
682
|
+
}
|
|
683
|
+
if (posture !== undefined && angle !== undefined) {
|
|
684
|
+
throw new robot_1.ActionableError("Provide either posture or angle, not both");
|
|
685
|
+
}
|
|
686
|
+
if (posture === undefined && angle === undefined) {
|
|
687
|
+
throw new robot_1.ActionableError("Either posture or angle is required to fold the device");
|
|
688
|
+
}
|
|
689
|
+
if (angle !== undefined) {
|
|
690
|
+
await robot.fold(angle);
|
|
691
|
+
return `Set device hinge angle to ${angle} degrees`;
|
|
692
|
+
}
|
|
693
|
+
await robot.fold(posture);
|
|
694
|
+
return `Changed device posture to ${posture}`;
|
|
695
|
+
});
|
|
674
696
|
tool("mobile_set_location", "Set Location", "Override the GPS location reported by the device, or clear the override to restore the real location. Omit latitude and longitude to clear.", {
|
|
675
697
|
device: zod_1.z.string().describe("The device identifier to use. Use mobile_list_available_devices to find which devices are available to you."),
|
|
676
698
|
latitude: zod_1.z.number().min(-90).max(90).optional().describe("Latitude in decimal degrees, e.g. 37.7749. Omit together with longitude to clear the override."),
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mobilenext/mobile-mcp",
|
|
3
3
|
"mcpName": "io.github.mobile-next/mobile-mcp",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.7",
|
|
5
5
|
"description": "Mobile MCP",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"commander": "14.0.0",
|
|
33
33
|
"express": "5.1.0",
|
|
34
34
|
"fast-xml-parser": "5.8.0",
|
|
35
|
-
"mobilewright": "0.0.
|
|
35
|
+
"mobilewright": "0.0.63",
|
|
36
36
|
"qs": "^6.15.0",
|
|
37
37
|
"zod": "^4.2.0",
|
|
38
38
|
"zod-to-json-schema": "3.25.0"
|