list_channels
Retrieve all channels in a Discord server by providing the server ID to manage and organize your community spaces.
Instructions
List all channels in a Discord server
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| guildId | Yes | The ID of the server (guild) |
Implementation Reference
- src/tools/channel-tools.ts:24-45 (handler)The handler function that executes the tool logic: fetches Discord client, retrieves guild by ID, fetches all channels, maps to structured data (id, name, type, parentId, position), filters valid channels, handles errors with withErrorHandling, and returns JSON-formatted response.async ({ guildId }) => { const result = await withErrorHandling(async () => { const client = await getDiscordClient(); const guild = await client.guilds.fetch(guildId); const channels = await guild.channels.fetch(); return channels.map((ch) => ({ id: ch?.id, name: ch?.name, type: ch?.type, typeName: ChannelType[ch?.type ?? 0], parentId: (ch as GuildChannel)?.parentId, position: (ch as GuildChannel)?.position, })).filter((ch) => ch.id); }); if (!result.success) { return { content: [{ type: 'text', text: result.error }], isError: true }; } return { content: [{ type: 'text', text: JSON.stringify(result.data, null, 2) }] }; }
- src/tools/channel-tools.ts:22-23 (schema)Zod input schema defining the required 'guildId' parameter as a string.guildId: z.string().describe('The ID of the server (guild)'), },
- src/tools/channel-tools.ts:19-46 (registration)Tool registration using McpServer.tool() method, specifying name 'list_channels', description, input schema, and inline handler function.'list_channels', 'List all channels in a Discord server', { guildId: z.string().describe('The ID of the server (guild)'), }, async ({ guildId }) => { const result = await withErrorHandling(async () => { const client = await getDiscordClient(); const guild = await client.guilds.fetch(guildId); const channels = await guild.channels.fetch(); return channels.map((ch) => ({ id: ch?.id, name: ch?.name, type: ch?.type, typeName: ChannelType[ch?.type ?? 0], parentId: (ch as GuildChannel)?.parentId, position: (ch as GuildChannel)?.position, })).filter((ch) => ch.id); }); if (!result.success) { return { content: [{ type: 'text', text: result.error }], isError: true }; } return { content: [{ type: 'text', text: JSON.stringify(result.data, null, 2) }] }; } );
- src/index.ts:55-55 (registration)Call to registerChannelTools function which registers the list_channels tool (and other channel tools) on the MCP server instance.registerChannelTools(server);