load_profile
Load saved cookies from a profile into an active browser tab to restore login sessions without re-authentication. Use after creating a tab to apply saved state.
Instructions
Load a saved profile's cookies into an active browser tab. Restores login sessions without re-authentication. Use after create_tab to restore saved state.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| profileId | Yes | Profile name to load | |
| tabId | Yes | Tab ID to load cookies into |
Implementation Reference
- src/tools/profiles.ts:52-94 (handler)MCP tool handler for 'load_profile'. Parses input (profileId, tabId), loads profile from disk via loadProfile(), and imports cookies into the browser tab via client.importCookies(). Returns profile details or error.
server.tool( "load_profile", "Load a saved profile's cookies into an active browser tab. Restores login sessions without re-authentication. Use after create_tab to restore saved state.", { profileId: z.string().min(1).describe("Profile name to load"), tabId: z.string().min(1).describe("Tab ID to load cookies into") }, async (input: unknown) => { try { const parsed = z .object({ profileId: z.string().min(1), tabId: z.string().min(1) }) .parse(input); const tracked = getTrackedTab(parsed.tabId); incrementToolCall(parsed.tabId); // Read profile from disk const profile = await loadProfile(deps.config.profilesDir, parsed.profileId); const userMismatch = profile.userId !== tracked.userId; // Import cookies into the session await deps.client.importCookies(tracked.userId, profile.cookies, tracked.tabId); return okResult({ profileId: profile.profileId, cookieCount: profile.metadata.cookieCount, lastSaved: profile.metadata.updatedAt, description: profile.metadata.description, ...(userMismatch ? { warning: `Profile was saved for userId "${profile.userId}" but loaded into "${tracked.userId}"` } : {}) }); } catch (error) { return toErrorResult(error); } } ); - src/tools/profiles.ts:55-68 (schema)Input schema for load_profile: requires profileId (string, min 1 char) and tabId (string, min 1 char).
{ profileId: z.string().min(1).describe("Profile name to load"), tabId: z.string().min(1).describe("Tab ID to load cookies into") }, async (input: unknown) => { try { const parsed = z .object({ profileId: z.string().min(1), tabId: z.string().min(1) }) .parse(input); const tracked = getTrackedTab(parsed.tabId); - src/server.ts:51-51 (registration)Registration of all profile tools (including load_profile) in the MCP server via registerProfileTools().
registerProfileTools(server, deps); - src/profiles.ts:191-232 (helper)Core loadProfile() helper function. Validates profile ID, reads the JSON file from disk, parses and validates against ProfileSchema, checks profileId match, and returns the Profile object.
export async function loadProfile(dir: string, profileId: string): Promise<Profile> { validateProfileId(profileId); const filePath = profilePath(dir, profileId); let raw: string; try { raw = await readFile(filePath, "utf-8"); } catch (error) { const parsedError = ErrnoErrorSchema.safeParse(error); if (parsedError.success && parsedError.data.code === "ENOENT") { throw new AppError("PROFILE_NOT_FOUND", `Profile "${profileId}" not found`); } throw new AppError( "PROFILE_ERROR", `Failed to read profile "${profileId}": ${error instanceof Error ? error.message : String(error)}` ); } let json: unknown; try { json = JSON.parse(raw); } catch { throw new AppError("PROFILE_ERROR", `Profile "${profileId}" contains invalid JSON`); } const parsed = ProfileSchema.safeParse(json); if (!parsed.success) { throw new AppError( "PROFILE_ERROR", `Profile "${profileId}" has invalid format: ${parsed.error.issues.map((i) => i.message).join(", ")}` ); } if (parsed.data.profileId !== profileId) { throw new AppError( "PROFILE_ERROR", `Profile file mismatch: expected "${profileId}" but file contains "${parsed.data.profileId}"` ); } return parsed.data; } - src/profiles.ts:80-107 (schema)Zod schemas used for profile validation: ProfileCookieSchema, ProfileMetadataSchema, and ProfileSchema (version, profileId, userId, cookies, metadata).
const ProfileCookieSchema = z .object({ name: z.string(), value: z.string(), domain: z.string(), path: z.string(), expires: z.number().optional(), httpOnly: z.boolean().optional(), secure: z.boolean().optional(), sameSite: z.string().optional() }) .passthrough(); const ProfileMetadataSchema = z.object({ createdAt: z.string(), updatedAt: z.string(), lastUrl: z.string().optional().nullable(), description: z.string().optional().nullable(), cookieCount: z.number() }); const ProfileSchema = z.object({ version: z.literal(1), profileId: z.string(), userId: z.string(), cookies: z.array(ProfileCookieSchema), metadata: ProfileMetadataSchema });