advanced_search
Search a knowledge base with filters for category and result limits to find specific information quickly.
Instructions
Search with additional filters like category and result limit
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"query": "<query>"
},
"name": "advanced_search"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | Search query | |
| category | No | Optional: filter by category | |
| limit | No | Maximum results to return |
Implementation Reference
- src/index.ts:198-220 (registration)Registration of the 'advanced_search' tool including its name, description, and input schema.
{ name: "advanced_search", description: "Search with additional filters like category and result limit", inputSchema: { type: "object", properties: { query: { type: "string", description: "Search query", }, category: { type: "string", description: "Optional: filter by category", }, limit: { type: "number", description: "Maximum results to return", default: 5, }, }, required: ["query"], }, }, - src/index.ts:423-474 (handler)Handler function for executing the 'advanced_search' tool. It searches the knowledge base, applies optional category filter and limit, formats results as JSON, caches the response, and returns it.
if (name === "advanced_search") { const query = args?.query as string; const category = args?.category as string | undefined; const limit = (args?.limit as number) || 5; if (!query) { throw new Error("Query parameter is required"); } let results = searchKnowledge(query, knowledgeBase.length); // Apply category filter if provided if (category) { results = results.filter( (item) => item.category.toLowerCase() === category.toLowerCase() ); } // Apply limit results = results.slice(0, limit); const responseText = JSON.stringify( { query, filters: { category: category || "none", limit, }, resultsCount: results.length, results: results.map((r) => ({ id: r.id, content: r.content, category: r.category, metadata: r.metadata, })), }, null, 2 ); // Cache the response setCache(cacheKey, responseText); return { content: [ { type: "text", text: responseText, }, ], }; } - src/index.ts:111-119 (helper)Helper function used by advanced_search to perform initial keyword search on the knowledge base.
function searchKnowledge(query: string, limit: number = 5): KnowledgeEntry[] { const lowerQuery = query.toLowerCase(); return knowledgeBase .filter((item) => item.content.toLowerCase().includes(lowerQuery) || item.category.toLowerCase().includes(lowerQuery) ) .slice(0, limit); } - src/index.ts:14-22 (helper)Type definition for knowledge base entries used in advanced_search results.
interface KnowledgeEntry { id: string; content: string; category: string; metadata: { source: string; date: string; }; }