interceptor_browser_get_cookie
Retrieve a browser cookie's full value by its cookie_id, with an adjustable character limit to control output size.
Instructions
Get one cookie by cookie_id with full value (subject to a hard cap to keep output bounded).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| target_id | Yes | Target ID from interceptor_browser_launch or interceptor_camoufox_launch | |
| cookie_id | Yes | cookie_id from interceptor_browser_list_cookies | |
| value_max_chars | No | Max characters for cookie value (default: 20000) |
Implementation Reference
- src/tools/devtools.ts:332-368 (registration)Registration of the 'interceptor_browser_get_cookie' tool via server.tool() with schema and handler.
server.tool( "interceptor_browser_get_cookie", "Get one cookie by cookie_id with full value (subject to a hard cap to keep output bounded).", { target_id: z.string().describe("Target ID from interceptor_browser_launch or interceptor_camoufox_launch"), cookie_id: z.string().describe("cookie_id from interceptor_browser_list_cookies"), value_max_chars: z.number().optional().default(HARD_VALUE_CAP_CHARS) .describe(`Max characters for cookie value (default: ${HARD_VALUE_CAP_CHARS})`), }, async ({ target_id, cookie_id, value_max_chars }) => { try { const context = await getContextForTarget(target_id); const cookies = await context.cookies(); const found = cookies.find((c) => cookieStableId(c) === cookie_id) ?? null; if (!found) { return { content: [{ type: "text", text: JSON.stringify({ status: "error", error: `Cookie '${cookie_id}' not found. Re-run list tool.` }) }] }; } const capped = capValue(found.value, Math.max(0, Math.min(HARD_VALUE_CAP_CHARS, Math.trunc(value_max_chars ?? HARD_VALUE_CAP_CHARS)))); return { content: [{ type: "text", text: truncateResult({ status: "success", target_id, cookie_id, cookie: { ...found, value: capped.value }, value_length: capped.valueLength, value_truncated: capped.truncated, value_max_chars: capped.maxChars, }), }], }; } catch (e) { return { content: [{ type: "text", text: JSON.stringify({ status: "error", error: errorToString(e) }) }] }; } }, ); - src/tools/devtools.ts:341-367 (handler)Handler function for interceptor_browser_get_cookie: gets a BrowserContext for the target, retrieves all cookies, finds the one matching the cookie_id (using cookieStableId), caps its value, and returns it.
async ({ target_id, cookie_id, value_max_chars }) => { try { const context = await getContextForTarget(target_id); const cookies = await context.cookies(); const found = cookies.find((c) => cookieStableId(c) === cookie_id) ?? null; if (!found) { return { content: [{ type: "text", text: JSON.stringify({ status: "error", error: `Cookie '${cookie_id}' not found. Re-run list tool.` }) }] }; } const capped = capValue(found.value, Math.max(0, Math.min(HARD_VALUE_CAP_CHARS, Math.trunc(value_max_chars ?? HARD_VALUE_CAP_CHARS)))); return { content: [{ type: "text", text: truncateResult({ status: "success", target_id, cookie_id, cookie: { ...found, value: capped.value }, value_length: capped.valueLength, value_truncated: capped.truncated, value_max_chars: capped.maxChars, }), }], }; } catch (e) { return { content: [{ type: "text", text: JSON.stringify({ status: "error", error: errorToString(e) }) }] }; } }, - src/tools/devtools.ts:335-340 (schema)Input schema for interceptor_browser_get_cookie: target_id, cookie_id, and optional value_max_chars (defaults to HARD_VALUE_CAP_CHARS=20000).
{ target_id: z.string().describe("Target ID from interceptor_browser_launch or interceptor_camoufox_launch"), cookie_id: z.string().describe("cookie_id from interceptor_browser_list_cookies"), value_max_chars: z.number().optional().default(HARD_VALUE_CAP_CHARS) .describe(`Max characters for cookie value (default: ${HARD_VALUE_CAP_CHARS})`), }, - src/tools/devtools.ts:88-99 (helper)cookieStableId helper function used to generate a stable SHA1-based identifier for a cookie, used both in list_cookies (to return cookie_id) and get_cookie (to look up by cookie_id).
function cookieStableId(cookie: { name?: string; domain?: string; path?: string; secure?: boolean; httpOnly?: boolean; sameSite?: string; partitionKey?: string }): string { const parts = [ cookie.name ?? "", cookie.domain ?? "", cookie.path ?? "", String(!!cookie.secure), String(!!cookie.httpOnly), cookie.sameSite ?? "", cookie.partitionKey ?? "", ]; return `ck_${createHash("sha1").update(parts.join("|"), "utf8").digest("hex")}`; } - src/tools/devtools.ts:76-86 (helper)capValue helper function that truncates a string value to a maximum character count, appending '...' if truncated. Used to bound cookie values.
function capValue(value: string, maxChars: number): { value: string; valueLength: number; truncated: boolean; maxChars: number } { const valueLength = value.length; const effectiveMax = Math.max(0, Math.min(HARD_VALUE_CAP_CHARS, Math.trunc(maxChars))); if (effectiveMax === 0) { return { value, valueLength, truncated: false, maxChars: 0 }; } if (valueLength <= effectiveMax) { return { value, valueLength, truncated: false, maxChars: effectiveMax }; } return { value: value.slice(0, effectiveMax) + "...", valueLength, truncated: true, maxChars: effectiveMax }; }