Close Tab
pinchtab_close_tabClose the active browser tab or a specific tab by providing its ID.
Instructions
Close the current tab or a specific tab by its ID.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| tabId | No | Tab ID to close. If omitted, closes the current tab. |
Implementation Reference
- src/tools/instances.ts:35-43 (handler)Handler function for pinchtab_close_tab. Accepts optional tabId, sends POST /tab with {action:'close'} and optionally tabId to the PinchTab HTTP API via pinch().
async ({ tabId }) => { try { const body: Record<string, unknown> = { action: "close" }; if (tabId) body.tabId = tabId; return toolResult(await pinch("POST", "/tab", body)); } catch (error) { return toolError(error); } }, - src/tools/instances.ts:25-33 (schema)Input schema for pinchtab_close_tab. Defines optional tabId (string) parameter for closing a specific tab.
{ description: "Close the current tab or a specific tab by its ID.", inputSchema: z.object({ tabId: z .string() .optional() .describe("Tab ID to close. If omitted, closes the current tab."), }), title: "Close Tab", - src/tools/instances.ts:23-44 (registration)Registration of 'pinchtab_close_tab' tool on the MCP server via server.registerTool() inside registerInstanceTools().
server.registerTool( "pinchtab_close_tab", { description: "Close the current tab or a specific tab by its ID.", inputSchema: z.object({ tabId: z .string() .optional() .describe("Tab ID to close. If omitted, closes the current tab."), }), title: "Close Tab", }, async ({ tabId }) => { try { const body: Record<string, unknown> = { action: "close" }; if (tabId) body.tabId = tabId; return toolResult(await pinch("POST", "/tab", body)); } catch (error) { return toolError(error); } }, ); - src/tools/index.ts:7-12 (registration)registerAllTools() calls registerInstanceTools(server), which registers pinchtab_close_tab along with other instance tools.
export function registerAllTools(server: McpServer) { registerInstanceTools(server); registerNavigationTools(server); registerInteractionTools(server); registerContentTools(server); } - src/pinchtab/client.ts:6-49 (helper)The pinch() helper function sends HTTP requests (POST /tab with body) to the PinchTab local API, used by the handler.
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(); }