expand_query
Generates multiple expanded search queries from an initial query to enable broader and deeper research by diversifying search terms and exploring related concepts.
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:234-287 (handler)Full implementation of the 'expand_query' tool handler: registers the tool with Zod schema, fetches expanded queries from Jina's svip.jina.ai API using POST with query_expansion: true, and returns array of expanded queries as text content items.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/tools/jina-tools.ts:238-239 (schema)Zod input schema for expand_query tool: requires a single 'query' string parameter.query: z.string().describe("The search query to expand (e.g., 'machine learning', 'climate change')") },
- src/tools/jina-tools.ts:235-287 (registration)Registration of the expand_query tool using server.tool() within registerJinaTools function."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-22 (registration)Calls registerJinaTools which registers the expand_query tool among others in the MCP server initialization.registerJinaTools(this.server, () => this.props); }