UNPKG

@mseep/hyperbrowser-mcp

Version:

Hyperbrowser Model Context Protocol Server

209 lines (208 loc) 8.55 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.listProfilesToolParamSchema = exports.listProfilesToolParamSchemaRaw = exports.deleteProfileToolParamSchema = exports.deleteProfileToolParamSchemaRaw = exports.bingSearchToolParamSchema = exports.bingSearchToolParamSchemaRaw = exports.claudeComputerUseToolParamSchema = exports.claudeComputerUseToolParamSchemaRaw = exports.oaiCuaToolParamSchema = exports.oaiCuaToolParamSchemaRaw = exports.browserUseToolParamSchema = exports.browserUseToolParamSchemaRaw = exports.crawlWebpagesToolParamSchema = exports.crawlWebpagesToolParamSchemaRaw = exports.extractStructuredDataToolParamSchema = exports.extractStructuredDataToolParamSchemaRaw = exports.scrapeWebpageToolParamSchema = exports.scrapeWebpageToolParamSchemaRaw = exports.sessionOptionsSchema = void 0; const zod_1 = require("zod"); const ajv_1 = require("ajv"); const ajv = new ajv_1.Ajv({ coerceTypes: true, useDefaults: true, }); exports.sessionOptionsSchema = zod_1.z .object({ useProxy: zod_1.z .boolean() .default(false) .describe("Whether to use a proxy. Recommended false."), useStealth: zod_1.z .boolean() .default(false) .describe("Whether to use stealth mode. Recommended false."), solveCaptchas: zod_1.z .boolean() .default(false) .describe("Whether to solve captchas. Recommended false."), acceptCookies: zod_1.z .boolean() .default(false) .describe("Whether to automatically close the accept cookies popup. Recommended false."), profile: zod_1.z .object({ id: zod_1.z .string() .optional() .describe("ID of the persistent profile to use for the session"), persistChanges: zod_1.z .boolean() .default(true) .describe("Whether changes made during the session should be saved to the profile. Recommended true."), }) .optional() .describe("Options for using a persistent Hyperbrowser profile"), }) .strict() // Ensure no unknown keys are passed .optional() .describe("Options for the browser session. Avoid setting these if not mentioned explicitly"); // Scrape Webpage exports.scrapeWebpageToolParamSchemaRaw = { url: zod_1.z.string().url().describe("The URL of the webpage to scrape"), sessionOptions: exports.sessionOptionsSchema, outputFormat: zod_1.z .array(zod_1.z.enum(["markdown", "html", "links", "screenshot"])) .min(1) .describe("The format of the output"), }; exports.scrapeWebpageToolParamSchema = zod_1.z.object(exports.scrapeWebpageToolParamSchemaRaw); // Extract Structured Data exports.extractStructuredDataToolParamSchemaRaw = { urls: zod_1.z .array(zod_1.z.string().url()) .describe("The list of URLs of the webpages to extract structured information from. Can include wildcards (e.g. https://example.com/*)"), prompt: zod_1.z.string().describe("The prompt to use for the extraction"), schema: zod_1.z .any({}) .transform((schema) => { if (!schema) { return false; } else { try { if (typeof schema === "string") { try { const parsedSchema = JSON.parse(schema); const validate = ajv.compile(parsedSchema); if (typeof validate === "function") { return parsedSchema; } else { return undefined; } } catch (err) { return undefined; } } else { const validate = ajv.compile(schema); if (typeof validate === "function") { return schema; } else { return undefined; } } } catch (err) { return false; } } }) .describe("The json schema to use for the extraction. Must provide an object describing a spec compliant json schema, any other types are invalid."), sessionOptions: exports.sessionOptionsSchema, }; exports.extractStructuredDataToolParamSchema = zod_1.z.object(exports.extractStructuredDataToolParamSchemaRaw); // Crawl Webpages exports.crawlWebpagesToolParamSchemaRaw = { url: zod_1.z.string().url().describe("The URL of the webpage to crawl."), sessionOptions: exports.sessionOptionsSchema, outputFormat: zod_1.z .array(zod_1.z.enum(["markdown", "html", "links", "screenshot"])) .min(1) .describe("The format of the output"), followLinks: zod_1.z .boolean() .describe("Whether to follow links on the crawled webpages"), maxPages: zod_1.z .number() .int() .positive() .finite() .safe() .min(1) .max(100) .default(10), ignoreSitemap: zod_1.z.boolean().default(false), }; exports.crawlWebpagesToolParamSchema = zod_1.z.object(exports.crawlWebpagesToolParamSchemaRaw); // Browser Use exports.browserUseToolParamSchemaRaw = { task: zod_1.z.string().describe("The task to perform inside the browser"), sessionOptions: exports.sessionOptionsSchema, returnStepInfo: zod_1.z .boolean() .default(false) .describe("Whether to return step-by-step information about the task.Should be false by default. May contain excessive information, so we strongly recommend setting this to false."), maxSteps: zod_1.z .number() .int() .positive() .finite() .safe() .min(1) .max(100) .default(25), }; exports.browserUseToolParamSchema = zod_1.z.object(exports.browserUseToolParamSchemaRaw); // OAI CUA exports.oaiCuaToolParamSchemaRaw = { task: zod_1.z.string().describe("The task to perform inside the browser"), sessionOptions: exports.sessionOptionsSchema, returnStepInfo: zod_1.z .boolean() .default(false) .describe("Whether to return step-by-step information about the task.Should be false by default. May contain excessive information, so we strongly recommend setting this to false."), maxSteps: zod_1.z .number() .int() .positive() .finite() .safe() .min(1) .max(100) .default(25), }; exports.oaiCuaToolParamSchema = zod_1.z.object(exports.oaiCuaToolParamSchemaRaw); // Claude Computer Use exports.claudeComputerUseToolParamSchemaRaw = { task: zod_1.z.string().describe("The task to perform inside the browser"), sessionOptions: exports.sessionOptionsSchema, returnStepInfo: zod_1.z .boolean() .default(false) .describe("Whether to return step-by-step information about the task.Should be false by default. May contain excessive information, so we strongly recommend setting this to false."), maxSteps: zod_1.z .number() .int() .positive() .finite() .safe() .min(1) .max(100) .default(25), }; exports.claudeComputerUseToolParamSchema = zod_1.z.object(exports.claudeComputerUseToolParamSchemaRaw); // Bing search // Scrape Webpage exports.bingSearchToolParamSchemaRaw = { query: zod_1.z.string().describe("The search query to submit to Bing"), sessionOptions: exports.sessionOptionsSchema, numResults: zod_1.z .number() .int() .positive() .min(1) .max(50) .default(10) .describe("Number of search results to return"), }; exports.bingSearchToolParamSchema = zod_1.z.object(exports.bingSearchToolParamSchemaRaw); // Delete Profile exports.deleteProfileToolParamSchemaRaw = { profileId: zod_1.z.string().describe("ID of the profile to delete"), }; exports.deleteProfileToolParamSchema = zod_1.z.object(exports.deleteProfileToolParamSchemaRaw); // List Profiles exports.listProfilesToolParamSchemaRaw = { page: zod_1.z.number().int().positive().optional().describe("Page number for pagination (optional)"), limit: zod_1.z.number().int().positive().optional().describe("Number of profiles per page (optional)"), }; exports.listProfilesToolParamSchema = zod_1.z.object(exports.listProfilesToolParamSchemaRaw);