import_cookies
Import cookies as JSON array to restore authenticated login sessions without re-authentication. Requires userId for session isolation.
Instructions
Import cookies for authenticated sessions. Provide cookies in a JSON string array. Restores login sessions without re-auth. Requires userId.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| userId | Yes | User ID for session isolation | |
| cookies | Yes | JSON string of cookie array to import | |
| tabId | No | Tab ID to target correct session (needed when using presets) |
Implementation Reference
- src/client.ts:894-914 (handler)The actual cookie import handler in the CamofoxClient class. Sends cookies to the server via POST /sessions/{userId}/cookies, batching in chunks of 500 if needed.
async importCookies(userId: string, cookies: unknown[], tabId?: string): Promise<void> { const MAX_COOKIES_PER_REQUEST = 500; if (cookies.length <= MAX_COOKIES_PER_REQUEST) { await this.requestNoContent(`/sessions/${encodeURIComponent(userId)}/cookies`, { method: "POST", body: JSON.stringify({ cookies, ...(tabId && { tabId }) }), requireApiKey: true }); return; } for (let i = 0; i < cookies.length; i += MAX_COOKIES_PER_REQUEST) { const batch = cookies.slice(i, i + MAX_COOKIES_PER_REQUEST); await this.requestNoContent(`/sessions/${encodeURIComponent(userId)}/cookies`, { method: "POST", body: JSON.stringify({ cookies: batch, ...(tabId && { tabId }) }), requireApiKey: true }); } } - src/tools/session.ts:11-47 (handler)The MCP tool handler that registers 'import_cookies' tool. Parses input (userId, cookies as JSON string, optional tabId), validates cookies is an array, then delegates to client.importCookies().
export function registerSessionTools(server: McpServer, deps: ToolDeps): void { server.tool( "import_cookies", "Import cookies for authenticated sessions. Provide cookies in a JSON string array. Restores login sessions without re-auth. Requires userId.", { userId: z.string().min(1).describe("User ID for session isolation"), cookies: z.string().min(1).describe("JSON string of cookie array to import"), tabId: z.string().optional().describe("Tab ID to target correct session (needed when using presets)") }, async (input: unknown) => { try { const parsed = z .object({ userId: z.string().min(1).describe("User ID for session isolation"), cookies: z.string().min(1).describe("JSON string of cookie array to import"), tabId: z.string().optional().describe("Tab ID to target correct session (needed when using presets)") }) .parse(input); let cookies: unknown; try { cookies = JSON.parse(parsed.cookies); } catch { throw new AppError("VALIDATION_ERROR", "cookies must be a JSON array"); } if (!Array.isArray(cookies)) { throw new AppError("VALIDATION_ERROR", "cookies must be a JSON array"); } await deps.client.importCookies(parsed.userId, cookies, parsed.tabId); return okResult({ success: true }); } catch (error) { return toErrorResult(error); } } ); - src/server.ts:49-49 (registration)Registration of the session tools (including import_cookies) in the MCP server via registerSessionTools().
registerSessionTools(server, deps); - src/tools/session.ts:15-19 (schema)Input schema for import_cookies: userId (string), cookies (JSON string of cookie array), tabId (optional string).
{ userId: z.string().min(1).describe("User ID for session isolation"), cookies: z.string().min(1).describe("JSON string of cookie array to import"), tabId: z.string().optional().describe("Tab ID to target correct session (needed when using presets)") }, - src/client.ts:957-959 (helper)Helper method requestNoContent used by importCookies to make the POST request without expecting JSON response.
private async requestNoContent(path: string, init: RequestInit & { requireApiKey?: boolean }): Promise<void> { await this.request(path, init); }