UNPKG

@mseep/hyperbrowser-mcp

Version:

Hyperbrowser Model Context Protocol Server

56 lines (55 loc) 2.04 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.bingSearchToolDescription = exports.bingSearchToolName = exports.bingSearchTool = void 0; const zod_1 = require("zod"); const utils_1 = require("../utils"); const searchResultSchema = zod_1.z.object({ title: zod_1.z.string().describe("The title of the search result"), url: zod_1.z.string().describe("The URL of the search result"), snippet: zod_1.z.string().describe("The snippet of the search result"), }); const searchResultsSchema = zod_1.z.object({ allSearchResults: zod_1.z.array(searchResultSchema), }); async function bingSearchTool({ query, numResults, sessionOptions, }) { try { const client = await (0, utils_1.getClient)(); const encodedUrl = encodeURI(`https://www.bing.com/search?q=${query}`); const result = await client.extract.startAndWait({ urls: [encodedUrl], sessionOptions: { ...sessionOptions, adblock: true, useProxy: false }, prompt: `Extract the top ${numResults} search results from this page.`, schema: searchResultsSchema, }); if (result.error) { return { isError: true, content: [ { type: "text", text: result.error, }, ], }; } const response = { content: [ { type: "text", text: JSON.stringify(result.data, null, 2), }, ], isError: false, }; return response; } catch (error) { return { content: [{ type: "text", text: `${error}` }], isError: true, }; } } exports.bingSearchTool = bingSearchTool; exports.bingSearchToolName = "search_with_bing"; exports.bingSearchToolDescription = "Search the web using Bing. This tool allows you to search the web using bing.com";