discourse_list_categories
Retrieve all forum categories accessible to your current authentication level within Discourse platforms.
Instructions
List categories visible to the current auth context.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- Handler function that lists Discourse categories by fetching /site.json via the site client, formatting category names and topic counts into a markdown list, and returning as text blocks. Includes error handling.async (_args, _extra: any) => { try { const { client } = ctx.siteState.ensureSelectedSite(); const data = (await client.getCached(`/site.json`, 30000)) as any; const cats: any[] = data?.categories || []; const lines = cats.map((c) => `- ${c.name} (${c.topic_count ?? 0} topics)`); const text = lines.length ? lines.join("\n") : "No categories found."; return { content: [{ type: "text", text }] }; } catch (e: any) { return { content: [{ type: "text", text: `Failed to list categories: ${e?.message || String(e)}` }], isError: true }; } }
- Zod schema for tool input: empty object (no parameters required).const schema = z.object({}).strict();
- src/tools/builtin/list_categories.ts:4-26 (registration)Exports registerListCategories function which defines the tool schema, metadata, and registers the handler with the MCP server.export const registerListCategories: RegisterFn = (server, ctx) => { const schema = z.object({}).strict(); server.registerTool( "discourse_list_categories", { title: "List Categories", description: "List categories visible to the current auth context.", inputSchema: schema.shape, }, async (_args, _extra: any) => { try { const { client } = ctx.siteState.ensureSelectedSite(); const data = (await client.getCached(`/site.json`, 30000)) as any; const cats: any[] = data?.categories || []; const lines = cats.map((c) => `- ${c.name} (${c.topic_count ?? 0} topics)`); const text = lines.length ? lines.join("\n") : "No categories found."; return { content: [{ type: "text", text }] }; } catch (e: any) { return { content: [{ type: "text", text: `Failed to list categories: ${e?.message || String(e)}` }], isError: true }; } } ); };
- src/tools/registry.ts:53-53 (registration)Top-level call to register the discourse_list_categories tool during MCP tools initialization in the registry.registerListCategories(server, ctx, { allowWrites: false });