Skip to content

Commit 664854a

Browse files
ottomaoclaude
andauthored
revert(web-integration): remove MCP session changes and createExportSessionReportTool (#2151)
Revert all MCP-related session persistence modifications across platforms (android, computer, harmony, ios, web, web-puppeteer) and shared MCP infrastructure. Remove createExportSessionReportTool and its export. These will be submitted in a separate PR. https://claude.ai/code/session_01S1H1TfbYsvLbgCm95qHgRN Co-authored-by: Claude <noreply@anthropic.com>
1 parent 9334381 commit 664854a

File tree

15 files changed

+50
-962
lines changed

15 files changed

+50
-962
lines changed

packages/android/src/mcp-tools.ts

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
import {
2-
createExportSessionReportTool,
3-
createSessionAgentOptions,
4-
z,
5-
} from '@midscene/core';
1+
import { z } from '@midscene/core';
62
import { getDebug } from '@midscene/shared/logger';
73
import { BaseMidsceneTools, type ToolDefinition } from '@midscene/shared/mcp';
84
import { type AndroidAgent, agentFromAdbDevice } from './agent';
@@ -21,15 +17,8 @@ export class AndroidMidsceneTools extends BaseMidsceneTools<AndroidAgent> {
2117
return new AndroidDevice('temp-for-action-space', {});
2218
}
2319

24-
protected async ensureAgent(
25-
deviceId?: string,
26-
options?: { sessionId?: string },
27-
): Promise<AndroidAgent> {
28-
const sessionId = options?.sessionId;
29-
if (
30-
this.agent &&
31-
(deviceId || this.shouldResetAgentForSession(sessionId))
32-
) {
20+
protected async ensureAgent(deviceId?: string): Promise<AndroidAgent> {
21+
if (this.agent && deviceId) {
3322
// If a specific deviceId is requested and we have an agent,
3423
// destroy it to create a new one with the new device
3524
try {
@@ -45,13 +34,8 @@ export class AndroidMidsceneTools extends BaseMidsceneTools<AndroidAgent> {
4534
}
4635

4736
debug('Creating Android agent with deviceId:', deviceId || 'auto-detect');
48-
const sessionOptions = createSessionAgentOptions({
49-
sessionId,
50-
platform: 'android',
51-
});
5237
const agent = await agentFromAdbDevice(deviceId, {
5338
autoDismissKeyboard: false,
54-
...sessionOptions,
5539
});
5640
this.agent = agent;
5741
return agent;
@@ -72,18 +56,15 @@ export class AndroidMidsceneTools extends BaseMidsceneTools<AndroidAgent> {
7256
.optional()
7357
.describe('Android device ID (from adb devices)'),
7458
},
75-
handler: async (args: { deviceId?: string; sessionId?: string }) => {
76-
const agent = await this.ensureAgent(
77-
args.deviceId,
78-
this.getAgentOptions(args as Record<string, unknown>),
79-
);
59+
handler: async ({ deviceId }: { deviceId?: string }) => {
60+
const agent = await this.ensureAgent(deviceId);
8061
const screenshot = await agent.page.screenshotBase64();
8162

8263
return {
8364
content: [
8465
{
8566
type: 'text',
86-
text: `Connected to Android device${args.deviceId ? `: ${args.deviceId}` : ' (auto-detected)'}`,
67+
text: `Connected to Android device${deviceId ? `: ${deviceId}` : ' (auto-detected)'}`,
8768
},
8869
...this.buildScreenshotContent(screenshot),
8970
],
@@ -98,7 +79,6 @@ export class AndroidMidsceneTools extends BaseMidsceneTools<AndroidAgent> {
9879
schema: {},
9980
handler: this.createDisconnectHandler('Android device'),
10081
},
101-
createExportSessionReportTool(),
10282
];
10383
}
10484
}

packages/computer/src/mcp-tools.ts

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
import {
2-
createExportSessionReportTool,
3-
createSessionAgentOptions,
4-
z,
5-
} from '@midscene/core';
1+
import { z } from '@midscene/core';
62
import { getDebug } from '@midscene/shared/logger';
73
import { BaseMidsceneTools, type ToolDefinition } from '@midscene/shared/mcp';
84
import { type ComputerAgent, agentFromComputer } from './agent';
@@ -22,14 +18,9 @@ export class ComputerMidsceneTools extends BaseMidsceneTools<ComputerAgent> {
2218

2319
protected async ensureAgent(
2420
displayId?: string,
25-
options?: { sessionId?: string; headless?: boolean },
21+
headless?: boolean,
2622
): Promise<ComputerAgent> {
27-
const sessionId = options?.sessionId;
28-
const headless = options?.headless;
29-
if (
30-
this.agent &&
31-
(displayId || this.shouldResetAgentForSession(sessionId))
32-
) {
23+
if (this.agent && displayId) {
3324
// If a specific displayId is requested and we have an agent,
3425
// destroy it to create a new one with the new display
3526
try {
@@ -45,14 +36,9 @@ export class ComputerMidsceneTools extends BaseMidsceneTools<ComputerAgent> {
4536
}
4637

4738
debug('Creating Computer agent with displayId:', displayId || 'primary');
48-
const sessionOptions = createSessionAgentOptions({
49-
sessionId,
50-
platform: 'computer',
51-
});
5239
const opts = {
5340
...(displayId ? { displayId } : {}),
5441
...(headless !== undefined ? { headless } : {}),
55-
...sessionOptions,
5642
};
5743
const agent = await agentFromComputer(
5844
Object.keys(opts).length > 0 ? opts : undefined,
@@ -80,22 +66,18 @@ export class ComputerMidsceneTools extends BaseMidsceneTools<ComputerAgent> {
8066
.optional()
8167
.describe('Start virtual display via Xvfb (Linux only)'),
8268
},
83-
handler: async (args: {
84-
displayId?: string;
85-
headless?: boolean;
86-
sessionId?: string;
87-
}) => {
88-
const agent = await this.ensureAgent(args.displayId, {
89-
...this.getAgentOptions(args as Record<string, unknown>),
90-
headless: args.headless,
91-
});
69+
handler: async ({
70+
displayId,
71+
headless,
72+
}: { displayId?: string; headless?: boolean }) => {
73+
const agent = await this.ensureAgent(displayId, headless);
9274
const screenshot = await agent.interface.screenshotBase64();
9375

9476
return {
9577
content: [
9678
{
9779
type: 'text',
98-
text: `Connected to computer${args.displayId ? ` (Display: ${args.displayId})` : ' (Primary display)'}`,
80+
text: `Connected to computer${displayId ? ` (Display: ${displayId})` : ' (Primary display)'}`,
9981
},
10082
...this.buildScreenshotContent(screenshot),
10183
],
@@ -108,7 +90,6 @@ export class ComputerMidsceneTools extends BaseMidsceneTools<ComputerAgent> {
10890
schema: {},
10991
handler: this.createDisconnectHandler('computer'),
11092
},
111-
createExportSessionReportTool(),
11293
{
11394
name: 'computer_list_displays',
11495
description: 'List all available displays/monitors',

packages/core/src/execution-report.ts

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {
44
globalConfigManager,
55
} from '@midscene/shared/env';
66
import { logMsg } from '@midscene/shared/utils';
7-
import { z } from 'zod';
87
import { ExecutionStore } from './execution-store';
98
import { reportHTMLContent } from './utils';
109

@@ -24,40 +23,3 @@ export function exportSessionReport(
2423

2524
return reportPath;
2625
}
27-
28-
/**
29-
* Create a platform-agnostic MCP tool definition for exporting session reports.
30-
* Eliminates the need for each platform to duplicate the same handler.
31-
*/
32-
export function createExportSessionReportTool() {
33-
return {
34-
name: 'export_session_report',
35-
description: 'Generate a merged HTML report from a persisted session',
36-
schema: {
37-
sessionId: z.string().describe('Persistent session ID to export'),
38-
},
39-
handler: async (args: { sessionId?: string }) => {
40-
const { sessionId } = args;
41-
if (typeof sessionId !== 'string' || !sessionId) {
42-
return {
43-
content: [
44-
{
45-
type: 'text' as const,
46-
text: 'sessionId is required to export a session report',
47-
},
48-
],
49-
isError: true,
50-
};
51-
}
52-
const reportPath = exportSessionReport(sessionId);
53-
return {
54-
content: [
55-
{
56-
type: 'text' as const,
57-
text: `Session report generated: ${reportPath}`,
58-
},
59-
],
60-
};
61-
},
62-
};
63-
}

packages/core/src/index.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,12 @@ export {
6464
} from './dump';
6565

6666
// Execution persistence & report
67-
export { ExecutionStore, createSessionAgentOptions } from './execution-store';
67+
export { ExecutionStore } from './execution-store';
6868
export type {
6969
SessionRecord,
7070
EnsureSessionRecordInput,
7171
} from './execution-store';
72-
export {
73-
exportSessionReport,
74-
createExportSessionReportTool,
75-
} from './execution-report';
72+
export { exportSessionReport } from './execution-report';
7673

7774
// ScreenshotItem
7875
export { ScreenshotItem } from './screenshot-item';

packages/harmony/src/mcp-tools.ts

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
import {
2-
createExportSessionReportTool,
3-
createSessionAgentOptions,
4-
z,
5-
} from '@midscene/core';
1+
import { z } from '@midscene/core';
62
import { getDebug } from '@midscene/shared/logger';
73
import { BaseMidsceneTools, type ToolDefinition } from '@midscene/shared/mcp';
84
import { type HarmonyAgent, agentFromHdcDevice } from './agent';
@@ -15,15 +11,8 @@ export class HarmonyMidsceneTools extends BaseMidsceneTools<HarmonyAgent> {
1511
return new HarmonyDevice('temp-for-action-space', {});
1612
}
1713

18-
protected async ensureAgent(
19-
deviceId?: string,
20-
options?: { sessionId?: string },
21-
): Promise<HarmonyAgent> {
22-
const sessionId = options?.sessionId;
23-
if (
24-
this.agent &&
25-
(deviceId || this.shouldResetAgentForSession(sessionId))
26-
) {
14+
protected async ensureAgent(deviceId?: string): Promise<HarmonyAgent> {
15+
if (this.agent && deviceId) {
2716
try {
2817
await this.agent.destroy?.();
2918
} catch (error) {
@@ -37,13 +26,8 @@ export class HarmonyMidsceneTools extends BaseMidsceneTools<HarmonyAgent> {
3726
}
3827

3928
debug('Creating Harmony agent with deviceId:', deviceId || 'auto-detect');
40-
const sessionOptions = createSessionAgentOptions({
41-
sessionId,
42-
platform: 'harmony',
43-
});
4429
const agent = await agentFromHdcDevice(deviceId, {
4530
autoDismissKeyboard: false,
46-
...sessionOptions,
4731
});
4832
this.agent = agent;
4933
return agent;
@@ -61,18 +45,15 @@ export class HarmonyMidsceneTools extends BaseMidsceneTools<HarmonyAgent> {
6145
.optional()
6246
.describe('HarmonyOS device ID (from hdc list targets)'),
6347
},
64-
handler: async (args: { deviceId?: string; sessionId?: string }) => {
65-
const agent = await this.ensureAgent(
66-
args.deviceId,
67-
this.getAgentOptions(args as Record<string, unknown>),
68-
);
48+
handler: async ({ deviceId }: { deviceId?: string }) => {
49+
const agent = await this.ensureAgent(deviceId);
6950
const screenshot = await agent.page.screenshotBase64();
7051

7152
return {
7253
content: [
7354
{
7455
type: 'text',
75-
text: `Connected to HarmonyOS device${args.deviceId ? `: ${args.deviceId}` : ' (auto-detected)'}`,
56+
text: `Connected to HarmonyOS device${deviceId ? `: ${deviceId}` : ' (auto-detected)'}`,
7657
},
7758
...this.buildScreenshotContent(screenshot),
7859
],
@@ -87,7 +68,6 @@ export class HarmonyMidsceneTools extends BaseMidsceneTools<HarmonyAgent> {
8768
schema: {},
8869
handler: this.createDisconnectHandler('HarmonyOS device'),
8970
},
90-
createExportSessionReportTool(),
9171
];
9272
}
9373
}

packages/ios/src/mcp-tools.ts

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
import {
2-
createExportSessionReportTool,
3-
createSessionAgentOptions,
4-
} from '@midscene/core';
51
import { getDebug } from '@midscene/shared/logger';
62
import { BaseMidsceneTools, type ToolDefinition } from '@midscene/shared/mcp';
73
import { type IOSAgent, agentFromWebDriverAgent } from './agent';
@@ -20,33 +16,14 @@ export class IOSMidsceneTools extends BaseMidsceneTools<IOSAgent> {
2016
return new IOSDevice({});
2117
}
2218

23-
protected async ensureAgent(
24-
_unused?: string,
25-
options?: { sessionId?: string },
26-
): Promise<IOSAgent> {
27-
const sessionId = options?.sessionId;
28-
29-
if (this.agent && this.shouldResetAgentForSession(sessionId)) {
30-
try {
31-
await this.agent.destroy?.();
32-
} catch (error) {
33-
debug('Failed to destroy agent during cleanup:', error);
34-
}
35-
this.agent = undefined;
36-
}
37-
19+
protected async ensureAgent(): Promise<IOSAgent> {
3820
if (this.agent) {
3921
return this.agent;
4022
}
4123

4224
debug('Creating iOS agent with WebDriverAgent');
43-
const sessionOptions = createSessionAgentOptions({
44-
sessionId,
45-
platform: 'ios',
46-
});
4725
this.agent = await agentFromWebDriverAgent({
4826
autoDismissKeyboard: false,
49-
...sessionOptions,
5027
});
5128
return this.agent;
5229
}
@@ -60,11 +37,8 @@ export class IOSMidsceneTools extends BaseMidsceneTools<IOSAgent> {
6037
name: 'ios_connect',
6138
description: 'Connect to iOS device or simulator via WebDriverAgent',
6239
schema: {},
63-
handler: async (args: { sessionId?: string }) => {
64-
const agent = await this.ensureAgent(
65-
undefined,
66-
this.getAgentOptions(args as Record<string, unknown>),
67-
);
40+
handler: async () => {
41+
const agent = await this.ensureAgent();
6842
const screenshot = await agent.page.screenshotBase64();
6943

7044
return {
@@ -86,7 +60,6 @@ export class IOSMidsceneTools extends BaseMidsceneTools<IOSAgent> {
8660
schema: {},
8761
handler: this.createDisconnectHandler('iOS device'),
8862
},
89-
createExportSessionReportTool(),
9063
];
9164
}
9265
}

0 commit comments

Comments
 (0)