list_channels
Retrieve all channels in a Discord server by providing the server ID. Use this tool to view channel names, types, and permissions for server management.
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)Handler function for the 'list_channels' tool. Fetches all channels from the specified Discord guild, maps them to an object with id, name, type, typeName, parentId, and position, filters out invalid channels, handles errors using withErrorHandling, and returns the JSON-formatted list or an error message.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:21-23 (schema)Input schema for 'list_channels' tool using Zod validation. Requires a single parameter: guildId (string, ID of the Discord server/guild).{ guildId: z.string().describe('The ID of the server (guild)'), },
- src/tools/channel-tools.ts:18-46 (registration)MCP server.tool registration for 'list_channels', including name, description, input schema, and inline handler function.server.tool( '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:54-54 (registration)Invocation of registerChannelTools(server) which registers the list_channels tool (among others) to the MCP server instance.registerChannelTools(server);