search_with_bing
Search the web using Bing to find information, answer questions, or gather data through the Hyperbrowser platform.
Instructions
Search the web using Bing. This tool allows you to search the web using bing.com
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | The search query to submit to Bing | |
| sessionOptions | No | Options for the browser session. Avoid setting these if not mentioned explicitly | |
| numResults | No | Number of search results to return |
Implementation Reference
- src/tools/bing-search.ts:22-74 (handler)The handler function `bingSearchTool` that implements the core logic for searching Bing by scraping the search results page and extracting structured data.
export async function bingSearchTool( params: BingSearchToolParamSchemaType, extra: RequestHandlerExtra<ServerRequest, ServerNotification> ): Promise<CallToolResult> { const { query, numResults, sessionOptions } = params; let apiKey: string | undefined = undefined; if (extra.authInfo && extra.authInfo.extra?.isSSE) { apiKey = extra.authInfo.token; } try { const client = await getClient({ hbApiKey: apiKey }); 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: CallToolResult = { content: [ { type: "text", text: JSON.stringify(result.data, null, 2), }, ], isError: false, }; return response; } catch (error) { return { content: [{ type: "text", text: `${error}` }], isError: true, }; } } - src/tools/tool-types.ts:243-262 (schema)Input parameter schema definition for the Bing search tool using Zod, including query, numResults, and sessionOptions.
// Scrape Webpage export const bingSearchToolParamSchemaRaw = { query: z.string().describe("The search query to submit to Bing"), sessionOptions: sessionOptionsSchema, numResults: z .number() .int() .positive() .min(1) .max(50) .default(10) .describe("Number of search results to return"), }; export const bingSearchToolParamSchema = z.object(bingSearchToolParamSchemaRaw); export type BingSearchToolParamSchemaType = z.infer< typeof bingSearchToolParamSchema >; - src/transports/setup_server.ts:117-122 (registration)Registration of the 'search_with_bing' tool on the MCP server using server.tool with name, description, schema, and handler.
server.tool( bingSearchToolName, bingSearchToolDescription, bingSearchToolParamSchemaRaw, bingSearchTool ); - src/tools/bing-search.ts:12-21 (helper)Internal schema used for extracting structured search results from the Bing page.
const searchResultSchema = z.object({ title: z.string().describe("The title of the search result"), url: z.string().describe("The URL of the search result"), snippet: z.string().describe("The snippet of the search result"), }); const searchResultsSchema = z.object({ allSearchResults: z.array(searchResultSchema), });