@ggboi360/mobile-dev-mcp 0.1.0 β 0.3.0
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/LICENSE +33 -37
- package/LICENSE-ELASTIC +71 -0
- package/LICENSE-MIT +43 -0
- package/README.md +75 -127
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +711 -2036
- package/dist/index.js.map +1 -1
- package/dist/license.d.ts +11 -96
- package/dist/license.d.ts.map +1 -1
- package/dist/license.js +243 -552
- package/dist/license.js.map +1 -1
- package/dist/types.d.ts +52 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +50 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +72 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +307 -0
- package/dist/utils.js.map +1 -0
- package/package.json +15 -5
- package/dist/license.test.d.ts +0 -2
- package/dist/license.test.d.ts.map +0 -1
- package/dist/license.test.js +0 -198
- package/dist/license.test.js.map +0 -1
- package/dist/tools.test.d.ts +0 -2
- package/dist/tools.test.d.ts.map +0 -1
- package/dist/tools.test.js +0 -337
- package/dist/tools.test.js.map +0 -1
package/dist/license.js
CHANGED
|
@@ -1,606 +1,297 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*
|
|
4
|
-
* Tiers:
|
|
5
|
-
* - TRIAL: No license, 50 tool requests then blocked
|
|
6
|
-
* - BASIC ($6/mo): 17 core tools (Android + iOS basics), 50 line limits, 1 device
|
|
7
|
-
* - ADVANCED ($8/wk, $12/mo, $99/yr): All 41 tools, unlimited, multi-device
|
|
8
|
-
*
|
|
9
|
-
* Handles:
|
|
10
|
-
* - License key validation against API
|
|
11
|
-
* - Local caching of license status
|
|
12
|
-
* - Trial usage tracking
|
|
13
|
-
* - Graceful degradation when offline
|
|
14
|
-
* - Feature gating based on tier
|
|
15
|
-
*/
|
|
1
|
+
// Mobile Dev MCP - License Management
|
|
2
|
+
// Read-only debugging tool - simplified 2-tier system
|
|
16
3
|
import * as fs from "fs";
|
|
17
4
|
import * as path from "path";
|
|
18
5
|
import * as os from "os";
|
|
6
|
+
import * as https from "https";
|
|
19
7
|
import * as crypto from "crypto";
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
//
|
|
23
|
-
|
|
24
|
-
const
|
|
8
|
+
import { execSync } from "child_process";
|
|
9
|
+
import { TIER_LIMITS, FREE_TOOLS, ADVANCED_TOOLS } from "./types.js";
|
|
10
|
+
// Re-export for tests
|
|
11
|
+
export { TIER_LIMITS, FREE_TOOLS, ADVANCED_TOOLS };
|
|
12
|
+
const CONFIG_DIR = path.join(os.homedir(), ".mobile-dev-mcp");
|
|
25
13
|
const LICENSE_CACHE_FILE = path.join(CONFIG_DIR, "license.json");
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const GRACE_PERIOD_MS = 7 * 24 * 60 * 60 * 1000; // 7 days
|
|
31
|
-
// Default API endpoint - UPDATE THIS after deploying your Cloudflare Worker!
|
|
32
|
-
const DEFAULT_API_ENDPOINT = "https://mobiledev-license-api.giladworkersdev.workers.dev";
|
|
33
|
-
// Trial settings
|
|
34
|
-
const TRIAL_LIMIT = 50; // Number of tool requests allowed in trial
|
|
35
|
-
// ============================================================================
|
|
36
|
-
// FEATURE TIERS
|
|
14
|
+
// License validation API (Cloudflare Worker)
|
|
15
|
+
const LICENSE_API_URL = "https://mobiledev-license-api.giladworkersdev.workers.dev/validate";
|
|
16
|
+
// Cache TTL: 1 hour (reduced from 24 hours for faster revocation)
|
|
17
|
+
const CACHE_TTL_MS = 60 * 60 * 1000;
|
|
37
18
|
// ============================================================================
|
|
38
|
-
//
|
|
39
|
-
export const BASIC_TOOLS = [
|
|
40
|
-
// Android tools
|
|
41
|
-
"get_metro_logs",
|
|
42
|
-
"get_adb_logs",
|
|
43
|
-
"screenshot_emulator",
|
|
44
|
-
"list_devices",
|
|
45
|
-
"check_metro_status",
|
|
46
|
-
"get_app_info",
|
|
47
|
-
"clear_app_data",
|
|
48
|
-
"restart_adb",
|
|
49
|
-
"get_device_info",
|
|
50
|
-
"start_metro_logging",
|
|
51
|
-
"stop_metro_logging",
|
|
52
|
-
// iOS Simulator tools
|
|
53
|
-
"list_ios_simulators",
|
|
54
|
-
"screenshot_ios_simulator",
|
|
55
|
-
"get_ios_simulator_logs",
|
|
56
|
-
"get_ios_simulator_info",
|
|
57
|
-
// License tools
|
|
58
|
-
"get_license_status",
|
|
59
|
-
"set_license_key",
|
|
60
|
-
];
|
|
61
|
-
// ADVANCED TIER ($8/wk, $12/mo, $99/yr) - Pro tools, only for Advanced subscribers
|
|
62
|
-
export const ADVANCED_TOOLS = [
|
|
63
|
-
// Android streaming & monitoring
|
|
64
|
-
"stream_adb_realtime",
|
|
65
|
-
"stop_adb_streaming",
|
|
66
|
-
"screenshot_history",
|
|
67
|
-
"watch_for_errors",
|
|
68
|
-
"multi_device_logs",
|
|
69
|
-
// Android interaction tools
|
|
70
|
-
"tap_screen",
|
|
71
|
-
"input_text",
|
|
72
|
-
"press_button",
|
|
73
|
-
"swipe_screen",
|
|
74
|
-
"launch_app",
|
|
75
|
-
"install_apk",
|
|
76
|
-
// iOS Simulator advanced tools
|
|
77
|
-
"boot_ios_simulator",
|
|
78
|
-
"shutdown_ios_simulator",
|
|
79
|
-
"install_ios_app",
|
|
80
|
-
"launch_ios_app",
|
|
81
|
-
"terminate_ios_app",
|
|
82
|
-
"ios_open_url",
|
|
83
|
-
"ios_push_notification",
|
|
84
|
-
"ios_set_location",
|
|
85
|
-
// React DevTools integration
|
|
86
|
-
"setup_react_devtools",
|
|
87
|
-
"check_devtools_connection",
|
|
88
|
-
"get_react_component_tree",
|
|
89
|
-
"inspect_react_component",
|
|
90
|
-
"search_react_components",
|
|
91
|
-
];
|
|
92
|
-
// Limits for each tier
|
|
93
|
-
export const TIER_LIMITS = {
|
|
94
|
-
trial: {
|
|
95
|
-
maxLogLines: 50, // Same as Basic during trial
|
|
96
|
-
maxDevices: 1,
|
|
97
|
-
screenshotHistory: 0,
|
|
98
|
-
},
|
|
99
|
-
basic: {
|
|
100
|
-
maxLogLines: 50,
|
|
101
|
-
maxDevices: 1,
|
|
102
|
-
screenshotHistory: 0,
|
|
103
|
-
},
|
|
104
|
-
advanced: {
|
|
105
|
-
maxLogLines: Infinity,
|
|
106
|
-
maxDevices: 3,
|
|
107
|
-
screenshotHistory: 20,
|
|
108
|
-
},
|
|
109
|
-
};
|
|
19
|
+
// MACHINE ID
|
|
110
20
|
// ============================================================================
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
fs.mkdirSync(CONFIG_DIR, { recursive: true });
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
export function loadConfig() {
|
|
119
|
-
ensureConfigDir();
|
|
120
|
-
const defaultConfig = {
|
|
121
|
-
metroPort: 8081,
|
|
122
|
-
logBufferSize: 100,
|
|
123
|
-
apiEndpoint: DEFAULT_API_ENDPOINT,
|
|
124
|
-
};
|
|
125
|
-
if (!fs.existsSync(CONFIG_FILE)) {
|
|
126
|
-
saveConfig(defaultConfig);
|
|
127
|
-
return defaultConfig;
|
|
128
|
-
}
|
|
21
|
+
let cachedMachineId = null;
|
|
22
|
+
function getMachineId() {
|
|
23
|
+
if (cachedMachineId)
|
|
24
|
+
return cachedMachineId;
|
|
129
25
|
try {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
26
|
+
if (process.platform === "win32") {
|
|
27
|
+
const output = execSync("wmic csproduct get uuid", { encoding: "utf-8" });
|
|
28
|
+
const lines = output.trim().split("\n");
|
|
29
|
+
if (lines.length > 1) {
|
|
30
|
+
cachedMachineId = lines[1].trim();
|
|
31
|
+
return cachedMachineId;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
else if (process.platform === "linux") {
|
|
35
|
+
if (fs.existsSync("/etc/machine-id")) {
|
|
36
|
+
cachedMachineId = fs.readFileSync("/etc/machine-id", "utf-8").trim();
|
|
37
|
+
return cachedMachineId;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
else if (process.platform === "darwin") {
|
|
41
|
+
const output = execSync("ioreg -rd1 -c IOPlatformExpertDevice | grep IOPlatformUUID", { encoding: "utf-8" });
|
|
42
|
+
const match = output.match(/"([A-F0-9-]+)"/);
|
|
43
|
+
if (match) {
|
|
44
|
+
cachedMachineId = match[1];
|
|
45
|
+
return cachedMachineId;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
133
48
|
}
|
|
134
49
|
catch {
|
|
135
|
-
|
|
50
|
+
// Ignore errors
|
|
136
51
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
ensureConfigDir();
|
|
140
|
-
fs.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2));
|
|
141
|
-
}
|
|
142
|
-
export function setLicenseKey(key) {
|
|
143
|
-
const config = loadConfig();
|
|
144
|
-
config.licenseKey = key;
|
|
145
|
-
saveConfig(config);
|
|
146
|
-
// Clear cached license to force revalidation
|
|
147
|
-
clearLicenseCache();
|
|
52
|
+
cachedMachineId = os.hostname();
|
|
53
|
+
return cachedMachineId;
|
|
148
54
|
}
|
|
149
55
|
// ============================================================================
|
|
150
|
-
//
|
|
56
|
+
// CACHE INTEGRITY (HMAC signing)
|
|
151
57
|
// ============================================================================
|
|
152
|
-
function
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
os.platform(),
|
|
156
|
-
os.arch(),
|
|
157
|
-
os.cpus()[0]?.model || "unknown",
|
|
158
|
-
].join("|");
|
|
159
|
-
return crypto.createHash("sha256").update(info).digest("hex").substring(0, 32);
|
|
58
|
+
function getCacheSecret() {
|
|
59
|
+
// Use machine ID as part of secret to prevent cache file copying between machines
|
|
60
|
+
return `mobiledev-${getMachineId()}-cache-v1`;
|
|
160
61
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
62
|
+
function signCacheData(data) {
|
|
63
|
+
const payload = JSON.stringify(data);
|
|
64
|
+
return crypto.createHmac("sha256", getCacheSecret()).update(payload).digest("hex");
|
|
65
|
+
}
|
|
66
|
+
function verifyCacheSignature(data, signature) {
|
|
67
|
+
const expected = signCacheData(data);
|
|
68
|
+
const sigBuffer = Buffer.from(signature);
|
|
69
|
+
const expBuffer = Buffer.from(expected);
|
|
70
|
+
// Length check before timingSafeEqual to prevent length-based timing leaks
|
|
71
|
+
// (timingSafeEqual throws if lengths differ, which is itself a timing leak)
|
|
72
|
+
if (sigBuffer.length !== expBuffer.length)
|
|
73
|
+
return false;
|
|
74
|
+
return crypto.timingSafeEqual(sigBuffer, expBuffer);
|
|
75
|
+
}
|
|
76
|
+
function loadCachedLicense() {
|
|
168
77
|
try {
|
|
169
|
-
|
|
170
|
-
|
|
78
|
+
if (fs.existsSync(LICENSE_CACHE_FILE)) {
|
|
79
|
+
const raw = JSON.parse(fs.readFileSync(LICENSE_CACHE_FILE, "utf-8"));
|
|
80
|
+
// Verify signature to prevent tampering
|
|
81
|
+
if (raw.data && raw.signature) {
|
|
82
|
+
if (verifyCacheSignature(raw.data, raw.signature)) {
|
|
83
|
+
return raw.data;
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
// Signature mismatch - delete corrupted cache
|
|
87
|
+
console.error("License cache signature mismatch - clearing cache");
|
|
88
|
+
fs.unlinkSync(LICENSE_CACHE_FILE);
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
// Legacy cache without signature - delete it
|
|
93
|
+
fs.unlinkSync(LICENSE_CACHE_FILE);
|
|
94
|
+
}
|
|
171
95
|
}
|
|
172
96
|
catch {
|
|
173
|
-
|
|
97
|
+
// Ignore errors
|
|
174
98
|
}
|
|
99
|
+
return null;
|
|
175
100
|
}
|
|
176
|
-
function saveLicenseCache(
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
101
|
+
function saveLicenseCache(data) {
|
|
102
|
+
try {
|
|
103
|
+
if (!fs.existsSync(CONFIG_DIR)) {
|
|
104
|
+
fs.mkdirSync(CONFIG_DIR, { recursive: true, mode: 0o700 });
|
|
105
|
+
}
|
|
106
|
+
const signature = signCacheData(data);
|
|
107
|
+
const cache = { data, signature };
|
|
108
|
+
// Write with restricted permissions (owner read/write only)
|
|
109
|
+
fs.writeFileSync(LICENSE_CACHE_FILE, JSON.stringify(cache, null, 2), { mode: 0o600 });
|
|
110
|
+
}
|
|
111
|
+
catch {
|
|
112
|
+
// Ignore write errors
|
|
183
113
|
}
|
|
184
|
-
}
|
|
185
|
-
function isCacheFresh(license) {
|
|
186
|
-
const validatedAt = new Date(license.validatedAt).getTime();
|
|
187
|
-
const now = Date.now();
|
|
188
|
-
return now - validatedAt < CACHE_TTL_MS;
|
|
189
|
-
}
|
|
190
|
-
function isWithinGracePeriod(license) {
|
|
191
|
-
const validatedAt = new Date(license.validatedAt).getTime();
|
|
192
|
-
const now = Date.now();
|
|
193
|
-
return now - validatedAt < GRACE_PERIOD_MS;
|
|
194
114
|
}
|
|
195
115
|
// ============================================================================
|
|
196
|
-
//
|
|
116
|
+
// LICENSE VALIDATION
|
|
197
117
|
// ============================================================================
|
|
198
|
-
function
|
|
199
|
-
if (!fs.existsSync(TRIAL_FILE)) {
|
|
200
|
-
return null;
|
|
201
|
-
}
|
|
118
|
+
export async function checkLicense() {
|
|
202
119
|
try {
|
|
203
|
-
const
|
|
204
|
-
|
|
120
|
+
const cached = loadCachedLicense();
|
|
121
|
+
if (cached && cached.licenseKey) {
|
|
122
|
+
const now = Date.now();
|
|
123
|
+
const lastCheck = cached.lastValidated || 0;
|
|
124
|
+
// Check if cache is still valid (1 hour TTL)
|
|
125
|
+
if (now - lastCheck < CACHE_TTL_MS) {
|
|
126
|
+
return {
|
|
127
|
+
tier: cached.tier,
|
|
128
|
+
valid: true,
|
|
129
|
+
licenseKey: cached.licenseKey,
|
|
130
|
+
expiresAt: cached.expiresAt,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
// Re-validate with API
|
|
134
|
+
const validated = await validateWithLemonSqueezy(cached.licenseKey);
|
|
135
|
+
if (validated) {
|
|
136
|
+
return validated;
|
|
137
|
+
}
|
|
138
|
+
// Validation failed - clear cache and fall back to free
|
|
139
|
+
try {
|
|
140
|
+
fs.unlinkSync(LICENSE_CACHE_FILE);
|
|
141
|
+
}
|
|
142
|
+
catch {
|
|
143
|
+
// Ignore
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return { tier: "free", valid: true };
|
|
205
147
|
}
|
|
206
148
|
catch {
|
|
207
|
-
return
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
function saveTrialInfo(trial) {
|
|
211
|
-
ensureConfigDir();
|
|
212
|
-
fs.writeFileSync(TRIAL_FILE, JSON.stringify(trial, null, 2));
|
|
213
|
-
}
|
|
214
|
-
function getMachineIdForTrial() {
|
|
215
|
-
const info = [
|
|
216
|
-
os.hostname(),
|
|
217
|
-
os.platform(),
|
|
218
|
-
os.arch(),
|
|
219
|
-
os.cpus()[0]?.model || "unknown",
|
|
220
|
-
].join("|");
|
|
221
|
-
return crypto.createHash("sha256").update(info).digest("hex").substring(0, 32);
|
|
222
|
-
}
|
|
223
|
-
export function getTrialStatus() {
|
|
224
|
-
const trial = loadTrialInfo();
|
|
225
|
-
if (!trial) {
|
|
226
|
-
return { remaining: TRIAL_LIMIT, used: 0, expired: false };
|
|
227
|
-
}
|
|
228
|
-
// Verify machine ID matches (prevent copying trial.json to new machines)
|
|
229
|
-
const currentMachineId = getMachineIdForTrial();
|
|
230
|
-
if (trial.machineId !== currentMachineId) {
|
|
231
|
-
return { remaining: TRIAL_LIMIT, used: 0, expired: false };
|
|
232
|
-
}
|
|
233
|
-
const remaining = Math.max(0, TRIAL_LIMIT - trial.usageCount);
|
|
234
|
-
return {
|
|
235
|
-
remaining,
|
|
236
|
-
used: trial.usageCount,
|
|
237
|
-
expired: remaining === 0,
|
|
238
|
-
};
|
|
239
|
-
}
|
|
240
|
-
export function incrementTrialUsage() {
|
|
241
|
-
const machineId = getMachineIdForTrial();
|
|
242
|
-
let trial = loadTrialInfo();
|
|
243
|
-
// Initialize trial if needed
|
|
244
|
-
if (!trial || trial.machineId !== machineId) {
|
|
245
|
-
trial = {
|
|
246
|
-
usageCount: 0,
|
|
247
|
-
firstUsedAt: new Date().toISOString(),
|
|
248
|
-
lastUsedAt: new Date().toISOString(),
|
|
249
|
-
machineId,
|
|
250
|
-
};
|
|
251
|
-
}
|
|
252
|
-
// Check if trial expired
|
|
253
|
-
if (trial.usageCount >= TRIAL_LIMIT) {
|
|
254
|
-
return {
|
|
255
|
-
allowed: false,
|
|
256
|
-
remaining: 0,
|
|
257
|
-
message: `π Trial expired! You've used all ${TRIAL_LIMIT} trial requests.
|
|
258
|
-
|
|
259
|
-
To continue using Mobile Dev MCP, purchase a license:
|
|
260
|
-
|
|
261
|
-
βββββββββββββββββββββββββββββββββββββββββββ
|
|
262
|
-
β Basic Solo $6/month β
|
|
263
|
-
β β 13 core tools, 50 log lines β
|
|
264
|
-
βββββββββββββββββββββββββββββββββββββββββββ€
|
|
265
|
-
β Advanced Solo $12/month (or $99/year) β
|
|
266
|
-
β β All 18 tools, unlimited logs β
|
|
267
|
-
β β Real-time streaming, multi-device β
|
|
268
|
-
βββββββββββββββββββββββββββββββββββββββββββ
|
|
269
|
-
|
|
270
|
-
Purchase at: https://mobile-dev-mcp.com
|
|
271
|
-
Then use 'set_license_key' to activate.`,
|
|
272
|
-
};
|
|
149
|
+
return { tier: "free", valid: true };
|
|
273
150
|
}
|
|
274
|
-
// Increment usage
|
|
275
|
-
trial.usageCount++;
|
|
276
|
-
trial.lastUsedAt = new Date().toISOString();
|
|
277
|
-
saveTrialInfo(trial);
|
|
278
|
-
const remaining = TRIAL_LIMIT - trial.usageCount;
|
|
279
|
-
return {
|
|
280
|
-
allowed: true,
|
|
281
|
-
remaining,
|
|
282
|
-
};
|
|
283
151
|
}
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
152
|
+
async function validateWithLemonSqueezy(licenseKey) {
|
|
153
|
+
return new Promise((resolve) => {
|
|
154
|
+
const machineId = getMachineId();
|
|
155
|
+
const postData = JSON.stringify({
|
|
156
|
+
license_key: licenseKey,
|
|
157
|
+
instance_id: machineId,
|
|
158
|
+
});
|
|
159
|
+
const url = new URL(LICENSE_API_URL);
|
|
160
|
+
const req = https.request({
|
|
161
|
+
hostname: url.hostname,
|
|
162
|
+
path: url.pathname,
|
|
290
163
|
method: "POST",
|
|
291
164
|
headers: {
|
|
292
165
|
"Content-Type": "application/json",
|
|
166
|
+
"Content-Length": postData.length,
|
|
293
167
|
},
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
168
|
+
}, (res) => {
|
|
169
|
+
let data = "";
|
|
170
|
+
const MAX_RESPONSE_SIZE = 1024 * 1024; // 1MB limit to prevent DoS
|
|
171
|
+
res.on("data", (chunk) => {
|
|
172
|
+
data += chunk;
|
|
173
|
+
// Abort if response is too large (potential DoS)
|
|
174
|
+
if (data.length > MAX_RESPONSE_SIZE) {
|
|
175
|
+
req.destroy();
|
|
176
|
+
resolve(null);
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
res.on("end", () => {
|
|
180
|
+
try {
|
|
181
|
+
const response = JSON.parse(data);
|
|
182
|
+
if (response.valid) {
|
|
183
|
+
const tier = mapProductToTier(response.meta?.product_name || "");
|
|
184
|
+
const info = {
|
|
185
|
+
tier,
|
|
186
|
+
valid: true,
|
|
187
|
+
licenseKey,
|
|
188
|
+
expiresAt: response.license_key?.expires_at,
|
|
189
|
+
};
|
|
190
|
+
saveLicenseCache({
|
|
191
|
+
tier,
|
|
192
|
+
licenseKey,
|
|
193
|
+
expiresAt: response.license_key?.expires_at,
|
|
194
|
+
lastValidated: Date.now(),
|
|
195
|
+
});
|
|
196
|
+
resolve(info);
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
resolve(null);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
catch {
|
|
203
|
+
resolve(null);
|
|
204
|
+
}
|
|
205
|
+
});
|
|
298
206
|
});
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
// Check variant name for tier hints
|
|
308
|
-
const variantName = data.meta?.variant_name?.toLowerCase() || "";
|
|
309
|
-
const productName = data.meta?.product_name?.toLowerCase() || "";
|
|
310
|
-
if (variantName.includes("advanced") ||
|
|
311
|
-
productName.includes("advanced")) {
|
|
312
|
-
tier = "advanced";
|
|
313
|
-
}
|
|
314
|
-
else if (variantName.includes("basic") ||
|
|
315
|
-
productName.includes("basic")) {
|
|
316
|
-
tier = "basic";
|
|
317
|
-
}
|
|
318
|
-
return {
|
|
319
|
-
key: licenseKey,
|
|
320
|
-
valid: true,
|
|
321
|
-
tier,
|
|
322
|
-
email: data.meta?.customer_email,
|
|
323
|
-
validatedAt: new Date().toISOString(),
|
|
324
|
-
expiresAt: data.license_key?.expires_at || undefined,
|
|
325
|
-
};
|
|
326
|
-
}
|
|
327
|
-
return {
|
|
328
|
-
key: licenseKey,
|
|
329
|
-
valid: false,
|
|
330
|
-
tier: "trial",
|
|
331
|
-
validatedAt: new Date().toISOString(),
|
|
332
|
-
};
|
|
333
|
-
}
|
|
334
|
-
catch (error) {
|
|
335
|
-
console.error("License validation API error:", error);
|
|
336
|
-
return null;
|
|
337
|
-
}
|
|
207
|
+
req.on("error", () => resolve(null));
|
|
208
|
+
req.setTimeout(5000, () => {
|
|
209
|
+
req.destroy();
|
|
210
|
+
resolve(null);
|
|
211
|
+
});
|
|
212
|
+
req.write(postData);
|
|
213
|
+
req.end();
|
|
214
|
+
});
|
|
338
215
|
}
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
//
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
// Return cached result if we've already checked this session
|
|
345
|
-
if (cachedLicenseResult) {
|
|
346
|
-
return cachedLicenseResult;
|
|
347
|
-
}
|
|
348
|
-
const config = loadConfig();
|
|
349
|
-
// No license key configured - trial mode
|
|
350
|
-
if (!config.licenseKey) {
|
|
351
|
-
cachedLicenseResult = {
|
|
352
|
-
key: "",
|
|
353
|
-
valid: false,
|
|
354
|
-
tier: "trial",
|
|
355
|
-
validatedAt: new Date().toISOString(),
|
|
356
|
-
};
|
|
357
|
-
return cachedLicenseResult;
|
|
358
|
-
}
|
|
359
|
-
// Check local cache first
|
|
360
|
-
const cached = loadLicenseCache();
|
|
361
|
-
if (cached && cached.key === config.licenseKey) {
|
|
362
|
-
if (cached.valid && isCacheFresh(cached)) {
|
|
363
|
-
cachedLicenseResult = cached;
|
|
364
|
-
return cached;
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
// Try to validate with API
|
|
368
|
-
const apiResult = await validateWithApi(config.licenseKey, config.apiEndpoint);
|
|
369
|
-
if (apiResult) {
|
|
370
|
-
saveLicenseCache(apiResult);
|
|
371
|
-
cachedLicenseResult = apiResult;
|
|
372
|
-
return apiResult;
|
|
216
|
+
function mapProductToTier(productName) {
|
|
217
|
+
const name = productName.toLowerCase();
|
|
218
|
+
// Any paid product maps to advanced tier
|
|
219
|
+
if (name.includes("advanced") || name.includes("pro") || name.includes("basic")) {
|
|
220
|
+
return "advanced";
|
|
373
221
|
}
|
|
374
|
-
|
|
375
|
-
if (cached && cached.valid && isWithinGracePeriod(cached)) {
|
|
376
|
-
console.error("License API unreachable, using cached license (grace period)");
|
|
377
|
-
cachedLicenseResult = cached;
|
|
378
|
-
return cached;
|
|
379
|
-
}
|
|
380
|
-
// No valid cache, API down - fall back to trial
|
|
381
|
-
cachedLicenseResult = {
|
|
382
|
-
key: config.licenseKey,
|
|
383
|
-
valid: false,
|
|
384
|
-
tier: "trial",
|
|
385
|
-
validatedAt: new Date().toISOString(),
|
|
386
|
-
};
|
|
387
|
-
return cachedLicenseResult;
|
|
222
|
+
return "free";
|
|
388
223
|
}
|
|
389
224
|
// ============================================================================
|
|
390
|
-
//
|
|
225
|
+
// TOOL ACCESS CONTROL
|
|
391
226
|
// ============================================================================
|
|
392
|
-
export function
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
if (isAdvancedTool(toolName)) {
|
|
402
|
-
return license.valid && license.tier === "advanced";
|
|
403
|
-
}
|
|
404
|
-
// Basic tools require Basic or Advanced tier
|
|
405
|
-
if (isBasicTool(toolName)) {
|
|
406
|
-
return license.valid && (license.tier === "basic" || license.tier === "advanced");
|
|
407
|
-
}
|
|
408
|
-
// Unknown tool - allow (might be a new tool)
|
|
409
|
-
return true;
|
|
410
|
-
}
|
|
411
|
-
export async function requireAdvanced(toolName) {
|
|
412
|
-
const license = await checkLicense();
|
|
413
|
-
// Advanced license holders always allowed
|
|
414
|
-
if (license.valid && license.tier === "advanced") {
|
|
415
|
-
return { allowed: true };
|
|
416
|
-
}
|
|
417
|
-
// Trial users can try Advanced tools (uses trial quota)
|
|
418
|
-
if (!license.valid || license.tier === "trial") {
|
|
419
|
-
const trialResult = incrementTrialUsage();
|
|
420
|
-
if (!trialResult.allowed) {
|
|
421
|
-
return {
|
|
422
|
-
allowed: false,
|
|
423
|
-
message: trialResult.message,
|
|
424
|
-
};
|
|
425
|
-
}
|
|
426
|
-
// Trial still has requests - allow with reminder
|
|
427
|
-
if (trialResult.remaining <= 10) {
|
|
428
|
-
return {
|
|
429
|
-
allowed: true,
|
|
430
|
-
message: `β οΈ Trial: ${trialResult.remaining} requests remaining. This is an Advanced feature - upgrade to keep using it!`,
|
|
431
|
-
};
|
|
227
|
+
export function canAccessTool(toolName, tier) {
|
|
228
|
+
// Free tools are always accessible
|
|
229
|
+
if (FREE_TOOLS.includes(toolName)) {
|
|
230
|
+
return true;
|
|
231
|
+
}
|
|
232
|
+
// Advanced tools require advanced tier
|
|
233
|
+
if (tier === "advanced") {
|
|
234
|
+
if (ADVANCED_TOOLS.includes(toolName)) {
|
|
235
|
+
return true;
|
|
432
236
|
}
|
|
433
|
-
return { allowed: true };
|
|
434
237
|
}
|
|
435
|
-
|
|
436
|
-
return {
|
|
437
|
-
allowed: false,
|
|
438
|
-
message: `π "${toolName}" requires Advanced tier.
|
|
439
|
-
|
|
440
|
-
Your current tier: BASIC
|
|
441
|
-
|
|
442
|
-
Upgrade to Advanced for:
|
|
443
|
-
- Real-time log streaming
|
|
444
|
-
- Screenshot history
|
|
445
|
-
- Multi-device support (3 devices)
|
|
446
|
-
- Error watching
|
|
447
|
-
- Unlimited log lines
|
|
448
|
-
- Device interaction (tap, type, swipe)
|
|
449
|
-
|
|
450
|
-
Pricing: $8/week, $12/month, or $99/year
|
|
451
|
-
|
|
452
|
-
Upgrade at: https://mobile-dev-mcp.com`,
|
|
453
|
-
};
|
|
238
|
+
return false;
|
|
454
239
|
}
|
|
455
|
-
export
|
|
456
|
-
|
|
457
|
-
// Licensed users can always use basic tools
|
|
458
|
-
if (license.valid) {
|
|
459
|
-
return { allowed: true };
|
|
460
|
-
}
|
|
461
|
-
// Trial users - check trial status
|
|
462
|
-
const trialResult = incrementTrialUsage();
|
|
463
|
-
if (!trialResult.allowed) {
|
|
464
|
-
return {
|
|
465
|
-
allowed: false,
|
|
466
|
-
message: trialResult.message,
|
|
467
|
-
};
|
|
468
|
-
}
|
|
469
|
-
// Trial still has requests - allow with reminder
|
|
470
|
-
if (trialResult.remaining <= 10) {
|
|
471
|
-
return {
|
|
472
|
-
allowed: true,
|
|
473
|
-
message: `β οΈ Trial: ${trialResult.remaining} requests remaining. Purchase a license to continue uninterrupted.`,
|
|
474
|
-
};
|
|
475
|
-
}
|
|
476
|
-
return { allowed: true };
|
|
240
|
+
export function isFreeTool(toolName) {
|
|
241
|
+
return FREE_TOOLS.includes(toolName);
|
|
477
242
|
}
|
|
478
|
-
export function
|
|
479
|
-
return
|
|
243
|
+
export function isAdvancedOnlyTool(toolName) {
|
|
244
|
+
return ADVANCED_TOOLS.includes(toolName) && !FREE_TOOLS.includes(toolName);
|
|
480
245
|
}
|
|
481
|
-
export
|
|
482
|
-
|
|
483
|
-
|
|
246
|
+
export function getMaxLogLines(tier) {
|
|
247
|
+
return TIER_LIMITS[tier]?.maxLogLines || 50;
|
|
248
|
+
}
|
|
249
|
+
export function getMaxDevices(tier) {
|
|
250
|
+
return TIER_LIMITS[tier]?.maxDevices || 1;
|
|
484
251
|
}
|
|
485
252
|
// ============================================================================
|
|
486
|
-
// LICENSE
|
|
253
|
+
// LICENSE TOOLS (exposed via MCP)
|
|
487
254
|
// ============================================================================
|
|
488
255
|
export async function getLicenseStatus() {
|
|
489
256
|
const license = await checkLicense();
|
|
490
|
-
const config = loadConfig();
|
|
491
|
-
if (!config.licenseKey) {
|
|
492
|
-
const trialStatus = getTrialStatus();
|
|
493
|
-
if (trialStatus.expired) {
|
|
494
|
-
return `π License Status: TRIAL EXPIRED
|
|
495
|
-
|
|
496
|
-
You've used all ${TRIAL_LIMIT} trial requests.
|
|
497
|
-
|
|
498
|
-
βββββββββββββββββββββββββββββββββββββββββββ
|
|
499
|
-
β Basic Solo $6/mo β Core tools β
|
|
500
|
-
β Advanced Solo $12/mo β All featuresβ
|
|
501
|
-
β $8/wk or $99/yr β
|
|
502
|
-
βββββββββββββββββββββββββββββββββββββββββββ
|
|
503
|
-
|
|
504
|
-
Purchase at: https://mobile-dev-mcp.com
|
|
505
|
-
Then use 'set_license_key' to activate.`;
|
|
506
|
-
}
|
|
507
|
-
return `π License Status: TRIAL
|
|
508
|
-
|
|
509
|
-
Trial requests remaining: ${trialStatus.remaining}/${TRIAL_LIMIT}
|
|
510
|
-
Trial requests used: ${trialStatus.used}
|
|
511
|
-
|
|
512
|
-
βββββββββββββββββββββββββββββββββββββββββββ
|
|
513
|
-
β Basic Solo $6/mo β Core tools β
|
|
514
|
-
β Advanced Solo $12/mo β All featuresβ
|
|
515
|
-
β $8/wk or $99/yr β
|
|
516
|
-
βββββββββββββββββββββββββββββββββββββββββββ
|
|
517
|
-
|
|
518
|
-
Purchase at: https://mobile-dev-mcp.com
|
|
519
|
-
Then use 'set_license_key' to activate.`;
|
|
520
|
-
}
|
|
521
|
-
if (!license.valid) {
|
|
522
|
-
return `π License Status: INVALID
|
|
523
|
-
|
|
524
|
-
License key: ${maskLicenseKey(config.licenseKey)}
|
|
525
|
-
Status: Invalid or expired
|
|
526
|
-
|
|
527
|
-
Please check your license key or purchase a new one.
|
|
528
|
-
https://mobile-dev-mcp.com`;
|
|
529
|
-
}
|
|
530
|
-
const tierEmoji = license.tier === "advanced" ? "β" : "β";
|
|
531
257
|
const limits = TIER_LIMITS[license.tier];
|
|
532
|
-
return
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
- Max log lines: ${limits.maxLogLines === Infinity ? "Unlimited" : limits.maxLogLines}
|
|
541
|
-
- Max devices: ${limits.maxDevices}
|
|
542
|
-
- Screenshot history: ${limits.screenshotHistory || "Not available"}
|
|
543
|
-
|
|
544
|
-
${license.tier === "basic" ? "\nπ‘ Upgrade to Advanced for real-time streaming & multi-device support!" : "All features unlocked! π"}`;
|
|
545
|
-
}
|
|
546
|
-
function maskLicenseKey(key) {
|
|
547
|
-
if (key.length < 8)
|
|
548
|
-
return "****";
|
|
549
|
-
return key.substring(0, 4) + "****" + key.substring(key.length - 4);
|
|
550
|
-
}
|
|
551
|
-
export const licenseTools = [
|
|
552
|
-
{
|
|
553
|
-
name: "get_license_status",
|
|
554
|
-
description: "Check your current license status and tier (free/basic/advanced)",
|
|
555
|
-
inputSchema: {
|
|
556
|
-
type: "object",
|
|
557
|
-
properties: {},
|
|
558
|
-
},
|
|
559
|
-
},
|
|
560
|
-
{
|
|
561
|
-
name: "set_license_key",
|
|
562
|
-
description: "Set or update your license key to unlock paid features",
|
|
563
|
-
inputSchema: {
|
|
564
|
-
type: "object",
|
|
565
|
-
properties: {
|
|
566
|
-
licenseKey: {
|
|
567
|
-
type: "string",
|
|
568
|
-
description: "Your license key from mobile-dev-mcp.com",
|
|
569
|
-
},
|
|
570
|
-
},
|
|
571
|
-
required: ["licenseKey"],
|
|
258
|
+
return JSON.stringify({
|
|
259
|
+
tier: license.tier.toUpperCase(),
|
|
260
|
+
valid: license.valid,
|
|
261
|
+
expiresAt: license.expiresAt || "N/A",
|
|
262
|
+
features: {
|
|
263
|
+
maxLogLines: limits?.maxLogLines || 50,
|
|
264
|
+
maxDevices: limits?.maxDevices || 1,
|
|
265
|
+
tools: license.tier === "advanced" ? 21 : 8,
|
|
572
266
|
},
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
}
|
|
596
|
-
|
|
597
|
-
return `β License key is invalid or expired.
|
|
598
|
-
|
|
599
|
-
Please check your key or contact support.
|
|
600
|
-
https://mobile-dev-mcp.com`;
|
|
601
|
-
}
|
|
602
|
-
default:
|
|
603
|
-
return `Unknown license tool: ${name}`;
|
|
267
|
+
upgrade: license.tier === "free" ? {
|
|
268
|
+
url: "https://mobiledevmcp.dev/pricing",
|
|
269
|
+
price: "$18/month",
|
|
270
|
+
features: ["UI inspection", "Screen analysis", "Multi-device support"],
|
|
271
|
+
} : null,
|
|
272
|
+
}, null, 2);
|
|
273
|
+
}
|
|
274
|
+
export async function setLicenseKey(licenseKey) {
|
|
275
|
+
if (!licenseKey || licenseKey.trim() === "") {
|
|
276
|
+
return JSON.stringify({ success: false, error: "License key is required" });
|
|
277
|
+
}
|
|
278
|
+
// Basic format validation
|
|
279
|
+
const key = licenseKey.trim();
|
|
280
|
+
if (key.length < 10 || key.length > 100) {
|
|
281
|
+
return JSON.stringify({ success: false, error: "Invalid license key format" });
|
|
282
|
+
}
|
|
283
|
+
const validated = await validateWithLemonSqueezy(key);
|
|
284
|
+
if (validated) {
|
|
285
|
+
return JSON.stringify({
|
|
286
|
+
success: true,
|
|
287
|
+
tier: validated.tier.toUpperCase(),
|
|
288
|
+
expiresAt: validated.expiresAt || "N/A",
|
|
289
|
+
message: `License activated! You now have ${validated.tier.toUpperCase()} tier access with all 21 tools.`,
|
|
290
|
+
});
|
|
604
291
|
}
|
|
292
|
+
return JSON.stringify({
|
|
293
|
+
success: false,
|
|
294
|
+
error: "Invalid license key. Please check your key and try again.",
|
|
295
|
+
});
|
|
605
296
|
}
|
|
606
297
|
//# sourceMappingURL=license.js.map
|