Select
pinchtab_selectSelect an option in a dropdown by referencing the element ID and providing the option value or visible text.
Instructions
Select an option in a dropdown by its ref ID. Pass the option value or visible text.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ref | Yes | Element reference ID of the <select> | |
| value | Yes | Option value or visible text to select |
Implementation Reference
- src/tools/interaction.ts:171-195 (registration)Registration of the 'pinchtab_select' tool via server.registerTool().
server.registerTool( "pinchtab_select", { description: "Select an option in a <select> dropdown by its ref ID. Pass the option value or visible text.", inputSchema: z.object({ ref: z.string().describe("Element reference ID of the <select>"), value: z.string().describe("Option value or visible text to select"), }), title: "Select", }, async ({ ref, value }) => { try { return toolResult( await pinch("POST", "/action", { kind: "select", ref, value, }), ); } catch (error) { return toolError(error); } }, ); - src/tools/interaction.ts:176-179 (schema)Input schema for pinchtab_select: requires 'ref' (string) and 'value' (string) fields.
inputSchema: z.object({ ref: z.string().describe("Element reference ID of the <select>"), value: z.string().describe("Option value or visible text to select"), }), - src/tools/interaction.ts:182-195 (handler)Handler function that calls pinch('POST', '/action', { kind: 'select', ref, value }) and returns the result.
async ({ ref, value }) => { try { return toolResult( await pinch("POST", "/action", { kind: "select", ref, value, }), ); } catch (error) { return toolError(error); } }, ); - src/pinchtab/client.ts:6-49 (helper)The 'pinch' helper function used by the handler to make HTTP requests to the PinchTab backend.
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(); } - src/utils.ts:17-29 (helper)Utility functions toolResult and toolError used to format the handler's response.
/** 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, }; }