get-category-members
Retrieve page IDs, namespaces, and titles for all members in a MediaWiki category, with filtering options for file types, pages, and subcategories.
Instructions
Gets all members in the category. Returns only page IDs, namespaces, and titles.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| category | Yes | Category name | |
| types | No | Types of members to include | |
| namespaces | No | Namespace IDs to filter by |
Implementation Reference
- src/tools/get-category-members.ts:36-70 (handler)The main handler function that fetches category members using the mwn library, applies filters, handles errors, and maps results using the helper.async function handleGetCategoryMembersTool( category: string, types?: CategoryMemberType[], namespaces?: number[] ): Promise< CallToolResult > { let data: ApiPageInfo[]; try { const mwn = await getMwn(); const mwnCategory = new mwn.Category( category ); const options: ApiQueryCategoryMembersParams = {}; if ( types ) { options.cmtype = types; } if ( namespaces ) { options.cmnamespace = namespaces; } data = await mwnCategory.members( options ); } catch ( error ) { return { content: [ { type: 'text', text: `Get category members failed: ${ ( error as Error ).message }` } as TextContent ], isError: true }; } return { content: data.map( getCategoryMembersToolResult ) }; }
- src/tools/get-category-members.ts:16-34 (registration)Tool registrar function that calls server.tool() to register 'get-category-members' with description, input schema using Zod, annotations, and references the handler.export function getCategoryMembersTool( server: McpServer ): RegisteredTool { return server.tool( 'get-category-members', 'Gets all members in the category. Returns only page IDs, namespaces, and titles.', { category: z.string().describe( 'Category name' ), types: z.array( z.nativeEnum( CategoryMemberType ) ).optional().describe( 'Types of members to include' ), namespaces: z.array( z.number().int().nonnegative() ).optional().describe( 'Namespace IDs to filter by' ) }, { title: 'Get category members', readOnlyHint: true, destructiveHint: false } as ToolAnnotations, async ( { category, types, namespaces } ) => handleGetCategoryMembersTool( category, types, namespaces ) ); }
- Helper function that formats a single category member (ApiPageInfo) into a structured TextContent block for the tool response.function getCategoryMembersToolResult( result: ApiPageInfo ): TextContent { return { type: 'text', text: [ `Page ID: ${ result.pageid }`, `Namespace: ${ result.ns }`, `Title: ${ result.title }` ].join( '\n' ) }; }
- Enum used in the input schema to specify types of category members (file, page, subcat).enum CategoryMemberType { file = 'file', page = 'page', subcat = 'subcat' }
- src/tools/index.ts:19-37 (registration)Imports the tool registrar and adds it to the list of tool registrars called by registerAllTools(server).import { getCategoryMembersTool } from './get-category-members.js'; import { searchPageByPrefixTool } from './search-page-by-prefix.js'; const toolRegistrars = [ getPageTool, getPageHistoryTool, searchPageTool, setWikiTool, addWikiTool, removeWikiTool, updatePageTool, getFileTool, createPageTool, uploadFileTool, uploadFileFromUrlTool, deletePageTool, getRevisionTool, undeletePageTool, getCategoryMembersTool,