Press Key
pinchtab_pressPress a keyboard key like Enter or Tab, optionally on a specific element, to trigger actions or navigation.
Instructions
Press a keyboard key (e.g. 'Enter', 'Tab', 'Escape', 'ArrowDown'). Optionally target a specific element.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| key | Yes | Key to press (e.g. 'Enter', 'Tab', 'Escape') | |
| ref | No | Element ref to focus before pressing the key (e.g. 'e5'). |
Implementation Reference
- src/tools/interaction.ts:112-121 (handler)The handler function for the 'pinchtab_press' tool. It receives { key, ref }, builds a body with kind:'press', and calls pinch('POST', '/action', body). On error it returns a toolError.
async ({ key, ref }) => { try { const body: Record<string, unknown> = { key, kind: "press" }; if (ref) body.ref = ref; return toolResult(await pinch("POST", "/action", body)); } catch (error) { return toolError(error); } }, ); - src/tools/interaction.ts:100-111 (schema)The tool metadata and input schema for 'pinchtab_press'. Defines 'key' (string, required) and 'ref' (string, optional) inputs. Also sets the description and title.
{ description: "Press a keyboard key (e.g. 'Enter', 'Tab', 'Escape', 'ArrowDown'). Optionally target a specific element.", inputSchema: z.object({ key: z.string().describe("Key to press (e.g. 'Enter', 'Tab', 'Escape')"), ref: z .string() .optional() .describe("Element ref to focus before pressing the key (e.g. 'e5')."), }), title: "Press Key", }, - src/tools/interaction.ts:98-121 (registration)Registration of the 'pinchtab_press' tool via server.registerTool(...) inside the registerInteractionTools function.
server.registerTool( "pinchtab_press", { description: "Press a keyboard key (e.g. 'Enter', 'Tab', 'Escape', 'ArrowDown'). Optionally target a specific element.", inputSchema: z.object({ key: z.string().describe("Key to press (e.g. 'Enter', 'Tab', 'Escape')"), ref: z .string() .optional() .describe("Element ref to focus before pressing the key (e.g. 'e5')."), }), title: "Press Key", }, async ({ key, ref }) => { try { const body: Record<string, unknown> = { key, kind: "press" }; if (ref) body.ref = ref; return toolResult(await pinch("POST", "/action", body)); } catch (error) { return toolError(error); } }, ); - src/utils.ts:17-49 (helper)The toolResult helper wraps data into an MCP content response. Used by the handler to return success results.
/** Wrap a tool handler with standardized error handling. */ export function toolResult(data: unknown): ToolResult { return { content: [{ text: toJson(data), type: "text" as const }] }; } /** Format an error as an MCP tool error response. */ export function toolError(error: unknown): ToolResult { const message = error instanceof Error ? error.message : String(error); return { content: [{ text: message, type: "text" as const }], isError: true, }; } - src/pinchtab/client.ts:6-49 (helper)The pinch() helper sends HTTP requests to the PinchTab backend. The handler calls pinch('POST', '/action', body) to execute the key press action.
export async function pinch( method: string, path: string, body?: Record<string, unknown>, ): Promise<unknown> { if (!(await isPinchtabRunning())) { await ensurePinchtabRunning(); } const headers: Record<string, string> = { "Content-Type": "application/json", }; if (PINCHTAB_TOKEN) { headers["Authorization"] = `Bearer ${PINCHTAB_TOKEN}`; } const url = `${PINCHTAB_URL}${path}`; let res: Response; try { res = await fetch(url, { body: body ? JSON.stringify(body) : undefined, headers, method, signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS), }); } catch (error) { if (error instanceof DOMException && error.name === "TimeoutError") { throw new Error(`PinchTab ${method} ${path} timed out after ${REQUEST_TIMEOUT_MS / 1000}s`); } throw error; } if (!res.ok) { const text = await res.text(); throw new Error(`PinchTab ${method} ${path} → ${res.status}: ${text}`); } const contentType = (res.headers.get("content-type") ?? "").split(";")[0].toLowerCase().trim(); if (contentType === "application/json") { return res.json(); } return res.text(); }