@midscene/shared 1.2.1-beta-20260108154312.0 → 1.2.1-beta-20260109060244.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/dist/es/mcp/base-tools.mjs +1 -19
- package/dist/es/mcp/tool-generator.mjs +2 -4
- package/dist/lib/mcp/base-tools.js +1 -19
- package/dist/lib/mcp/tool-generator.js +2 -4
- package/dist/types/mcp/base-tools.d.ts +0 -4
- package/dist/types/mcp/types.d.ts +0 -1
- package/package.json +1 -1
- package/src/mcp/base-tools.ts +6 -44
- package/src/mcp/tool-generator.ts +0 -2
- package/src/mcp/types.ts +0 -1
|
@@ -41,27 +41,9 @@ class BaseMidsceneTools {
|
|
|
41
41
|
attachToServer(server) {
|
|
42
42
|
this.mcpServer = server;
|
|
43
43
|
if (0 === this.toolDefinitions.length) debug('Warning: No tools to register. Tools may be initialized lazily.');
|
|
44
|
-
for (const toolDef of this.toolDefinitions)
|
|
45
|
-
else this.mcpServer.tool(toolDef.name, toolDef.description, toolDef.schema, toolDef.handler);
|
|
44
|
+
for (const toolDef of this.toolDefinitions)this.mcpServer.tool(toolDef.name, toolDef.description, toolDef.schema, toolDef.handler);
|
|
46
45
|
debug('Registered', this.toolDefinitions.length, 'tools');
|
|
47
46
|
}
|
|
48
|
-
toolWithAutoDestroy(name, description, schema, handler) {
|
|
49
|
-
if (!this.mcpServer) throw new Error('MCP server not attached');
|
|
50
|
-
this.mcpServer.tool(name, description, schema, async (...args)=>{
|
|
51
|
-
try {
|
|
52
|
-
return await handler(...args);
|
|
53
|
-
} finally{
|
|
54
|
-
if (!process.env.MIDSCENE_MCP_DISABLE_AGENT_AUTO_DESTROY) {
|
|
55
|
-
try {
|
|
56
|
-
await this.agent?.destroy?.();
|
|
57
|
-
} catch (error) {
|
|
58
|
-
debug('Failed to destroy agent during cleanup:', error);
|
|
59
|
-
}
|
|
60
|
-
this.agent = void 0;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
47
|
async closeBrowser() {
|
|
66
48
|
await this.agent?.destroy?.();
|
|
67
49
|
}
|
|
@@ -168,8 +168,7 @@ function generateToolsFromActionSpace(actionSpace, getAgent) {
|
|
|
168
168
|
console.error(`Error in handler for "${action.name}":`, errorMessage);
|
|
169
169
|
return createErrorResult(`Failed to get agent or execute action "${action.name}": ${errorMessage}`);
|
|
170
170
|
}
|
|
171
|
-
}
|
|
172
|
-
autoDestroy: true
|
|
171
|
+
}
|
|
173
172
|
};
|
|
174
173
|
});
|
|
175
174
|
}
|
|
@@ -199,8 +198,7 @@ function generateCommonTools(getAgent) {
|
|
|
199
198
|
console.error('Error taking screenshot:', errorMessage);
|
|
200
199
|
return createErrorResult(`Failed to capture screenshot: ${errorMessage}`);
|
|
201
200
|
}
|
|
202
|
-
}
|
|
203
|
-
autoDestroy: true
|
|
201
|
+
}
|
|
204
202
|
}
|
|
205
203
|
];
|
|
206
204
|
}
|
|
@@ -69,27 +69,9 @@ class BaseMidsceneTools {
|
|
|
69
69
|
attachToServer(server) {
|
|
70
70
|
this.mcpServer = server;
|
|
71
71
|
if (0 === this.toolDefinitions.length) debug('Warning: No tools to register. Tools may be initialized lazily.');
|
|
72
|
-
for (const toolDef of this.toolDefinitions)
|
|
73
|
-
else this.mcpServer.tool(toolDef.name, toolDef.description, toolDef.schema, toolDef.handler);
|
|
72
|
+
for (const toolDef of this.toolDefinitions)this.mcpServer.tool(toolDef.name, toolDef.description, toolDef.schema, toolDef.handler);
|
|
74
73
|
debug('Registered', this.toolDefinitions.length, 'tools');
|
|
75
74
|
}
|
|
76
|
-
toolWithAutoDestroy(name, description, schema, handler) {
|
|
77
|
-
if (!this.mcpServer) throw new Error('MCP server not attached');
|
|
78
|
-
this.mcpServer.tool(name, description, schema, async (...args)=>{
|
|
79
|
-
try {
|
|
80
|
-
return await handler(...args);
|
|
81
|
-
} finally{
|
|
82
|
-
if (!process.env.MIDSCENE_MCP_DISABLE_AGENT_AUTO_DESTROY) {
|
|
83
|
-
try {
|
|
84
|
-
await this.agent?.destroy?.();
|
|
85
|
-
} catch (error) {
|
|
86
|
-
debug('Failed to destroy agent during cleanup:', error);
|
|
87
|
-
}
|
|
88
|
-
this.agent = void 0;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
75
|
async closeBrowser() {
|
|
94
76
|
await this.agent?.destroy?.();
|
|
95
77
|
}
|
|
@@ -197,8 +197,7 @@ function generateToolsFromActionSpace(actionSpace, getAgent) {
|
|
|
197
197
|
console.error(`Error in handler for "${action.name}":`, errorMessage);
|
|
198
198
|
return createErrorResult(`Failed to get agent or execute action "${action.name}": ${errorMessage}`);
|
|
199
199
|
}
|
|
200
|
-
}
|
|
201
|
-
autoDestroy: true
|
|
200
|
+
}
|
|
202
201
|
};
|
|
203
202
|
});
|
|
204
203
|
}
|
|
@@ -228,8 +227,7 @@ function generateCommonTools(getAgent) {
|
|
|
228
227
|
console.error('Error taking screenshot:', errorMessage);
|
|
229
228
|
return createErrorResult(`Failed to capture screenshot: ${errorMessage}`);
|
|
230
229
|
}
|
|
231
|
-
}
|
|
232
|
-
autoDestroy: true
|
|
230
|
+
}
|
|
233
231
|
}
|
|
234
232
|
];
|
|
235
233
|
}
|
|
@@ -36,10 +36,6 @@ export declare abstract class BaseMidsceneTools<TAgent extends BaseAgent = BaseA
|
|
|
36
36
|
* Attach to MCP server and register all tools
|
|
37
37
|
*/
|
|
38
38
|
attachToServer(server: McpServer): void;
|
|
39
|
-
/**
|
|
40
|
-
* Wrapper for auto-destroy behavior
|
|
41
|
-
*/
|
|
42
|
-
private toolWithAutoDestroy;
|
|
43
39
|
/**
|
|
44
40
|
* Cleanup method - destroy agent and release resources
|
|
45
41
|
*/
|
package/package.json
CHANGED
package/src/mcp/base-tools.ts
CHANGED
|
@@ -124,55 +124,17 @@ export abstract class BaseMidsceneTools<TAgent extends BaseAgent = BaseAgent>
|
|
|
124
124
|
}
|
|
125
125
|
|
|
126
126
|
for (const toolDef of this.toolDefinitions) {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
);
|
|
134
|
-
} else {
|
|
135
|
-
this.mcpServer.tool(
|
|
136
|
-
toolDef.name,
|
|
137
|
-
toolDef.description,
|
|
138
|
-
toolDef.schema,
|
|
139
|
-
toolDef.handler,
|
|
140
|
-
);
|
|
141
|
-
}
|
|
127
|
+
this.mcpServer.tool(
|
|
128
|
+
toolDef.name,
|
|
129
|
+
toolDef.description,
|
|
130
|
+
toolDef.schema,
|
|
131
|
+
toolDef.handler,
|
|
132
|
+
);
|
|
142
133
|
}
|
|
143
134
|
|
|
144
135
|
debug('Registered', this.toolDefinitions.length, 'tools');
|
|
145
136
|
}
|
|
146
137
|
|
|
147
|
-
/**
|
|
148
|
-
* Wrapper for auto-destroy behavior
|
|
149
|
-
*/
|
|
150
|
-
private toolWithAutoDestroy(
|
|
151
|
-
name: string,
|
|
152
|
-
description: string,
|
|
153
|
-
schema: any,
|
|
154
|
-
handler: (...args: any[]) => Promise<any>,
|
|
155
|
-
): void {
|
|
156
|
-
if (!this.mcpServer) {
|
|
157
|
-
throw new Error('MCP server not attached');
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
this.mcpServer.tool(name, description, schema, async (...args: any[]) => {
|
|
161
|
-
try {
|
|
162
|
-
return await handler(...args);
|
|
163
|
-
} finally {
|
|
164
|
-
if (!process.env.MIDSCENE_MCP_DISABLE_AGENT_AUTO_DESTROY) {
|
|
165
|
-
try {
|
|
166
|
-
await this.agent?.destroy?.();
|
|
167
|
-
} catch (error) {
|
|
168
|
-
debug('Failed to destroy agent during cleanup:', error);
|
|
169
|
-
}
|
|
170
|
-
this.agent = undefined;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
|
|
176
138
|
/**
|
|
177
139
|
* Cleanup method - destroy agent and release resources
|
|
178
140
|
*/
|
|
@@ -288,7 +288,6 @@ export function generateToolsFromActionSpace(
|
|
|
288
288
|
);
|
|
289
289
|
}
|
|
290
290
|
},
|
|
291
|
-
autoDestroy: true,
|
|
292
291
|
};
|
|
293
292
|
});
|
|
294
293
|
}
|
|
@@ -324,7 +323,6 @@ export function generateCommonTools(
|
|
|
324
323
|
);
|
|
325
324
|
}
|
|
326
325
|
},
|
|
327
|
-
autoDestroy: true,
|
|
328
326
|
},
|
|
329
327
|
];
|
|
330
328
|
}
|