Skip to content

Commit 49d46ef

Browse files
committed
Update tools to support session-aware opt-out mode
1 parent eba0474 commit 49d46ef

42 files changed

Lines changed: 363 additions & 102 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/mcp/tools/device/build_device.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ import { ToolResponse, XcodePlatform } from '../../../types/common.ts';
1010
import { executeXcodeBuildCommand } from '../../../utils/build/index.ts';
1111
import type { CommandExecutor } from '../../../utils/execution/index.ts';
1212
import { getDefaultCommandExecutor } from '../../../utils/execution/index.ts';
13-
import { createSessionAwareTool } from '../../../utils/typed-tool-factory.ts';
13+
import {
14+
createSessionAwareTool,
15+
getSessionAwareToolSchemaShape,
16+
} from '../../../utils/typed-tool-factory.ts';
1417
import { nullifyEmptyStrings } from '../../../utils/schema-helpers.ts';
1518

1619
// Unified schema: XOR between projectPath and workspacePath
@@ -36,6 +39,13 @@ const buildDeviceSchema = baseSchema
3639

3740
export type BuildDeviceParams = z.infer<typeof buildDeviceSchema>;
3841

42+
const publicSchemaObject = baseSchemaObject.omit({
43+
projectPath: true,
44+
workspacePath: true,
45+
scheme: true,
46+
configuration: true,
47+
} as const);
48+
3949
/**
4050
* Business logic for building device project or workspace.
4151
* Exported for direct testing and reuse.
@@ -64,12 +74,10 @@ export async function buildDeviceLogic(
6474
export default {
6575
name: 'build_device',
6676
description: 'Builds an app for a connected device.',
67-
schema: baseSchemaObject.omit({
68-
projectPath: true,
69-
workspacePath: true,
70-
scheme: true,
71-
configuration: true,
72-
} as const).shape,
77+
schema: getSessionAwareToolSchemaShape({
78+
sessionAware: publicSchemaObject,
79+
legacy: baseSchemaObject,
80+
}),
7381
handler: createSessionAwareTool<BuildDeviceParams>({
7482
internalSchema: buildDeviceSchema as unknown as z.ZodType<BuildDeviceParams>,
7583
logicFunction: buildDeviceLogic,

src/mcp/tools/device/get_device_app_path.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ import { log } from '../../../utils/logging/index.ts';
1111
import { createTextResponse } from '../../../utils/responses/index.ts';
1212
import type { CommandExecutor } from '../../../utils/execution/index.ts';
1313
import { getDefaultCommandExecutor } from '../../../utils/execution/index.ts';
14-
import { createSessionAwareTool } from '../../../utils/typed-tool-factory.ts';
14+
import {
15+
createSessionAwareTool,
16+
getSessionAwareToolSchemaShape,
17+
} from '../../../utils/typed-tool-factory.ts';
1518
import { nullifyEmptyStrings } from '../../../utils/schema-helpers.ts';
1619

1720
// Unified schema: XOR between projectPath and workspacePath, sharing common options
@@ -43,6 +46,13 @@ const getDeviceAppPathSchema = baseSchema
4346
// Use z.infer for type safety
4447
type GetDeviceAppPathParams = z.infer<typeof getDeviceAppPathSchema>;
4548

49+
const publicSchemaObject = baseSchemaObject.omit({
50+
projectPath: true,
51+
workspacePath: true,
52+
scheme: true,
53+
configuration: true,
54+
} as const);
55+
4656
export async function get_device_app_pathLogic(
4757
params: GetDeviceAppPathParams,
4858
executor: CommandExecutor,
@@ -147,12 +157,10 @@ export async function get_device_app_pathLogic(
147157
export default {
148158
name: 'get_device_app_path',
149159
description: 'Retrieves the built app path for a connected device.',
150-
schema: baseSchemaObject.omit({
151-
projectPath: true,
152-
workspacePath: true,
153-
scheme: true,
154-
configuration: true,
155-
} as const).shape,
160+
schema: getSessionAwareToolSchemaShape({
161+
sessionAware: publicSchemaObject,
162+
legacy: baseSchemaObject,
163+
}),
156164
handler: createSessionAwareTool<GetDeviceAppPathParams>({
157165
internalSchema: getDeviceAppPathSchema as unknown as z.ZodType<GetDeviceAppPathParams>,
158166
logicFunction: get_device_app_pathLogic,

src/mcp/tools/device/install_app_device.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ import { ToolResponse } from '../../../types/common.ts';
1010
import { log } from '../../../utils/logging/index.ts';
1111
import type { CommandExecutor } from '../../../utils/execution/index.ts';
1212
import { getDefaultCommandExecutor } from '../../../utils/execution/index.ts';
13-
import { createSessionAwareTool } from '../../../utils/typed-tool-factory.ts';
13+
import {
14+
createSessionAwareTool,
15+
getSessionAwareToolSchemaShape,
16+
} from '../../../utils/typed-tool-factory.ts';
1417

1518
// Define schema as ZodObject
1619
const installAppDeviceSchema = z.object({
@@ -23,6 +26,8 @@ const installAppDeviceSchema = z.object({
2326
.describe('Path to the .app bundle to install (full path to the .app directory)'),
2427
});
2528

29+
const publicSchemaObject = installAppDeviceSchema.omit({ deviceId: true } as const);
30+
2631
// Use z.infer for type safety
2732
type InstallAppDeviceParams = z.infer<typeof installAppDeviceSchema>;
2833

@@ -83,7 +88,10 @@ export async function install_app_deviceLogic(
8388
export default {
8489
name: 'install_app_device',
8590
description: 'Installs an app on a connected device.',
86-
schema: installAppDeviceSchema.omit({ deviceId: true } as const).shape,
91+
schema: getSessionAwareToolSchemaShape({
92+
sessionAware: publicSchemaObject,
93+
legacy: installAppDeviceSchema,
94+
}),
8795
handler: createSessionAwareTool<InstallAppDeviceParams>({
8896
internalSchema: installAppDeviceSchema as unknown as z.ZodType<InstallAppDeviceParams>,
8997
logicFunction: install_app_deviceLogic,

src/mcp/tools/device/launch_app_device.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ import { ToolResponse } from '../../../types/common.ts';
1010
import { log } from '../../../utils/logging/index.ts';
1111
import type { CommandExecutor } from '../../../utils/execution/index.ts';
1212
import { getDefaultCommandExecutor } from '../../../utils/execution/index.ts';
13-
import { createSessionAwareTool } from '../../../utils/typed-tool-factory.ts';
13+
import {
14+
createSessionAwareTool,
15+
getSessionAwareToolSchemaShape,
16+
} from '../../../utils/typed-tool-factory.ts';
1417
import { promises as fs } from 'fs';
1518
import { tmpdir } from 'os';
1619
import { join } from 'path';
@@ -32,6 +35,8 @@ const launchAppDeviceSchema = z.object({
3235
.describe('Bundle identifier of the app to launch (e.g., "com.example.MyApp")'),
3336
});
3437

38+
const publicSchemaObject = launchAppDeviceSchema.omit({ deviceId: true } as const);
39+
3540
// Use z.infer for type safety
3641
type LaunchAppDeviceParams = z.infer<typeof launchAppDeviceSchema>;
3742

@@ -142,7 +147,10 @@ export async function launch_app_deviceLogic(
142147
export default {
143148
name: 'launch_app_device',
144149
description: 'Launches an app on a connected device.',
145-
schema: launchAppDeviceSchema.omit({ deviceId: true } as const).shape,
150+
schema: getSessionAwareToolSchemaShape({
151+
sessionAware: publicSchemaObject,
152+
legacy: launchAppDeviceSchema,
153+
}),
146154
handler: createSessionAwareTool<LaunchAppDeviceParams>({
147155
internalSchema: launchAppDeviceSchema as unknown as z.ZodType<LaunchAppDeviceParams>,
148156
logicFunction: launch_app_deviceLogic,

src/mcp/tools/device/stop_app_device.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ import { ToolResponse } from '../../../types/common.ts';
1010
import { log } from '../../../utils/logging/index.ts';
1111
import type { CommandExecutor } from '../../../utils/execution/index.ts';
1212
import { getDefaultCommandExecutor } from '../../../utils/execution/index.ts';
13-
import { createSessionAwareTool } from '../../../utils/typed-tool-factory.ts';
13+
import {
14+
createSessionAwareTool,
15+
getSessionAwareToolSchemaShape,
16+
} from '../../../utils/typed-tool-factory.ts';
1417

1518
// Define schema as ZodObject
1619
const stopAppDeviceSchema = z.object({
@@ -21,6 +24,8 @@ const stopAppDeviceSchema = z.object({
2124
// Use z.infer for type safety
2225
type StopAppDeviceParams = z.infer<typeof stopAppDeviceSchema>;
2326

27+
const publicSchemaObject = stopAppDeviceSchema.omit({ deviceId: true } as const);
28+
2429
export async function stop_app_deviceLogic(
2530
params: StopAppDeviceParams,
2631
executor: CommandExecutor,
@@ -85,7 +90,10 @@ export async function stop_app_deviceLogic(
8590
export default {
8691
name: 'stop_app_device',
8792
description: 'Stops a running app on a connected device.',
88-
schema: stopAppDeviceSchema.omit({ deviceId: true } as const).shape,
93+
schema: getSessionAwareToolSchemaShape({
94+
sessionAware: publicSchemaObject,
95+
legacy: stopAppDeviceSchema,
96+
}),
8997
handler: createSessionAwareTool<StopAppDeviceParams>({
9098
internalSchema: stopAppDeviceSchema as unknown as z.ZodType<StopAppDeviceParams>,
9199
logicFunction: stop_app_deviceLogic,

src/mcp/tools/device/test_device.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ import {
2121
getDefaultCommandExecutor,
2222
getDefaultFileSystemExecutor,
2323
} from '../../../utils/execution/index.ts';
24-
import { createSessionAwareTool } from '../../../utils/typed-tool-factory.ts';
24+
import {
25+
createSessionAwareTool,
26+
getSessionAwareToolSchemaShape,
27+
} from '../../../utils/typed-tool-factory.ts';
2528
import { nullifyEmptyStrings } from '../../../utils/schema-helpers.ts';
2629

2730
// Unified schema: XOR between projectPath and workspacePath
@@ -58,6 +61,14 @@ const testDeviceSchema = baseSchema
5861

5962
export type TestDeviceParams = z.infer<typeof testDeviceSchema>;
6063

64+
const publicSchemaObject = baseSchemaObject.omit({
65+
projectPath: true,
66+
workspacePath: true,
67+
scheme: true,
68+
deviceId: true,
69+
configuration: true,
70+
} as const);
71+
6172
/**
6273
* Type definition for test summary structure from xcresulttool
6374
* (JavaScript implementation - no actual interface, this is just documentation)
@@ -276,13 +287,10 @@ export async function testDeviceLogic(
276287
export default {
277288
name: 'test_device',
278289
description: 'Runs tests on a physical Apple device.',
279-
schema: baseSchemaObject.omit({
280-
projectPath: true,
281-
workspacePath: true,
282-
scheme: true,
283-
deviceId: true,
284-
configuration: true,
285-
} as const).shape,
290+
schema: getSessionAwareToolSchemaShape({
291+
sessionAware: publicSchemaObject,
292+
legacy: baseSchemaObject,
293+
}),
286294
handler: createSessionAwareTool<TestDeviceParams>({
287295
internalSchema: testDeviceSchema as unknown as z.ZodType<TestDeviceParams>,
288296
logicFunction: (params: TestDeviceParams, executor: CommandExecutor) =>

src/mcp/tools/logging/start_device_log_cap.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ import { log } from '../../../utils/logging/index.ts';
1414
import type { CommandExecutor, FileSystemExecutor } from '../../../utils/execution/index.ts';
1515
import { getDefaultCommandExecutor } from '../../../utils/execution/index.ts';
1616
import { ToolResponse } from '../../../types/common.ts';
17-
import { createSessionAwareTool } from '../../../utils/typed-tool-factory.ts';
17+
import {
18+
createSessionAwareTool,
19+
getSessionAwareToolSchemaShape,
20+
} from '../../../utils/typed-tool-factory.ts';
1821

1922
/**
2023
* Log file retention policy for device logs:
@@ -632,6 +635,8 @@ const startDeviceLogCapSchema = z.object({
632635
bundleId: z.string().describe('Bundle identifier of the app to launch and capture logs for.'),
633636
});
634637

638+
const publicSchemaObject = startDeviceLogCapSchema.omit({ deviceId: true } as const);
639+
635640
// Use z.infer for type safety
636641
type StartDeviceLogCapParams = z.infer<typeof startDeviceLogCapSchema>;
637642

@@ -679,7 +684,10 @@ export async function start_device_log_capLogic(
679684
export default {
680685
name: 'start_device_log_cap',
681686
description: 'Starts log capture on a connected device.',
682-
schema: startDeviceLogCapSchema.omit({ deviceId: true } as const).shape,
687+
schema: getSessionAwareToolSchemaShape({
688+
sessionAware: publicSchemaObject,
689+
legacy: startDeviceLogCapSchema,
690+
}),
683691
handler: createSessionAwareTool<StartDeviceLogCapParams>({
684692
internalSchema: startDeviceLogCapSchema as unknown as z.ZodType<StartDeviceLogCapParams>,
685693
logicFunction: start_device_log_capLogic,

src/mcp/tools/logging/start_sim_log_cap.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ import { z } from 'zod';
88
import { startLogCapture } from '../../../utils/log-capture/index.ts';
99
import { CommandExecutor, getDefaultCommandExecutor } from '../../../utils/command.ts';
1010
import { ToolResponse, createTextContent } from '../../../types/common.ts';
11-
import { createSessionAwareTool } from '../../../utils/typed-tool-factory.ts';
11+
import {
12+
createSessionAwareTool,
13+
getSessionAwareToolSchemaShape,
14+
} from '../../../utils/typed-tool-factory.ts';
1215

1316
// Define schema as ZodObject
1417
const startSimLogCapSchema = z.object({
@@ -61,7 +64,10 @@ export default {
6164
name: 'start_sim_log_cap',
6265
description:
6366
'Starts capturing logs from a specified simulator. Returns a session ID. By default, captures only structured logs.',
64-
schema: publicSchemaObject.shape, // MCP SDK compatibility
67+
schema: getSessionAwareToolSchemaShape({
68+
sessionAware: publicSchemaObject,
69+
legacy: startSimLogCapSchema,
70+
}),
6571
handler: createSessionAwareTool<StartSimLogCapParams>({
6672
internalSchema: startSimLogCapSchema as unknown as z.ZodType<StartSimLogCapParams>,
6773
logicFunction: start_sim_log_capLogic,

src/mcp/tools/macos/build_macos.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ import { executeXcodeBuildCommand } from '../../../utils/build/index.ts';
1111
import { ToolResponse, XcodePlatform } from '../../../types/common.ts';
1212
import type { CommandExecutor } from '../../../utils/execution/index.ts';
1313
import { getDefaultCommandExecutor } from '../../../utils/execution/index.ts';
14-
import { createSessionAwareTool } from '../../../utils/typed-tool-factory.ts';
14+
import {
15+
createSessionAwareTool,
16+
getSessionAwareToolSchemaShape,
17+
} from '../../../utils/typed-tool-factory.ts';
1518
import { nullifyEmptyStrings } from '../../../utils/schema-helpers.ts';
1619

1720
// Types for dependency injection
@@ -98,7 +101,10 @@ export async function buildMacOSLogic(
98101
export default {
99102
name: 'build_macos',
100103
description: 'Builds a macOS app.',
101-
schema: publicSchemaObject.shape,
104+
schema: getSessionAwareToolSchemaShape({
105+
sessionAware: publicSchemaObject,
106+
legacy: baseSchemaObject,
107+
}),
102108
handler: createSessionAwareTool<BuildMacOSParams>({
103109
internalSchema: buildMacOSSchema as unknown as z.ZodType<BuildMacOSParams>,
104110
logicFunction: buildMacOSLogic,

src/mcp/tools/macos/build_run_macos.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ import { executeXcodeBuildCommand } from '../../../utils/build/index.ts';
1212
import { ToolResponse, XcodePlatform } from '../../../types/common.ts';
1313
import type { CommandExecutor } from '../../../utils/execution/index.ts';
1414
import { getDefaultCommandExecutor } from '../../../utils/execution/index.ts';
15-
import { createSessionAwareTool } from '../../../utils/typed-tool-factory.ts';
15+
import {
16+
createSessionAwareTool,
17+
getSessionAwareToolSchemaShape,
18+
} from '../../../utils/typed-tool-factory.ts';
1619
import { nullifyEmptyStrings } from '../../../utils/schema-helpers.ts';
1720

1821
// Unified schema: XOR between projectPath and workspacePath
@@ -216,7 +219,10 @@ export async function buildRunMacOSLogic(
216219
export default {
217220
name: 'build_run_macos',
218221
description: 'Builds and runs a macOS app.',
219-
schema: publicSchemaObject.shape,
222+
schema: getSessionAwareToolSchemaShape({
223+
sessionAware: publicSchemaObject,
224+
legacy: baseSchemaObject,
225+
}),
220226
handler: createSessionAwareTool<BuildRunMacOSParams>({
221227
internalSchema: buildRunMacOSSchema as unknown as z.ZodType<BuildRunMacOSParams>,
222228
logicFunction: buildRunMacOSLogic,

0 commit comments

Comments
 (0)