get_by_category
Retrieve knowledge base entries filtered by specific categories like 'ai', 'technology', or 'product' to access organized information efficiently.
Instructions
Get all knowledge base entries for a specific category
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| category | Yes | Category to filter by (e.g., 'ai', 'technology', 'product') |
Implementation Reference
- src/index.ts:313-369 (handler)Executes the get_by_category tool: extracts category from args, validates it, filters the knowledgeBase array case-insensitively, handles no-results case with available categories list, formats and returns JSON response with entries (id, content, metadata), caches successful results.if (name === "get_by_category") { const category = args?.category as string; if (!category) { throw new Error("Category parameter is required"); } const results = knowledgeBase.filter( (item) => item.category.toLowerCase() === category.toLowerCase() ); if (results.length === 0) { const responseText = JSON.stringify({ category, message: "No entries found for this category", availableCategories: [ ...new Set(knowledgeBase.map((item) => item.category)), ], }); // Don't cache errors return { content: [ { type: "text", text: responseText, }, ], }; } const responseText = JSON.stringify( { category, count: results.length, entries: results.map((r) => ({ id: r.id, content: r.content, metadata: r.metadata, })), }, null, 2 ); // Cache the response setCache(cacheKey, responseText); return { content: [ { type: "text", text: responseText, }, ], }; }
- src/index.ts:166-179 (registration)Registers the get_by_category tool in the tools list provided to MCP clients, including name, description, and input schema requiring a 'category' string.{ name: "get_by_category", description: "Get all knowledge base entries for a specific category", inputSchema: { type: "object", properties: { category: { type: "string", description: "Category to filter by (e.g., 'ai', 'technology', 'product')", }, }, required: ["category"], }, },
- src/index.ts:169-178 (schema)Input schema for get_by_category tool: object with required 'category' string property.inputSchema: { type: "object", properties: { category: { type: "string", description: "Category to filter by (e.g., 'ai', 'technology', 'product')", }, }, required: ["category"], },