discourse_list_categories
Retrieve all forum categories accessible to your current authentication level. This tool displays available discussion sections for browsing or posting.
Instructions
List categories visible to the current auth context.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- The core handler function that fetches and formats Discourse categories from the selected site using the client.getCached('/site.json') API call, returning a markdown-style list or an error message.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 }; } }
- Input schema definition using Zod: an empty strict object (no input parameters required).const schema = z.object({}).strict();
- src/tools/builtin/list_categories.ts:6-25 (registration)Registers the 'discourse_list_categories' tool with MCP server, including title, description, input schema, and inline handler function.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)Invocation of the registerListCategories function within the registerAllTools orchestration, passing server context and read-only options.registerListCategories(server, ctx, { allowWrites: false });