@midscene/shared 1.9.8-beta-20260618014851.0 → 1.9.8
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/dist/es/cli/cli-runner.mjs +1 -1
- package/dist/es/env/parse-model-config.mjs +1 -1
- package/dist/es/env/types.mjs +5 -3
- package/dist/es/mcp/base-server.mjs +295 -0
- package/dist/es/{agent-tools → mcp}/base-tools.mjs +8 -1
- package/dist/es/{agent-tools → mcp}/chrome-path.mjs +3 -14
- package/dist/es/{agent-tools → mcp}/index.mjs +3 -0
- package/dist/es/mcp/inject-report-html-plugin.mjs +53 -0
- package/dist/es/mcp/launcher-helper.mjs +52 -0
- package/dist/es/{agent-tools → mcp}/tool-generator.mjs +3 -3
- package/dist/es/utils.mjs +6 -2
- package/dist/lib/cli/cli-runner.js +1 -1
- package/dist/lib/env/parse-model-config.js +1 -1
- package/dist/lib/env/types.js +10 -5
- package/dist/lib/mcp/base-server.js +345 -0
- package/dist/lib/{agent-tools → mcp}/base-tools.js +8 -1
- package/dist/lib/{agent-tools → mcp}/chrome-path.js +2 -13
- package/dist/lib/{agent-tools → mcp}/index.js +37 -16
- package/dist/lib/mcp/inject-report-html-plugin.js +98 -0
- package/dist/lib/mcp/launcher-helper.js +86 -0
- package/dist/lib/{agent-tools → mcp}/tool-generator.js +3 -3
- package/dist/lib/utils.js +15 -8
- package/dist/types/cli/cli-args.d.ts +1 -1
- package/dist/types/cli/cli-runner.d.ts +2 -2
- package/dist/types/env/types.d.ts +6 -8
- package/dist/types/key-alias-utils.d.ts +2 -2
- package/dist/types/mcp/base-server.d.ts +106 -0
- package/dist/types/{agent-tools → mcp}/base-tools.d.ts +13 -7
- package/dist/types/{agent-tools → mcp}/index.d.ts +3 -0
- package/dist/types/{agent-tools → mcp}/init-arg-utils.d.ts +3 -3
- package/dist/types/mcp/inject-report-html-plugin.d.ts +18 -0
- package/dist/types/mcp/launcher-helper.d.ts +94 -0
- package/dist/types/{agent-tools → mcp}/tool-defaults.d.ts +6 -5
- package/dist/types/{agent-tools → mcp}/tool-generator.d.ts +1 -1
- package/dist/types/{agent-tools → mcp}/types.d.ts +9 -4
- package/dist/types/utils.d.ts +1 -0
- package/package.json +8 -15
- package/src/cli/cli-args.ts +1 -1
- package/src/cli/cli-runner.ts +4 -4
- package/src/env/types.ts +5 -5
- package/src/key-alias-utils.ts +2 -2
- package/src/mcp/base-server.ts +529 -0
- package/src/{agent-tools → mcp}/base-tools.ts +33 -8
- package/src/{agent-tools → mcp}/chrome-path.ts +3 -20
- package/src/{agent-tools → mcp}/index.ts +3 -0
- package/src/{agent-tools → mcp}/init-arg-utils.ts +3 -3
- package/src/mcp/inject-report-html-plugin.ts +119 -0
- package/src/mcp/launcher-helper.ts +200 -0
- package/src/{agent-tools → mcp}/tool-defaults.ts +6 -5
- package/src/{agent-tools → mcp}/tool-generator.ts +6 -6
- package/src/{agent-tools → mcp}/types.ts +9 -4
- package/src/utils.ts +10 -1
- /package/dist/es/{agent-tools → mcp}/agent-behavior-init-args.mjs +0 -0
- /package/dist/es/{agent-tools → mcp}/cli-report-session.mjs +0 -0
- /package/dist/es/{agent-tools → mcp}/error-formatter.mjs +0 -0
- /package/dist/es/{agent-tools → mcp}/init-arg-utils.mjs +0 -0
- /package/dist/es/{agent-tools → mcp}/tool-defaults.mjs +0 -0
- /package/dist/es/{agent-tools → mcp}/types.mjs +0 -0
- /package/dist/es/{agent-tools → mcp}/user-prompt.mjs +0 -0
- /package/dist/lib/{agent-tools → mcp}/agent-behavior-init-args.js +0 -0
- /package/dist/lib/{agent-tools → mcp}/cli-report-session.js +0 -0
- /package/dist/lib/{agent-tools → mcp}/error-formatter.js +0 -0
- /package/dist/lib/{agent-tools → mcp}/init-arg-utils.js +0 -0
- /package/dist/lib/{agent-tools → mcp}/tool-defaults.js +0 -0
- /package/dist/lib/{agent-tools → mcp}/types.js +0 -0
- /package/dist/lib/{agent-tools → mcp}/user-prompt.js +0 -0
- /package/dist/types/{agent-tools → mcp}/agent-behavior-init-args.d.ts +0 -0
- /package/dist/types/{agent-tools → mcp}/chrome-path.d.ts +0 -0
- /package/dist/types/{agent-tools → mcp}/cli-report-session.d.ts +0 -0
- /package/dist/types/{agent-tools → mcp}/error-formatter.d.ts +0 -0
- /package/dist/types/{agent-tools → mcp}/user-prompt.d.ts +0 -0
- /package/src/{agent-tools → mcp}/agent-behavior-init-args.ts +0 -0
- /package/src/{agent-tools → mcp}/cli-report-session.ts +0 -0
- /package/src/{agent-tools → mcp}/error-formatter.ts +0 -0
- /package/src/{agent-tools → mcp}/user-prompt.ts +0 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.n = (module)=>{
|
|
5
|
+
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
6
|
+
__webpack_require__.d(getter, {
|
|
7
|
+
a: getter
|
|
8
|
+
});
|
|
9
|
+
return getter;
|
|
10
|
+
};
|
|
11
|
+
})();
|
|
12
|
+
(()=>{
|
|
13
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
14
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: definition[key]
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
})();
|
|
20
|
+
(()=>{
|
|
21
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
22
|
+
})();
|
|
23
|
+
(()=>{
|
|
24
|
+
__webpack_require__.r = (exports1)=>{
|
|
25
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
26
|
+
value: 'Module'
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
29
|
+
value: true
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
})();
|
|
33
|
+
var __webpack_exports__ = {};
|
|
34
|
+
__webpack_require__.r(__webpack_exports__);
|
|
35
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
36
|
+
injectReportHtmlFromCore: ()=>injectReportHtmlFromCore
|
|
37
|
+
});
|
|
38
|
+
const external_node_fs_namespaceObject = require("node:fs");
|
|
39
|
+
var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
|
|
40
|
+
const external_node_path_namespaceObject = require("node:path");
|
|
41
|
+
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
|
|
42
|
+
const MAGIC_STRING = 'REPLACE_ME_WITH_REPORT_HTML';
|
|
43
|
+
const REPLACED_MARK = '/*REPORT_HTML_REPLACED*/';
|
|
44
|
+
const REG_EXP_FOR_REPLACE = /\/\*REPORT_HTML_REPLACED\*\/.*/;
|
|
45
|
+
function injectReportHtmlFromCore(packageDir) {
|
|
46
|
+
return {
|
|
47
|
+
name: 'inject-report-html-from-core',
|
|
48
|
+
setup (api) {
|
|
49
|
+
api.onAfterBuild(()=>{
|
|
50
|
+
const coreUtilsPath = external_node_path_default().resolve(packageDir, '..', 'core', 'dist', 'lib', 'utils.js');
|
|
51
|
+
if (!external_node_fs_default().existsSync(coreUtilsPath)) return void console.warn('[inject-report-html] @midscene/core dist not found, skipping');
|
|
52
|
+
const coreContent = external_node_fs_default().readFileSync(coreUtilsPath, 'utf-8');
|
|
53
|
+
if (!coreContent.includes(REPLACED_MARK)) return void console.warn('[inject-report-html] HTML not found in core dist. Ensure report builds first.');
|
|
54
|
+
const markerIndex = coreContent.indexOf(REPLACED_MARK);
|
|
55
|
+
const jsonStart = markerIndex + REPLACED_MARK.length;
|
|
56
|
+
let jsonEnd = jsonStart;
|
|
57
|
+
if ('"' === coreContent[jsonStart]) {
|
|
58
|
+
jsonEnd = jsonStart + 1;
|
|
59
|
+
while(jsonEnd < coreContent.length)if ('\\' === coreContent[jsonEnd]) jsonEnd += 2;
|
|
60
|
+
else if ('"' === coreContent[jsonEnd]) {
|
|
61
|
+
jsonEnd += 1;
|
|
62
|
+
break;
|
|
63
|
+
} else jsonEnd += 1;
|
|
64
|
+
}
|
|
65
|
+
const jsonString = coreContent.slice(jsonStart, jsonEnd);
|
|
66
|
+
if (!jsonString || jsonString.length < 10) return void console.warn('[inject-report-html] Failed to extract HTML from core');
|
|
67
|
+
const finalContent = `${REPLACED_MARK}${jsonString}`;
|
|
68
|
+
const distDir = external_node_path_default().join(packageDir, 'dist');
|
|
69
|
+
if (!external_node_fs_default().existsSync(distDir)) return;
|
|
70
|
+
const jsFiles = external_node_fs_default().readdirSync(distDir).filter((f)=>f.endsWith('.js'));
|
|
71
|
+
let injectedCount = 0;
|
|
72
|
+
for (const file of jsFiles){
|
|
73
|
+
const filePath = external_node_path_default().join(distDir, file);
|
|
74
|
+
const content = external_node_fs_default().readFileSync(filePath, 'utf-8');
|
|
75
|
+
if (content.includes(REPLACED_MARK)) {
|
|
76
|
+
if (REG_EXP_FOR_REPLACE.test(content)) {
|
|
77
|
+
external_node_fs_default().writeFileSync(filePath, content.replace(REG_EXP_FOR_REPLACE, ()=>finalContent));
|
|
78
|
+
console.log(`[inject-report-html] Updated: ${file}`);
|
|
79
|
+
injectedCount++;
|
|
80
|
+
}
|
|
81
|
+
} else if (content.includes(`'${MAGIC_STRING}'`)) {
|
|
82
|
+
external_node_fs_default().writeFileSync(filePath, content.replace(`'${MAGIC_STRING}'`, ()=>finalContent));
|
|
83
|
+
console.log(`[inject-report-html] Injected: ${file}`);
|
|
84
|
+
injectedCount++;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (injectedCount > 0) console.log(`[inject-report-html] Completed: ${injectedCount} file(s)`);
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
exports.injectReportHtmlFromCore = __webpack_exports__.injectReportHtmlFromCore;
|
|
93
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
94
|
+
"injectReportHtmlFromCore"
|
|
95
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
96
|
+
Object.defineProperty(exports, '__esModule', {
|
|
97
|
+
value: true
|
|
98
|
+
});
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
createMCPServerLauncher: ()=>createMCPServerLauncher
|
|
28
|
+
});
|
|
29
|
+
function createMCPServerLauncher(config) {
|
|
30
|
+
const { agent, platformName, ToolsManagerClass, MCPServerClass } = config;
|
|
31
|
+
function validateAgent() {
|
|
32
|
+
const device = agent.interface;
|
|
33
|
+
if (!device) throw new Error(`Agent must have an 'interface' property that references the underlying device.
|
|
34
|
+
Please ensure your agent instance is properly initialized with a device interface.
|
|
35
|
+
Expected: agent.interface to be defined, but got: ${typeof device}
|
|
36
|
+
Solution: Check that your agent constructor properly sets the interface property.`);
|
|
37
|
+
}
|
|
38
|
+
function createToolsManager() {
|
|
39
|
+
const toolsManager = new ToolsManagerClass();
|
|
40
|
+
toolsManager.agent = agent;
|
|
41
|
+
return toolsManager;
|
|
42
|
+
}
|
|
43
|
+
function logStartupInfo(mode, additionalInfo) {
|
|
44
|
+
const device = agent.interface;
|
|
45
|
+
console.log(`Starting Midscene ${platformName} MCP Server (${mode})...`);
|
|
46
|
+
console.log(`Agent: ${agent.constructor.name}`);
|
|
47
|
+
console.log(`Device: ${device.constructor.name}`);
|
|
48
|
+
if (additionalInfo?.port !== void 0) console.log(`Port: ${additionalInfo.port}`);
|
|
49
|
+
if (additionalInfo?.host) console.log(`Host: ${additionalInfo.host}`);
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
async launch (options = {}) {
|
|
53
|
+
const { verbose = true } = options;
|
|
54
|
+
validateAgent();
|
|
55
|
+
if (verbose) logStartupInfo('stdio');
|
|
56
|
+
const toolsManager = createToolsManager();
|
|
57
|
+
const server = new MCPServerClass(toolsManager);
|
|
58
|
+
const result = await server.launch();
|
|
59
|
+
if (verbose) console.log(`${platformName} MCP Server started (stdio mode)`);
|
|
60
|
+
return result;
|
|
61
|
+
},
|
|
62
|
+
async launchHttp (options) {
|
|
63
|
+
const { port, host = 'localhost', verbose = true } = options;
|
|
64
|
+
validateAgent();
|
|
65
|
+
if (verbose) logStartupInfo('HTTP', {
|
|
66
|
+
port,
|
|
67
|
+
host
|
|
68
|
+
});
|
|
69
|
+
const toolsManager = createToolsManager();
|
|
70
|
+
const server = new MCPServerClass(toolsManager);
|
|
71
|
+
const result = await server.launchHttp({
|
|
72
|
+
port,
|
|
73
|
+
host
|
|
74
|
+
});
|
|
75
|
+
if (verbose) console.log(`${platformName} MCP Server started on http://${result.host}:${result.port}/mcp`);
|
|
76
|
+
return result;
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
exports.createMCPServerLauncher = __webpack_exports__.createMCPServerLauncher;
|
|
81
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
82
|
+
"createMCPServerLauncher"
|
|
83
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
84
|
+
Object.defineProperty(exports, '__esModule', {
|
|
85
|
+
value: true
|
|
86
|
+
});
|
|
@@ -33,7 +33,7 @@ const external_zod_namespaceObject = require("zod");
|
|
|
33
33
|
const external_zod_schema_utils_js_namespaceObject = require("../zod-schema-utils.js");
|
|
34
34
|
const external_error_formatter_js_namespaceObject = require("./error-formatter.js");
|
|
35
35
|
const external_user_prompt_js_namespaceObject = require("./user-prompt.js");
|
|
36
|
-
function
|
|
36
|
+
function describeActionForMCP(action) {
|
|
37
37
|
const actionDesc = action.description || `Execute ${action.name} action`;
|
|
38
38
|
if (!action.paramSchema) return `${action.name} action, ${actionDesc}`;
|
|
39
39
|
const shape = getZodObjectShape(action.paramSchema);
|
|
@@ -105,7 +105,7 @@ function extractActionSchema(paramSchema, actionName) {
|
|
|
105
105
|
const shape = getZodObjectShape(paramSchema);
|
|
106
106
|
if (!shape) {
|
|
107
107
|
const typeName = paramSchema?._def?.typeName ?? 'unknown';
|
|
108
|
-
throw new Error(`Action "${actionName}" declared a non-object paramSchema (${typeName}). CLI tool schemas must be a ZodObject (e.g. z.object({ uri: z.string() })) or undefined. Wrap primitive fields in an object schema.`);
|
|
108
|
+
throw new Error(`Action "${actionName}" declared a non-object paramSchema (${typeName}). CLI and MCP tool schemas must be a ZodObject (e.g. z.object({ uri: z.string() })) or undefined. Wrap primitive fields in an object schema.`);
|
|
109
109
|
}
|
|
110
110
|
return Object.fromEntries(Object.entries(shape).map(([key, value])=>transformSchemaField(key, value)));
|
|
111
111
|
}
|
|
@@ -357,7 +357,7 @@ function generateToolsFromActionSpace(actionSpace, getAgent, sanitizeArgs = (arg
|
|
|
357
357
|
};
|
|
358
358
|
return {
|
|
359
359
|
name: action.name,
|
|
360
|
-
description:
|
|
360
|
+
description: describeActionForMCP(action),
|
|
361
361
|
schema,
|
|
362
362
|
cli: initArgCliMetadata,
|
|
363
363
|
handler: async (args)=>{
|
package/dist/lib/utils.js
CHANGED
|
@@ -24,19 +24,20 @@ var __webpack_require__ = {};
|
|
|
24
24
|
var __webpack_exports__ = {};
|
|
25
25
|
__webpack_require__.r(__webpack_exports__);
|
|
26
26
|
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
uuid: ()=>uuid,
|
|
28
|
+
isPlainObject: ()=>isPlainObject,
|
|
29
|
+
ifInBrowser: ()=>ifInBrowser,
|
|
30
|
+
repeat: ()=>repeat,
|
|
31
|
+
mergeAndNormalizeAppNameMapping: ()=>mergeAndNormalizeAppNameMapping,
|
|
32
|
+
ifInNode: ()=>ifInNode,
|
|
33
|
+
assert: ()=>assert,
|
|
27
34
|
escapeScriptTag: ()=>escapeScriptTag,
|
|
28
35
|
logMsg: ()=>logMsg,
|
|
29
|
-
isPlainObject: ()=>isPlainObject,
|
|
30
36
|
replaceIllegalPathCharsAndSpace: ()=>replaceIllegalPathCharsAndSpace,
|
|
31
|
-
uuid: ()=>uuid,
|
|
32
|
-
ifInBrowser: ()=>ifInBrowser,
|
|
33
37
|
generateHashId: ()=>generateHashId,
|
|
34
38
|
normalizeForComparison: ()=>normalizeForComparison,
|
|
35
|
-
mergeAndNormalizeAppNameMapping: ()=>mergeAndNormalizeAppNameMapping,
|
|
36
|
-
ifInNode: ()=>ifInNode,
|
|
37
39
|
ifInWorker: ()=>ifInWorker,
|
|
38
|
-
|
|
39
|
-
assert: ()=>assert,
|
|
40
|
+
setIsMcp: ()=>setIsMcp,
|
|
40
41
|
antiEscapeScriptTag: ()=>antiEscapeScriptTag
|
|
41
42
|
});
|
|
42
43
|
const external_js_sha256_namespaceObject = require("js-sha256");
|
|
@@ -75,8 +76,12 @@ function generateHashId(rect, content = '') {
|
|
|
75
76
|
function assert(condition, message) {
|
|
76
77
|
if (!condition) throw new Error(message || 'Assertion failed');
|
|
77
78
|
}
|
|
79
|
+
let isMcp = false;
|
|
80
|
+
function setIsMcp(value) {
|
|
81
|
+
isMcp = value;
|
|
82
|
+
}
|
|
78
83
|
function logMsg(...message) {
|
|
79
|
-
console.log(...message);
|
|
84
|
+
if (!isMcp) console.log(...message);
|
|
80
85
|
}
|
|
81
86
|
async function repeat(times, fn) {
|
|
82
87
|
for(let i = 0; i < times; i++)await fn(i);
|
|
@@ -119,6 +124,7 @@ exports.mergeAndNormalizeAppNameMapping = __webpack_exports__.mergeAndNormalizeA
|
|
|
119
124
|
exports.normalizeForComparison = __webpack_exports__.normalizeForComparison;
|
|
120
125
|
exports.repeat = __webpack_exports__.repeat;
|
|
121
126
|
exports.replaceIllegalPathCharsAndSpace = __webpack_exports__.replaceIllegalPathCharsAndSpace;
|
|
127
|
+
exports.setIsMcp = __webpack_exports__.setIsMcp;
|
|
122
128
|
exports.uuid = __webpack_exports__.uuid;
|
|
123
129
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
124
130
|
"antiEscapeScriptTag",
|
|
@@ -134,6 +140,7 @@ for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
|
134
140
|
"normalizeForComparison",
|
|
135
141
|
"repeat",
|
|
136
142
|
"replaceIllegalPathCharsAndSpace",
|
|
143
|
+
"setIsMcp",
|
|
137
144
|
"uuid"
|
|
138
145
|
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
139
146
|
Object.defineProperty(exports, '__esModule', {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ToolCliOption, ToolDefinition } from '../
|
|
1
|
+
import type { ToolCliOption, ToolDefinition } from '../mcp/types';
|
|
2
2
|
export declare function parseValue(raw: string): unknown;
|
|
3
3
|
export declare function parseCliArgs(args: string[]): Record<string, unknown>;
|
|
4
4
|
export declare function getCliOptionDisplay(key: string, cliOption?: ToolCliOption): {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { BaseMidsceneTools } from '../
|
|
2
|
-
import type { ToolDefinition } from '../
|
|
1
|
+
import type { BaseMidsceneTools } from '../mcp/base-tools';
|
|
2
|
+
import type { ToolDefinition } from '../mcp/types';
|
|
3
3
|
export interface CLIExtraCommand {
|
|
4
4
|
name: string;
|
|
5
5
|
def: ToolDefinition;
|
|
@@ -5,11 +5,9 @@ export declare const MIDSCENE_DEBUG_MODEL_PROFILE = "MIDSCENE_DEBUG_MODEL_PROFIL
|
|
|
5
5
|
export declare const MIDSCENE_DEBUG_MODEL_RESPONSE = "MIDSCENE_DEBUG_MODEL_RESPONSE";
|
|
6
6
|
export declare const MIDSCENE_DANGEROUSLY_PRINT_ALL_CONFIG = "MIDSCENE_DANGEROUSLY_PRINT_ALL_CONFIG";
|
|
7
7
|
export declare const MIDSCENE_DEBUG_MODE = "MIDSCENE_DEBUG_MODE";
|
|
8
|
-
export declare const
|
|
9
|
-
/**
|
|
10
|
-
* @deprecated Use MIDSCENE_CHROME_PATH instead. This is kept for backward compatibility.
|
|
11
|
-
*/
|
|
8
|
+
export declare const MIDSCENE_MCP_USE_PUPPETEER_MODE = "MIDSCENE_MCP_USE_PUPPETEER_MODE";
|
|
12
9
|
export declare const MIDSCENE_MCP_CHROME_PATH = "MIDSCENE_MCP_CHROME_PATH";
|
|
10
|
+
export declare const MIDSCENE_MCP_ANDROID_MODE = "MIDSCENE_MCP_ANDROID_MODE";
|
|
13
11
|
export declare const DOCKER_CONTAINER = "DOCKER_CONTAINER";
|
|
14
12
|
export declare const MIDSCENE_LANGSMITH_DEBUG = "MIDSCENE_LANGSMITH_DEBUG";
|
|
15
13
|
export declare const MIDSCENE_LANGFUSE_DEBUG = "MIDSCENE_LANGFUSE_DEBUG";
|
|
@@ -106,22 +104,22 @@ export declare const UNUSED_ENV_KEYS: string[];
|
|
|
106
104
|
* can not be override by overrideAIConfig
|
|
107
105
|
*/
|
|
108
106
|
export declare const BASIC_ENV_KEYS: readonly ["MIDSCENE_DEBUG_MODE", "MIDSCENE_DEBUG_MODEL_PROFILE", "MIDSCENE_DEBUG_MODEL_RESPONSE", "MIDSCENE_RUN_DIR"];
|
|
109
|
-
export declare const BOOLEAN_ENV_KEYS: readonly ["MIDSCENE_CACHE", "MIDSCENE_LANGSMITH_DEBUG", "MIDSCENE_LANGFUSE_DEBUG", "MIDSCENE_REPORT_QUIET"];
|
|
107
|
+
export declare const BOOLEAN_ENV_KEYS: readonly ["MIDSCENE_CACHE", "MIDSCENE_MCP_USE_PUPPETEER_MODE", "MIDSCENE_MCP_ANDROID_MODE", "MIDSCENE_LANGSMITH_DEBUG", "MIDSCENE_LANGFUSE_DEBUG", "MIDSCENE_REPORT_QUIET"];
|
|
110
108
|
export declare const NUMBER_ENV_KEYS: readonly ["MIDSCENE_CACHE_MAX_FILENAME_LENGTH", "MIDSCENE_REPLANNING_CYCLE_LIMIT"];
|
|
111
|
-
export declare const STRING_ENV_KEYS: readonly ["MIDSCENE_ADB_PATH", "MIDSCENE_ADB_REMOTE_HOST", "MIDSCENE_ADB_REMOTE_PORT", "MIDSCENE_ANDROID_IME_STRATEGY", "MIDSCENE_IOS_DEVICE_UDID", "MIDSCENE_IOS_SIMULATOR_UDID", "MIDSCENE_REPORT_TAG_NAME", "MIDSCENE_PREFERRED_LANGUAGE", "MATCH_BY_POSITION", "
|
|
109
|
+
export declare const STRING_ENV_KEYS: readonly ["MIDSCENE_ADB_PATH", "MIDSCENE_ADB_REMOTE_HOST", "MIDSCENE_ADB_REMOTE_PORT", "MIDSCENE_ANDROID_IME_STRATEGY", "MIDSCENE_IOS_DEVICE_UDID", "MIDSCENE_IOS_SIMULATOR_UDID", "MIDSCENE_REPORT_TAG_NAME", "MIDSCENE_PREFERRED_LANGUAGE", "MATCH_BY_POSITION", "MIDSCENE_MCP_CHROME_PATH", "DOCKER_CONTAINER"];
|
|
112
110
|
/**
|
|
113
111
|
* Non model related env keys, used for globally controlling the behavior of midscene
|
|
114
112
|
* Can not be override by agent.modelConfig but can be override by overrideAIConfig
|
|
115
113
|
* Can be access at any time
|
|
116
114
|
*/
|
|
117
|
-
export declare const GLOBAL_ENV_KEYS: readonly ["MIDSCENE_CACHE", "MIDSCENE_LANGSMITH_DEBUG", "MIDSCENE_LANGFUSE_DEBUG", "MIDSCENE_REPORT_QUIET", "MIDSCENE_CACHE_MAX_FILENAME_LENGTH", "MIDSCENE_REPLANNING_CYCLE_LIMIT", "MIDSCENE_ADB_PATH", "MIDSCENE_ADB_REMOTE_HOST", "MIDSCENE_ADB_REMOTE_PORT", "MIDSCENE_ANDROID_IME_STRATEGY", "MIDSCENE_IOS_DEVICE_UDID", "MIDSCENE_IOS_SIMULATOR_UDID", "MIDSCENE_REPORT_TAG_NAME", "MIDSCENE_PREFERRED_LANGUAGE", "MATCH_BY_POSITION", "
|
|
115
|
+
export declare const GLOBAL_ENV_KEYS: readonly ["MIDSCENE_CACHE", "MIDSCENE_MCP_USE_PUPPETEER_MODE", "MIDSCENE_MCP_ANDROID_MODE", "MIDSCENE_LANGSMITH_DEBUG", "MIDSCENE_LANGFUSE_DEBUG", "MIDSCENE_REPORT_QUIET", "MIDSCENE_CACHE_MAX_FILENAME_LENGTH", "MIDSCENE_REPLANNING_CYCLE_LIMIT", "MIDSCENE_ADB_PATH", "MIDSCENE_ADB_REMOTE_HOST", "MIDSCENE_ADB_REMOTE_PORT", "MIDSCENE_ANDROID_IME_STRATEGY", "MIDSCENE_IOS_DEVICE_UDID", "MIDSCENE_IOS_SIMULATOR_UDID", "MIDSCENE_REPORT_TAG_NAME", "MIDSCENE_PREFERRED_LANGUAGE", "MATCH_BY_POSITION", "MIDSCENE_MCP_CHROME_PATH", "DOCKER_CONTAINER"];
|
|
118
116
|
/**
|
|
119
117
|
* Model related eve keys, used for declare which model to use.
|
|
120
118
|
* Can be override by both agent.modelConfig and overrideAIConfig
|
|
121
119
|
* Can only be access after agent.constructor
|
|
122
120
|
*/
|
|
123
121
|
export declare const MODEL_ENV_KEYS: readonly ["MIDSCENE_MODEL_NAME", "MIDSCENE_MODEL_INIT_CONFIG_JSON", "MIDSCENE_MODEL_EXTRA_BODY_JSON", "MIDSCENE_MODEL_API_KEY", "MIDSCENE_MODEL_BASE_URL", "MIDSCENE_MODEL_SOCKS_PROXY", "MIDSCENE_MODEL_HTTP_PROXY", "MIDSCENE_MODEL_TIMEOUT", "MIDSCENE_MODEL_TEMPERATURE", "MIDSCENE_MODEL_RETRY_COUNT", "MIDSCENE_MODEL_RETRY_INTERVAL", "MIDSCENE_MODEL_REASONING_EFFORT", "MIDSCENE_MODEL_REASONING_ENABLED", "MIDSCENE_MODEL_REASONING_BUDGET", "MIDSCENE_USE_VLM_UI_TARS", "MIDSCENE_USE_QWEN_VL", "MIDSCENE_USE_QWEN3_VL", "MIDSCENE_USE_DOUBAO_VISION", "MIDSCENE_USE_GEMINI", "MIDSCENE_USE_VL_MODEL", "OPENAI_API_KEY", "OPENAI_BASE_URL", "MIDSCENE_OPENAI_INIT_CONFIG_JSON", "MIDSCENE_OPENAI_HTTP_PROXY", "MIDSCENE_OPENAI_SOCKS_PROXY", "MIDSCENE_INSIGHT_MODEL_NAME", "MIDSCENE_INSIGHT_MODEL_SOCKS_PROXY", "MIDSCENE_INSIGHT_MODEL_HTTP_PROXY", "MIDSCENE_INSIGHT_MODEL_BASE_URL", "MIDSCENE_INSIGHT_MODEL_API_KEY", "MIDSCENE_INSIGHT_MODEL_INIT_CONFIG_JSON", "MIDSCENE_INSIGHT_MODEL_EXTRA_BODY_JSON", "MIDSCENE_INSIGHT_MODEL_TIMEOUT", "MIDSCENE_INSIGHT_MODEL_TEMPERATURE", "MIDSCENE_INSIGHT_MODEL_RETRY_COUNT", "MIDSCENE_INSIGHT_MODEL_RETRY_INTERVAL", "MIDSCENE_INSIGHT_MODEL_FAMILY", "MIDSCENE_INSIGHT_MODEL_REASONING_EFFORT", "MIDSCENE_INSIGHT_MODEL_REASONING_ENABLED", "MIDSCENE_INSIGHT_MODEL_REASONING_BUDGET", "MIDSCENE_PLANNING_MODEL_NAME", "MIDSCENE_PLANNING_MODEL_SOCKS_PROXY", "MIDSCENE_PLANNING_MODEL_HTTP_PROXY", "MIDSCENE_PLANNING_MODEL_BASE_URL", "MIDSCENE_PLANNING_MODEL_API_KEY", "MIDSCENE_PLANNING_MODEL_INIT_CONFIG_JSON", "MIDSCENE_PLANNING_MODEL_EXTRA_BODY_JSON", "MIDSCENE_PLANNING_MODEL_TIMEOUT", "MIDSCENE_PLANNING_MODEL_TEMPERATURE", "MIDSCENE_PLANNING_MODEL_RETRY_COUNT", "MIDSCENE_PLANNING_MODEL_RETRY_INTERVAL", "MIDSCENE_PLANNING_MODEL_FAMILY", "MIDSCENE_PLANNING_MODEL_REASONING_EFFORT", "MIDSCENE_PLANNING_MODEL_REASONING_ENABLED", "MIDSCENE_PLANNING_MODEL_REASONING_BUDGET", "MIDSCENE_MODEL_FAMILY"];
|
|
124
|
-
export declare const ALL_ENV_KEYS: readonly [...string[], "MIDSCENE_DEBUG_MODE", "MIDSCENE_DEBUG_MODEL_PROFILE", "MIDSCENE_DEBUG_MODEL_RESPONSE", "MIDSCENE_RUN_DIR", "MIDSCENE_CACHE", "MIDSCENE_LANGSMITH_DEBUG", "MIDSCENE_LANGFUSE_DEBUG", "MIDSCENE_REPORT_QUIET", "MIDSCENE_CACHE_MAX_FILENAME_LENGTH", "MIDSCENE_REPLANNING_CYCLE_LIMIT", "MIDSCENE_ADB_PATH", "MIDSCENE_ADB_REMOTE_HOST", "MIDSCENE_ADB_REMOTE_PORT", "MIDSCENE_ANDROID_IME_STRATEGY", "MIDSCENE_IOS_DEVICE_UDID", "MIDSCENE_IOS_SIMULATOR_UDID", "MIDSCENE_REPORT_TAG_NAME", "MIDSCENE_PREFERRED_LANGUAGE", "MATCH_BY_POSITION", "
|
|
122
|
+
export declare const ALL_ENV_KEYS: readonly [...string[], "MIDSCENE_DEBUG_MODE", "MIDSCENE_DEBUG_MODEL_PROFILE", "MIDSCENE_DEBUG_MODEL_RESPONSE", "MIDSCENE_RUN_DIR", "MIDSCENE_CACHE", "MIDSCENE_MCP_USE_PUPPETEER_MODE", "MIDSCENE_MCP_ANDROID_MODE", "MIDSCENE_LANGSMITH_DEBUG", "MIDSCENE_LANGFUSE_DEBUG", "MIDSCENE_REPORT_QUIET", "MIDSCENE_CACHE_MAX_FILENAME_LENGTH", "MIDSCENE_REPLANNING_CYCLE_LIMIT", "MIDSCENE_ADB_PATH", "MIDSCENE_ADB_REMOTE_HOST", "MIDSCENE_ADB_REMOTE_PORT", "MIDSCENE_ANDROID_IME_STRATEGY", "MIDSCENE_IOS_DEVICE_UDID", "MIDSCENE_IOS_SIMULATOR_UDID", "MIDSCENE_REPORT_TAG_NAME", "MIDSCENE_PREFERRED_LANGUAGE", "MATCH_BY_POSITION", "MIDSCENE_MCP_CHROME_PATH", "DOCKER_CONTAINER", "MIDSCENE_MODEL_NAME", "MIDSCENE_MODEL_INIT_CONFIG_JSON", "MIDSCENE_MODEL_EXTRA_BODY_JSON", "MIDSCENE_MODEL_API_KEY", "MIDSCENE_MODEL_BASE_URL", "MIDSCENE_MODEL_SOCKS_PROXY", "MIDSCENE_MODEL_HTTP_PROXY", "MIDSCENE_MODEL_TIMEOUT", "MIDSCENE_MODEL_TEMPERATURE", "MIDSCENE_MODEL_RETRY_COUNT", "MIDSCENE_MODEL_RETRY_INTERVAL", "MIDSCENE_MODEL_REASONING_EFFORT", "MIDSCENE_MODEL_REASONING_ENABLED", "MIDSCENE_MODEL_REASONING_BUDGET", "MIDSCENE_USE_VLM_UI_TARS", "MIDSCENE_USE_QWEN_VL", "MIDSCENE_USE_QWEN3_VL", "MIDSCENE_USE_DOUBAO_VISION", "MIDSCENE_USE_GEMINI", "MIDSCENE_USE_VL_MODEL", "OPENAI_API_KEY", "OPENAI_BASE_URL", "MIDSCENE_OPENAI_INIT_CONFIG_JSON", "MIDSCENE_OPENAI_HTTP_PROXY", "MIDSCENE_OPENAI_SOCKS_PROXY", "MIDSCENE_INSIGHT_MODEL_NAME", "MIDSCENE_INSIGHT_MODEL_SOCKS_PROXY", "MIDSCENE_INSIGHT_MODEL_HTTP_PROXY", "MIDSCENE_INSIGHT_MODEL_BASE_URL", "MIDSCENE_INSIGHT_MODEL_API_KEY", "MIDSCENE_INSIGHT_MODEL_INIT_CONFIG_JSON", "MIDSCENE_INSIGHT_MODEL_EXTRA_BODY_JSON", "MIDSCENE_INSIGHT_MODEL_TIMEOUT", "MIDSCENE_INSIGHT_MODEL_TEMPERATURE", "MIDSCENE_INSIGHT_MODEL_RETRY_COUNT", "MIDSCENE_INSIGHT_MODEL_RETRY_INTERVAL", "MIDSCENE_INSIGHT_MODEL_FAMILY", "MIDSCENE_INSIGHT_MODEL_REASONING_EFFORT", "MIDSCENE_INSIGHT_MODEL_REASONING_ENABLED", "MIDSCENE_INSIGHT_MODEL_REASONING_BUDGET", "MIDSCENE_PLANNING_MODEL_NAME", "MIDSCENE_PLANNING_MODEL_SOCKS_PROXY", "MIDSCENE_PLANNING_MODEL_HTTP_PROXY", "MIDSCENE_PLANNING_MODEL_BASE_URL", "MIDSCENE_PLANNING_MODEL_API_KEY", "MIDSCENE_PLANNING_MODEL_INIT_CONFIG_JSON", "MIDSCENE_PLANNING_MODEL_EXTRA_BODY_JSON", "MIDSCENE_PLANNING_MODEL_TIMEOUT", "MIDSCENE_PLANNING_MODEL_TEMPERATURE", "MIDSCENE_PLANNING_MODEL_RETRY_COUNT", "MIDSCENE_PLANNING_MODEL_RETRY_INTERVAL", "MIDSCENE_PLANNING_MODEL_FAMILY", "MIDSCENE_PLANNING_MODEL_REASONING_EFFORT", "MIDSCENE_PLANNING_MODEL_REASONING_ENABLED", "MIDSCENE_PLANNING_MODEL_REASONING_BUDGET", "MIDSCENE_MODEL_FAMILY"];
|
|
125
123
|
export type TEnvKeys = (typeof ALL_ENV_KEYS)[number];
|
|
126
124
|
export type TGlobalConfig = Record<TEnvKeys, string | undefined>;
|
|
127
125
|
/**
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Internal-only helpers for CLI argument key aliasing.
|
|
2
|
+
* Internal-only helpers for CLI/MCP argument key aliasing.
|
|
3
3
|
* Not re-exported from the package entry point — keep consumers within
|
|
4
|
-
* `cli/`.
|
|
4
|
+
* `cli/` and `mcp/`.
|
|
5
5
|
*/
|
|
6
6
|
export declare function kebabToCamel(str: string): string;
|
|
7
7
|
export declare function camelToKebab(str: string): string;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import type { ParseArgsConfig } from 'node:util';
|
|
2
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
3
|
+
import { type ToolDefaults } from './tool-defaults';
|
|
4
|
+
import type { IMidsceneTools } from './types';
|
|
5
|
+
export interface BaseMCPServerConfig {
|
|
6
|
+
name: string;
|
|
7
|
+
version: string;
|
|
8
|
+
description: string;
|
|
9
|
+
}
|
|
10
|
+
export interface HttpLaunchOptions {
|
|
11
|
+
port: number;
|
|
12
|
+
host?: string;
|
|
13
|
+
}
|
|
14
|
+
export interface LaunchMCPServerResult {
|
|
15
|
+
/**
|
|
16
|
+
* The MCP server port (for HTTP mode)
|
|
17
|
+
*/
|
|
18
|
+
port?: number;
|
|
19
|
+
/**
|
|
20
|
+
* The server host (for HTTP mode)
|
|
21
|
+
*/
|
|
22
|
+
host?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Function to gracefully shutdown the MCP server
|
|
25
|
+
*/
|
|
26
|
+
close: () => Promise<void>;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* CLI argument configuration for MCP servers. Behavior flags (e.g.
|
|
30
|
+
* `--deep-locate`) are generated from {@link TOOL_BEHAVIOR_FLAGS}, so adding a
|
|
31
|
+
* new flag there exposes it here automatically.
|
|
32
|
+
*/
|
|
33
|
+
export declare const CLI_ARGS_CONFIG: ParseArgsConfig['options'];
|
|
34
|
+
export interface CLIArgs {
|
|
35
|
+
mode?: string;
|
|
36
|
+
port?: string;
|
|
37
|
+
host?: string;
|
|
38
|
+
/** Behavior flags such as `deep-locate` / `deep-think` (see TOOL_BEHAVIOR_FLAGS). */
|
|
39
|
+
[flag: string]: string | boolean | undefined;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Launch an MCP server based on CLI arguments
|
|
43
|
+
* Shared helper to reduce duplication across platform CLI entry points
|
|
44
|
+
*/
|
|
45
|
+
export declare function launchMCPServer(server: BaseMCPServer, args: CLIArgs): Promise<LaunchMCPServerResult>;
|
|
46
|
+
/**
|
|
47
|
+
* Base MCP Server class with programmatic launch() API
|
|
48
|
+
* Each platform extends this to provide their own tools manager
|
|
49
|
+
*/
|
|
50
|
+
export declare abstract class BaseMCPServer {
|
|
51
|
+
protected mcpServer: McpServer;
|
|
52
|
+
protected toolsManager?: IMidsceneTools;
|
|
53
|
+
protected config: BaseMCPServerConfig;
|
|
54
|
+
protected providedToolsManager?: IMidsceneTools;
|
|
55
|
+
protected toolDefaults: ToolDefaults;
|
|
56
|
+
constructor(config: BaseMCPServerConfig, toolsManager?: IMidsceneTools);
|
|
57
|
+
/**
|
|
58
|
+
* Set the default options injected into generated tool calls (e.g. forced
|
|
59
|
+
* deep locate / deep think). Must be called before `launch()` /
|
|
60
|
+
* `launchHttp()` so they are applied to the tools manager before its tools
|
|
61
|
+
* are generated. Merges with any previously set defaults.
|
|
62
|
+
*/
|
|
63
|
+
setToolDefaults(toolDefaults: ToolDefaults): void;
|
|
64
|
+
/**
|
|
65
|
+
* Platform-specific: create tools manager instance
|
|
66
|
+
* This is only called if no tools manager was provided in constructor
|
|
67
|
+
*/
|
|
68
|
+
protected abstract createToolsManager(): IMidsceneTools;
|
|
69
|
+
/**
|
|
70
|
+
* Initialize tools manager and attach to MCP server
|
|
71
|
+
*/
|
|
72
|
+
private initializeToolsManager;
|
|
73
|
+
/**
|
|
74
|
+
* Perform cleanup on shutdown
|
|
75
|
+
*/
|
|
76
|
+
private performCleanup;
|
|
77
|
+
/**
|
|
78
|
+
* Initialize and launch the MCP server with stdio transport
|
|
79
|
+
*/
|
|
80
|
+
launch(): Promise<LaunchMCPServerResult>;
|
|
81
|
+
/**
|
|
82
|
+
* Launch MCP server with HTTP transport
|
|
83
|
+
* Supports stateful sessions for web applications and service integration
|
|
84
|
+
*/
|
|
85
|
+
launchHttp(options: HttpLaunchOptions): Promise<LaunchMCPServerResult>;
|
|
86
|
+
/**
|
|
87
|
+
* Create a new HTTP session with transport
|
|
88
|
+
*/
|
|
89
|
+
private createHttpSession;
|
|
90
|
+
/**
|
|
91
|
+
* Start periodic session cleanup for inactive sessions
|
|
92
|
+
*/
|
|
93
|
+
private startSessionCleanup;
|
|
94
|
+
/**
|
|
95
|
+
* Setup shutdown handlers for HTTP server
|
|
96
|
+
*/
|
|
97
|
+
private setupHttpShutdownHandlers;
|
|
98
|
+
/**
|
|
99
|
+
* Get the underlying MCP server instance
|
|
100
|
+
*/
|
|
101
|
+
getServer(): McpServer;
|
|
102
|
+
/**
|
|
103
|
+
* Get the tools manager instance
|
|
104
|
+
*/
|
|
105
|
+
getToolsManager(): IMidsceneTools | undefined;
|
|
106
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
1
2
|
import type { z } from 'zod';
|
|
2
3
|
import { type CliReportSession } from './cli-report-session';
|
|
3
4
|
import { type ToolDefaults } from './tool-defaults';
|
|
@@ -10,11 +11,11 @@ import type { BaseAgent, BaseDevice, IMidsceneTools, ToolCliMetadata, ToolDefini
|
|
|
10
11
|
export interface InitArgSpec<TInitParam> {
|
|
11
12
|
/** Arg namespace, e.g. `android`, `ios`. */
|
|
12
13
|
namespace: string;
|
|
13
|
-
/** Zod shape describing the init args. Field names drive the
|
|
14
|
+
/** Zod shape describing the init args. Field names drive the MCP schema. */
|
|
14
15
|
shape: Record<string, z.ZodTypeAny>;
|
|
15
16
|
/**
|
|
16
17
|
* Optional CLI presentation hints. These affect `--help` output for
|
|
17
|
-
* single-platform CLIs but do not alter YAML protocol keys.
|
|
18
|
+
* single-platform CLIs but do not alter MCP/YAML protocol keys.
|
|
18
19
|
*/
|
|
19
20
|
cli?: {
|
|
20
21
|
/** Prefer bare `--device-id`-style options in platform CLI help output. */
|
|
@@ -29,23 +30,24 @@ export interface InitArgSpec<TInitParam> {
|
|
|
29
30
|
adapt?: (extracted: Record<string, unknown> | undefined) => TInitParam | undefined;
|
|
30
31
|
}
|
|
31
32
|
/**
|
|
32
|
-
* Base class for platform-specific
|
|
33
|
+
* Base class for platform-specific MCP tools.
|
|
33
34
|
* @typeParam TAgent - Platform-specific agent type.
|
|
34
35
|
* @typeParam TInitParam - Platform-specific init parameter consumed by
|
|
35
36
|
* `ensureAgent`. Defaults to `undefined` for platforms that take no args.
|
|
36
37
|
*/
|
|
37
38
|
export declare abstract class BaseMidsceneTools<TAgent extends BaseAgent = BaseAgent, TInitParam = unknown> implements IMidsceneTools {
|
|
39
|
+
protected mcpServer?: McpServer;
|
|
38
40
|
protected agent?: TAgent;
|
|
39
41
|
protected toolDefinitions: ToolDefinition[];
|
|
40
42
|
/**
|
|
41
43
|
* Default options injected into every generated tool call (e.g. forced deep
|
|
42
|
-
* locate / deep think). Set from
|
|
44
|
+
* locate / deep think). Set from server/CLI behavior flags before
|
|
43
45
|
* `initTools()` so they are baked into the generated tool handlers.
|
|
44
46
|
* See https://github.com/web-infra-dev/midscene/issues/2446.
|
|
45
47
|
*/
|
|
46
48
|
protected toolDefaults: ToolDefaults;
|
|
47
49
|
/**
|
|
48
|
-
* Declarative init-arg spec. Subclasses that accept CLI init args should
|
|
50
|
+
* Declarative init-arg spec. Subclasses that accept CLI/MCP init args should
|
|
49
51
|
* set this once and get `extractAgentInitParam` / `sanitizeToolArgs` /
|
|
50
52
|
* `getAgentInitArgSchema` auto-implemented.
|
|
51
53
|
*
|
|
@@ -64,7 +66,7 @@ export declare abstract class BaseMidsceneTools<TAgent extends BaseAgent = BaseA
|
|
|
64
66
|
protected abstract ensureAgent(initParam?: TInitParam): Promise<TAgent>;
|
|
65
67
|
private getInitArgKeys;
|
|
66
68
|
/**
|
|
67
|
-
* Extract a platform-specific agent init parameter from CLI tool args.
|
|
69
|
+
* Extract a platform-specific agent init parameter from CLI/MCP tool args.
|
|
68
70
|
*/
|
|
69
71
|
protected extractAgentInitParam(args: Record<string, unknown>): TInitParam | undefined;
|
|
70
72
|
/**
|
|
@@ -80,7 +82,7 @@ export declare abstract class BaseMidsceneTools<TAgent extends BaseAgent = BaseA
|
|
|
80
82
|
* show ergonomic bare flags while the underlying schema stays namespaced.
|
|
81
83
|
* When `preferBareKeys` is enabled, single-platform CLIs only accept the
|
|
82
84
|
* bare spellings; namespaced dotted spellings remain available through the
|
|
83
|
-
* YAML schema instead of the platform CLI surface.
|
|
85
|
+
* MCP/YAML schema instead of the platform CLI surface.
|
|
84
86
|
*/
|
|
85
87
|
protected getAgentInitArgCliMetadata(): ToolCliMetadata | undefined;
|
|
86
88
|
/**
|
|
@@ -107,6 +109,10 @@ export declare abstract class BaseMidsceneTools<TAgent extends BaseAgent = BaseA
|
|
|
107
109
|
* 2. Create temporary device instance to read actionSpace (always succeeds)
|
|
108
110
|
*/
|
|
109
111
|
initTools(): Promise<void>;
|
|
112
|
+
/**
|
|
113
|
+
* Attach to MCP server and register all tools
|
|
114
|
+
*/
|
|
115
|
+
attachToServer(server: McpServer): void;
|
|
110
116
|
/**
|
|
111
117
|
* Cleanup method - destroy agent and release resources
|
|
112
118
|
*/
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export * from './base-server';
|
|
1
2
|
export * from './base-tools';
|
|
2
3
|
export * from './tool-defaults';
|
|
3
4
|
export * from './agent-behavior-init-args';
|
|
@@ -5,4 +6,6 @@ export * from './init-arg-utils';
|
|
|
5
6
|
export * from './error-formatter';
|
|
6
7
|
export * from './tool-generator';
|
|
7
8
|
export * from './types';
|
|
9
|
+
export * from './inject-report-html-plugin';
|
|
10
|
+
export * from './launcher-helper';
|
|
8
11
|
export * from './chrome-path';
|
|
@@ -3,11 +3,11 @@ import type { ToolSchema } from './types';
|
|
|
3
3
|
export declare function extractNamespacedArgs<TFieldName extends string, TArgs extends Record<string, unknown> = Record<string, unknown>>(args: Record<string, unknown>, namespace: string, keys: readonly TFieldName[]): TArgs | undefined;
|
|
4
4
|
export declare function sanitizeNamespacedArgs(args: Record<string, unknown>, namespace: string, keys: readonly string[]): Record<string, unknown>;
|
|
5
5
|
/**
|
|
6
|
-
* Build a flat tool schema whose keys are dotted `"<namespace>.<field>"`.
|
|
6
|
+
* Build a flat MCP tool schema whose keys are dotted `"<namespace>.<field>"`.
|
|
7
7
|
*
|
|
8
8
|
* We intentionally stay flat (rather than `{ namespace: z.object({...}) }`) so
|
|
9
|
-
* that CLI (`--android.device-id`) and `--help` output share
|
|
10
|
-
* `readNamespacedArg` understands all three input shapes:
|
|
9
|
+
* that CLI (`--android.device-id`), MCP clients, and `--help` output all share
|
|
10
|
+
* the same spelling. `readNamespacedArg` understands all three input shapes:
|
|
11
11
|
* nested namespace object, dotted flat key, and bare key fallback.
|
|
12
12
|
*/
|
|
13
13
|
export declare function createNamespacedInitArgSchema(namespace: string, shape: Record<string, z.ZodTypeAny>): ToolSchema;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
interface RslibPluginApi {
|
|
2
|
+
onAfterBuild: (callback: () => void) => void;
|
|
3
|
+
}
|
|
4
|
+
/**
|
|
5
|
+
* Rslib plugin to inject report HTML from @midscene/core dist into MCP bundle.
|
|
6
|
+
* This runs after build and reads the already-injected HTML from core.
|
|
7
|
+
*
|
|
8
|
+
* Prerequisites:
|
|
9
|
+
* - @midscene/report must be in devDependencies to ensure correct build order
|
|
10
|
+
* - @midscene/core dist must exist with injected HTML
|
|
11
|
+
*
|
|
12
|
+
* @param packageDir - The directory of the MCP package (use __dirname)
|
|
13
|
+
*/
|
|
14
|
+
export declare function injectReportHtmlFromCore(packageDir: string): {
|
|
15
|
+
name: string;
|
|
16
|
+
setup(api: RslibPluginApi): void;
|
|
17
|
+
};
|
|
18
|
+
export {};
|