search_web
Search the web using Jina AI's API to find information, extract content, and retrieve web data in multiple formats for analysis.
Instructions
Search the web using Jina AI's search API
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | ||
| count | No | ||
| retain_images | No | none | |
| with_generated_alt | No | ||
| return_format | No | markdown |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"count": {
"default": 5,
"type": "number"
},
"query": {
"type": "string"
},
"retain_images": {
"default": "none",
"enum": [
"none",
"all"
],
"type": "string"
},
"return_format": {
"default": "markdown",
"enum": [
"markdown",
"text",
"html"
],
"type": "string"
},
"with_generated_alt": {
"default": true,
"type": "boolean"
}
},
"required": [
"query"
],
"type": "object"
}
Implementation Reference
- index.ts:65-87 (handler)The `searchWeb` function that executes the core logic of the 'search_web' tool by querying Jina AI's search API and parsing the response.async function searchWeb(params: z.infer<typeof SearchWebSchema>) { const headers: Record<string, string> = { 'Authorization': `Bearer ${JINA_API_KEY}`, 'Accept': 'application/json', 'X-Retain-Images': params.retain_images, 'X-With-Generated-Alt': params.with_generated_alt.toString(), 'X-Return-Format': params.return_format }; const queryString = encodeURIComponent(params.query); const url = `https://s.jina.ai/${queryString}?count=${params.count}`; const response = await fetch(url, { method: 'GET', headers, }); if (!response.ok) { throw new Error(`Jina AI Search API error: ${response.statusText}`); } return SearchResponseSchema.parse(await response.json()); }
- schemas.ts:44-50 (schema)Zod schema defining the input parameters for the 'search_web' tool.export const SearchWebSchema = z.object({ query: z.string(), count: z.number().optional().default(5), retain_images: z.enum(['none', 'all']).optional().default('none'), with_generated_alt: z.boolean().optional().default(true), return_format: z.enum(['markdown', 'text', 'html']).optional().default('markdown') });
- index.ts:118-122 (registration)Registration of the 'search_web' tool in the ListTools handler, providing name, description, and input schema.{ name: "search_web", description: "Search the web using Jina AI's search API", inputSchema: zodToJsonSchema(SearchWebSchema) },
- index.ts:145-149 (registration)Dispatch handler in the CallToolRequestSchema that parses arguments, calls searchWeb, and formats the response.case "search_web": { const args = SearchWebSchema.parse(request.params.arguments); const result = await searchWeb(args); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] }; }
- schemas.ts:52-66 (schema)Zod schema for parsing the output response from Jina AI's search API.export const SearchResponseSchema = z.object({ code: z.number(), status: z.number(), data: z.array(z.object({ title: z.string(), description: z.string().optional(), url: z.string(), content: z.string(), images: z.record(z.string()).optional(), links: z.record(z.string()).optional(), usage: z.object({ tokens: z.number() }) })) });