get_categories
Retrieve categories or pages within a specific category from the Consumer Rights Wiki. Specify a category name to filter results or list all categories. Supports limits for controlled output.
Instructions
Get all categories or pages in a specific category
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| category | No | Category name (without Category: prefix). If empty, lists all categories. | |
| limit | No | Number of results to return (default: 20, max: 50) |
Implementation Reference
- src/index.ts:384-449 (handler)Handler function that executes the get_categories tool. It either lists all categories or members of a specific category using the wiki's API endpoints (allcategories or categorymembers).private async getCategories(args: any) { const { category, limit = 20 } = args; if (category) { // Get pages in a specific category const data = await this.makeApiRequest({ action: 'query', list: 'categorymembers', cmtitle: `Category:${category}`, cmlimit: Math.min(limit, 50).toString(), cmprop: 'ids|title|timestamp', }); if (data.error) { throw new McpError(ErrorCode.InternalError, data.error.info); } const members = data.query?.categorymembers || []; return { content: [ { type: 'text', text: JSON.stringify({ category: `Category:${category}`, members: members.map((member: any) => ({ title: member.title, pageid: member.pageid, timestamp: member.timestamp, url: `${WIKI_BASE_URL}/${member.title.replace(/ /g, '_')}`, })), }, null, 2), }, ], }; } else { // List all categories const data = await this.makeApiRequest({ action: 'query', list: 'allcategories', aclimit: Math.min(limit, 50).toString(), acprop: 'size', }); if (data.error) { throw new McpError(ErrorCode.InternalError, data.error.info); } const categories = data.query?.allcategories || []; return { content: [ { type: 'text', text: JSON.stringify({ categories: categories.map((cat: any) => ({ name: cat['*'], size: cat.size, url: `${WIKI_BASE_URL}/Category:${cat['*'].replace(/ /g, '_')}`, })), }, null, 2), }, ], }; } }
- src/index.ts:132-149 (registration)Tool registration in the ListToolsRequestHandler, including name, description, and input schema.{ name: 'get_categories', description: 'Get all categories or pages in a specific category', inputSchema: { type: 'object', properties: { category: { type: 'string', description: 'Category name (without Category: prefix). If empty, lists all categories.', }, limit: { type: 'number', description: 'Number of results to return (default: 20, max: 50)', default: 20, }, }, }, },
- src/index.ts:177-178 (registration)Dispatch case in CallToolRequestHandler that routes calls to the getCategories handler.case 'get_categories': return this.getCategories(request.params.arguments);