Skip to content

Commit f80f6e0

Browse files
committed
fix: resolve TypeScript errors in key_press.ts
1 parent 9900b23 commit f80f6e0

5 files changed

Lines changed: 33 additions & 24 deletions

File tree

src/mcp/tools/ui-testing/button.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,23 @@ export async function buttonLogic(
3737
): Promise<ToolResponse> {
3838
const toolName = 'button';
3939
const simUuidValidation = validateRequiredParam('simulatorUuid', params.simulatorUuid);
40-
if (!simUuidValidation.isValid) return simUuidValidation.errorResponse;
40+
if (!simUuidValidation.isValid) return simUuidValidation.errorResponse!;
4141
const buttonTypeValidation = validateRequiredParam('buttonType', params.buttonType);
42-
if (!buttonTypeValidation.isValid) return buttonTypeValidation.errorResponse;
42+
if (!buttonTypeValidation.isValid) return buttonTypeValidation.errorResponse!;
4343

4444
const { simulatorUuid, buttonType, duration } = params;
45-
const commandArgs = ['button', buttonType];
45+
const commandArgs = ['button', buttonType as string];
4646
if (duration !== undefined) {
4747
commandArgs.push('--duration', String(duration));
4848
}
4949

50-
log('info', `${LOG_PREFIX}/${toolName}: Starting ${buttonType} button press on ${simulatorUuid}`);
50+
log(
51+
'info',
52+
`${LOG_PREFIX}/${toolName}: Starting ${buttonType} button press on ${simulatorUuid as string}`,
53+
);
5154

5255
try {
53-
await executeAxeCommand(commandArgs, simulatorUuid, 'button', executor, axeHelpers);
56+
await executeAxeCommand(commandArgs, simulatorUuid as string, 'button', executor, axeHelpers);
5457
log('info', `${LOG_PREFIX}/${toolName}: Success for ${simulatorUuid}`);
5558
return {
5659
content: [{ type: 'text', text: `Hardware button '${buttonType}' pressed successfully.` }],
@@ -144,7 +147,9 @@ async function executeAxeCommand(
144147
);
145148
}
146149

147-
return result.output.trim();
150+
return {
151+
content: [{ type: 'text', text: result.output.trim() }],
152+
};
148153
} catch (error) {
149154
if (error instanceof Error) {
150155
if (error instanceof AxeError) {

src/mcp/tools/ui-testing/describe_ui.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export async function describe_uiLogic(
4545
): Promise<ToolResponse> {
4646
const toolName = 'describe_ui';
4747
const simUuidValidation = validateRequiredParam('simulatorUuid', params.simulatorUuid);
48-
if (!simUuidValidation.isValid) return simUuidValidation.errorResponse;
48+
if (!simUuidValidation.isValid) return simUuidValidation.errorResponse!;
4949

5050
const { simulatorUuid } = params;
5151
const commandArgs = ['describe-ui'];
@@ -114,7 +114,7 @@ export default {
114114
simulatorUuid: z.string().uuid('Invalid Simulator UUID format'),
115115
},
116116
async handler(args: Record<string, unknown>): Promise<ToolResponse> {
117-
return describe_uiLogic(args as DescribeUiParams, getDefaultCommandExecutor());
117+
return describe_uiLogic(args as unknown as DescribeUiParams, getDefaultCommandExecutor());
118118
},
119119
};
120120

@@ -128,7 +128,7 @@ async function executeAxeCommand(
128128
getAxePath: () => string | null;
129129
getBundledAxeEnvironment: () => Record<string, string>;
130130
},
131-
): Promise<ToolResponse> {
131+
): Promise<string> {
132132
// Get the appropriate axe binary path
133133
const axeBinary = axeHelpers ? axeHelpers.getAxePath() : getAxePath();
134134
if (!axeBinary) {

src/mcp/tools/ui-testing/gesture.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ export async function gestureLogic(
4747
): Promise<ToolResponse> {
4848
const toolName = 'gesture';
4949
const simUuidValidation = validateRequiredParam('simulatorUuid', params.simulatorUuid);
50-
if (!simUuidValidation.isValid) return simUuidValidation.errorResponse;
50+
if (!simUuidValidation.isValid) return simUuidValidation.errorResponse!;
5151
const presetValidation = validateRequiredParam('preset', params.preset);
52-
if (!presetValidation.isValid) return presetValidation.errorResponse;
52+
if (!presetValidation.isValid) return presetValidation.errorResponse!;
5353

5454
const { simulatorUuid, preset, screenWidth, screenHeight, duration, delta, preDelay, postDelay } =
5555
params;
@@ -163,7 +163,7 @@ export default {
163163
.describe('Optional: Delay after completing the gesture in seconds.'),
164164
},
165165
async handler(args: Record<string, unknown>): Promise<ToolResponse> {
166-
return gestureLogic(args as GestureParams, getDefaultCommandExecutor());
166+
return gestureLogic(args as unknown as GestureParams, getDefaultCommandExecutor());
167167
},
168168
};
169169

@@ -215,7 +215,7 @@ async function executeAxeCommand(
215215
);
216216
}
217217

218-
return result.output.trim();
218+
return createTextResponse(result.output.trim());
219219
} catch (error) {
220220
if (error instanceof Error) {
221221
if (error instanceof AxeError) {

src/mcp/tools/ui-testing/key_press.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ export async function key_pressLogic(
3131
): Promise<ToolResponse> {
3232
const toolName = 'key_press';
3333
const simUuidValidation = validateRequiredParam('simulatorUuid', params.simulatorUuid);
34-
if (!simUuidValidation.isValid) return simUuidValidation.errorResponse;
34+
if (!simUuidValidation.isValid) return simUuidValidation.errorResponse!;
3535
const keyCodeValidation = validateRequiredParam('keyCode', params.keyCode);
36-
if (!keyCodeValidation.isValid) return keyCodeValidation.errorResponse;
36+
if (!keyCodeValidation.isValid) return keyCodeValidation.errorResponse!;
3737

38-
const { simulatorUuid, keyCode, duration } = params as KeyPressParams;
38+
const { simulatorUuid, keyCode, duration } = params as unknown as KeyPressParams;
3939
const commandArgs = ['key', String(keyCode)];
4040
if (duration !== undefined) {
4141
commandArgs.push('--duration', String(duration));
@@ -144,7 +144,9 @@ async function executeAxeCommand(
144144
);
145145
}
146146

147-
return result.output.trim();
147+
return {
148+
content: [{ type: 'text', text: result.output.trim() }],
149+
};
148150
} catch (error) {
149151
if (error instanceof Error) {
150152
if (error instanceof AxeError) {

src/mcp/tools/ui-testing/key_sequence.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,32 +31,34 @@ export async function key_sequenceLogic(
3131
): Promise<ToolResponse> {
3232
const toolName = 'key_sequence';
3333
const simUuidValidation = validateRequiredParam('simulatorUuid', params.simulatorUuid);
34-
if (!simUuidValidation.isValid) return simUuidValidation.errorResponse;
34+
if (!simUuidValidation.isValid) return simUuidValidation.errorResponse!;
3535
const keyCodesValidation = validateRequiredParam('keyCodes', params.keyCodes);
36-
if (!keyCodesValidation.isValid) return keyCodesValidation.errorResponse;
36+
if (!keyCodesValidation.isValid) return keyCodesValidation.errorResponse!;
3737

3838
const { simulatorUuid, keyCodes, delay } = params;
39-
const commandArgs = ['key-sequence', '--keycodes', keyCodes.join(',')];
39+
const commandArgs = ['key-sequence', '--keycodes', (keyCodes as number[]).join(',')];
4040
if (delay !== undefined) {
4141
commandArgs.push('--delay', String(delay));
4242
}
4343

4444
log(
4545
'info',
46-
`${LOG_PREFIX}/${toolName}: Starting key sequence [${keyCodes.join(',')}] on ${simulatorUuid}`,
46+
`${LOG_PREFIX}/${toolName}: Starting key sequence [${(keyCodes as number[]).join(',')}] on ${simulatorUuid}`,
4747
);
4848

4949
try {
5050
await executeAxeCommand(
5151
commandArgs,
52-
simulatorUuid,
52+
simulatorUuid as string,
5353
'key-sequence',
5454
executor,
5555
getAxePathFn,
5656
getBundledAxeEnvironmentFn,
5757
);
5858
log('info', `${LOG_PREFIX}/${toolName}: Success for ${simulatorUuid}`);
59-
return createTextResponse(`Key sequence [${keyCodes.join(',')}] executed successfully.`);
59+
return createTextResponse(
60+
`Key sequence [${(keyCodes as number[]).join(',')}] executed successfully.`,
61+
);
6062
} catch (error) {
6163
log('error', `${LOG_PREFIX}/${toolName}: Failed - ${error}`);
6264
if (error instanceof DependencyError) {
@@ -144,7 +146,7 @@ async function executeAxeCommand(
144146
);
145147
}
146148

147-
return result.output.trim();
149+
return createTextResponse(result.output.trim());
148150
} catch (error) {
149151
if (error instanceof Error) {
150152
if (error instanceof AxeError) {

0 commit comments

Comments
 (0)