expand_query
Generate multiple expanded search queries from an initial input to explore broader and deeper research results, improving search effectiveness and diversity.
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
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | The search query to expand (e.g., 'machine learning', 'climate change') |
Implementation Reference
- src/tools/jina-tools.ts:313-359 (handler)Handler function that executes the expand_query tool: fetches expanded queries from Jina's query expansion API at https://svip.jina.ai/ using POST with query and query_expansion=true, processes results into 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:311-312 (schema)Input schema using Zod: single string parameter 'query' for the search query to expand.query: z.string().describe("The search query to expand (e.g., 'machine learning', 'climate change')") },
- src/tools/jina-tools.ts:307-360 (registration)Registration of the expand_query tool within registerJinaTools function using McpServer.tool(name, description, inputSchema, handler). Called from src/index.ts.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)}`); } }, );
- src/index.ts:21-21 (registration)Invocation of registerJinaTools in MyMCP.init(), which registers all tools including expand_query.registerJinaTools(this.server, () => this.props);
- src/index.ts:137-137 (registration)Documentation listing of the expand_query tool in the root endpoint response."expand_query - Expand and rewrite search queries based on the query expansion model",