@mobilenext/mobile-mcp 1.0.2 → 1.0.4
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.ja.md +577 -0
- package/README.md +49 -18
- package/README.zh-CN.md +577 -0
- package/lib/coordinate-mapping.js +27 -0
- package/lib/format-elements.js +82 -0
- package/lib/index.js +65 -39
- package/lib/jpeg.js +41 -0
- package/lib/mobile-device.js +85 -6
- package/lib/mobilecli.js +18 -14
- package/lib/server.js +247 -91
- package/package.json +4 -3
- package/lib/image-utils.js +0 -155
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.4",
|
|
5
5
|
"description": "Mobile MCP",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
"license": "Apache-2.0",
|
|
14
14
|
"scripts": {
|
|
15
15
|
"build": "tsc && chmod +x lib/index.js",
|
|
16
|
+
"start": "node lib/index.js",
|
|
16
17
|
"lint": "eslint .",
|
|
17
18
|
"fixlint": "eslint . --fix",
|
|
18
19
|
"test": "c8 playwright test",
|
|
@@ -24,12 +25,12 @@
|
|
|
24
25
|
"lib"
|
|
25
26
|
],
|
|
26
27
|
"dependencies": {
|
|
27
|
-
"@modelcontextprotocol/sdk": "1.
|
|
28
|
+
"@modelcontextprotocol/sdk": "1.30.0",
|
|
28
29
|
"ajv": "^8.18.0",
|
|
29
30
|
"commander": "14.0.0",
|
|
30
31
|
"express": "5.1.0",
|
|
31
32
|
"fast-xml-parser": "5.8.0",
|
|
32
|
-
"mobilewright": "0.0.
|
|
33
|
+
"mobilewright": "0.0.57",
|
|
33
34
|
"qs": "^6.15.0",
|
|
34
35
|
"zod": "^4.1.13",
|
|
35
36
|
"zod-to-json-schema": "3.25.0"
|
package/lib/image-utils.js
DELETED
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.isScalingAvailable = exports.isImageMagickInstalled = exports.isSipsInstalled = exports.Image = exports.ImageTransformer = void 0;
|
|
7
|
-
const child_process_1 = require("child_process");
|
|
8
|
-
const node_os_1 = __importDefault(require("node:os"));
|
|
9
|
-
const node_fs_1 = __importDefault(require("node:fs"));
|
|
10
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
11
|
-
const logger_1 = require("./logger");
|
|
12
|
-
const DEFAULT_JPEG_QUALITY = 75;
|
|
13
|
-
class ImageTransformer {
|
|
14
|
-
buffer;
|
|
15
|
-
newWidth = 0;
|
|
16
|
-
newFormat = "png";
|
|
17
|
-
jpegOptions = { quality: DEFAULT_JPEG_QUALITY };
|
|
18
|
-
constructor(buffer) {
|
|
19
|
-
this.buffer = buffer;
|
|
20
|
-
}
|
|
21
|
-
resize(width) {
|
|
22
|
-
this.newWidth = width;
|
|
23
|
-
return this;
|
|
24
|
-
}
|
|
25
|
-
jpeg(options) {
|
|
26
|
-
this.newFormat = "jpg";
|
|
27
|
-
this.jpegOptions = options;
|
|
28
|
-
return this;
|
|
29
|
-
}
|
|
30
|
-
png() {
|
|
31
|
-
this.newFormat = "png";
|
|
32
|
-
return this;
|
|
33
|
-
}
|
|
34
|
-
toBuffer() {
|
|
35
|
-
if ((0, exports.isSipsInstalled)()) {
|
|
36
|
-
try {
|
|
37
|
-
return this.toBufferWithSips();
|
|
38
|
-
}
|
|
39
|
-
catch (error) {
|
|
40
|
-
(0, logger_1.trace)(`Sips failed, falling back to ImageMagick: ${error}`);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
try {
|
|
44
|
-
return this.toBufferWithImageMagick();
|
|
45
|
-
}
|
|
46
|
-
catch (error) {
|
|
47
|
-
(0, logger_1.trace)(`ImageMagick failed: ${error}`);
|
|
48
|
-
throw new Error("Image scaling unavailable (requires Sips or ImageMagick).");
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
qualityToSips(q) {
|
|
52
|
-
if (q >= 90) {
|
|
53
|
-
return "best";
|
|
54
|
-
}
|
|
55
|
-
if (q >= 75) {
|
|
56
|
-
return "high";
|
|
57
|
-
}
|
|
58
|
-
if (q >= 50) {
|
|
59
|
-
return "normal";
|
|
60
|
-
}
|
|
61
|
-
return "low";
|
|
62
|
-
}
|
|
63
|
-
toBufferWithSips() {
|
|
64
|
-
const tempDir = node_fs_1.default.mkdtempSync(node_path_1.default.join(node_os_1.default.tmpdir(), "image-"));
|
|
65
|
-
const inputFile = node_path_1.default.join(tempDir, "input");
|
|
66
|
-
const outputFile = node_path_1.default.join(tempDir, `output.${this.newFormat === "jpg" ? "jpg" : "png"}`);
|
|
67
|
-
try {
|
|
68
|
-
node_fs_1.default.writeFileSync(inputFile, this.buffer);
|
|
69
|
-
const args = ["-s", "format", this.newFormat === "jpg" ? "jpeg" : "png"];
|
|
70
|
-
if (this.newFormat === "jpg") {
|
|
71
|
-
args.push("-s", "formatOptions", this.qualityToSips(this.jpegOptions.quality));
|
|
72
|
-
}
|
|
73
|
-
args.push("-Z", `${this.newWidth}`);
|
|
74
|
-
args.push("--out", outputFile);
|
|
75
|
-
args.push(inputFile);
|
|
76
|
-
(0, logger_1.trace)(`Running sips command: /usr/bin/sips ${args.join(" ")}`);
|
|
77
|
-
const proc = (0, child_process_1.spawnSync)("/usr/bin/sips", args, {
|
|
78
|
-
maxBuffer: 8 * 1024 * 1024
|
|
79
|
-
});
|
|
80
|
-
if (proc.status !== 0) {
|
|
81
|
-
throw new Error(`Sips failed with status ${proc.status}`);
|
|
82
|
-
}
|
|
83
|
-
const outputBuffer = node_fs_1.default.readFileSync(outputFile);
|
|
84
|
-
(0, logger_1.trace)("Sips returned buffer of size: " + outputBuffer.length);
|
|
85
|
-
return outputBuffer;
|
|
86
|
-
}
|
|
87
|
-
finally {
|
|
88
|
-
try {
|
|
89
|
-
node_fs_1.default.rmSync(tempDir, { recursive: true, force: true });
|
|
90
|
-
}
|
|
91
|
-
catch (error) {
|
|
92
|
-
// Ignore cleanup errors
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
toBufferWithImageMagick() {
|
|
97
|
-
const magickArgs = ["-", "-resize", `${this.newWidth}x`, "-quality", `${this.jpegOptions.quality}`, `${this.newFormat}:-`];
|
|
98
|
-
(0, logger_1.trace)(`Running magick command: magick ${magickArgs.join(" ")}`);
|
|
99
|
-
const proc = (0, child_process_1.spawnSync)("magick", magickArgs, {
|
|
100
|
-
maxBuffer: 8 * 1024 * 1024,
|
|
101
|
-
input: this.buffer
|
|
102
|
-
});
|
|
103
|
-
return proc.stdout;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
exports.ImageTransformer = ImageTransformer;
|
|
107
|
-
class Image {
|
|
108
|
-
buffer;
|
|
109
|
-
constructor(buffer) {
|
|
110
|
-
this.buffer = buffer;
|
|
111
|
-
}
|
|
112
|
-
static fromBuffer(buffer) {
|
|
113
|
-
return new Image(buffer);
|
|
114
|
-
}
|
|
115
|
-
resize(width) {
|
|
116
|
-
return new ImageTransformer(this.buffer).resize(width);
|
|
117
|
-
}
|
|
118
|
-
jpeg(options) {
|
|
119
|
-
return new ImageTransformer(this.buffer).jpeg(options);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
exports.Image = Image;
|
|
123
|
-
const isDarwin = () => {
|
|
124
|
-
return node_os_1.default.platform() === "darwin";
|
|
125
|
-
};
|
|
126
|
-
const isSipsInstalled = () => {
|
|
127
|
-
if (!isDarwin()) {
|
|
128
|
-
return false;
|
|
129
|
-
}
|
|
130
|
-
try {
|
|
131
|
-
(0, child_process_1.execFileSync)("/usr/bin/sips", ["--version"]);
|
|
132
|
-
return true;
|
|
133
|
-
}
|
|
134
|
-
catch (error) {
|
|
135
|
-
return false;
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
exports.isSipsInstalled = isSipsInstalled;
|
|
139
|
-
const isImageMagickInstalled = () => {
|
|
140
|
-
try {
|
|
141
|
-
return (0, child_process_1.execFileSync)("magick", ["--version"])
|
|
142
|
-
.toString()
|
|
143
|
-
.split("\n")
|
|
144
|
-
.filter(line => line.includes("Version: ImageMagick"))
|
|
145
|
-
.length > 0;
|
|
146
|
-
}
|
|
147
|
-
catch (error) {
|
|
148
|
-
return false;
|
|
149
|
-
}
|
|
150
|
-
};
|
|
151
|
-
exports.isImageMagickInstalled = isImageMagickInstalled;
|
|
152
|
-
const isScalingAvailable = () => {
|
|
153
|
-
return (0, exports.isImageMagickInstalled)() || (0, exports.isSipsInstalled)();
|
|
154
|
-
};
|
|
155
|
-
exports.isScalingAvailable = isScalingAvailable;
|