expand_query
Generate multiple expanded search queries from an initial input to diversify and deepen research results, enhancing web and academic search capabilities.
Instructions
Expand and rewrite search queries based on an up-to-date query expansion model. This tool takes an initial query and returns multiple expanded queries that can be used for more diversed and deeper searches. Useful for improving deep research results by searching broader and deeper.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | The search query to expand (e.g., 'machine learning', 'climate change') |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"query": {
"description": "The search query to expand (e.g., 'machine learning', 'climate change')",
"type": "string"
}
},
"required": [
"query"
],
"type": "object"
}
Implementation Reference
- src/tools/jina-tools.ts:240-286 (handler)The handler function for the 'expand_query' tool. It fetches expanded queries from the Jina query expansion API at 'https://svip.jina.ai/', processes the results, and returns them as text content items.async ({ query }: { query: string }) => { try { const props = getProps(); const tokenError = checkBearerToken(props.bearerToken); if (tokenError) { return tokenError; } const response = await fetch('https://svip.jina.ai/', { method: 'POST', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json', 'Authorization': `Bearer ${props.bearerToken}`, }, body: JSON.stringify({ q: query, query_expansion: true }), }); if (!response.ok) { return handleApiError(response, "Query expansion"); } const data = await response.json() as any; // Return each result as individual text items for consistency const contentItems: Array<{ type: 'text'; text: string }> = []; if (data.results && Array.isArray(data.results)) { for (const result of data.results) { contentItems.push({ type: "text" as const, text: result, }); } } return { content: contentItems, }; } catch (error) { return createErrorResponse(`Error: ${error instanceof Error ? error.message : String(error)}`); } },
- src/tools/jina-tools.ts:237-239 (schema)Zod input schema for the 'expand_query' tool, defining the required 'query' parameter.{ query: z.string().describe("The search query to expand (e.g., 'machine learning', 'climate change')") },
- src/tools/jina-tools.ts:234-287 (registration)Registration of the 'expand_query' tool using server.tool(), including name, description, input schema, and handler reference.server.tool( "expand_query", "Expand and rewrite search queries based on an up-to-date query expansion model. This tool takes an initial query and returns multiple expanded queries that can be used for more diversed and deeper searches. Useful for improving deep research results by searching broader and deeper.", { query: z.string().describe("The search query to expand (e.g., 'machine learning', 'climate change')") }, async ({ query }: { query: string }) => { try { const props = getProps(); const tokenError = checkBearerToken(props.bearerToken); if (tokenError) { return tokenError; } const response = await fetch('https://svip.jina.ai/', { method: 'POST', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json', 'Authorization': `Bearer ${props.bearerToken}`, }, body: JSON.stringify({ q: query, query_expansion: true }), }); if (!response.ok) { return handleApiError(response, "Query expansion"); } const data = await response.json() as any; // Return each result as individual text items for consistency const contentItems: Array<{ type: 'text'; text: string }> = []; if (data.results && Array.isArray(data.results)) { for (const result of data.results) { contentItems.push({ type: "text" as const, text: result, }); } } return { content: contentItems, }; } catch (error) { return createErrorResponse(`Error: ${error instanceof Error ? error.message : String(error)}`); } }, );