get_channel_permissions
Retrieve all permission overwrites for a Discord channel to manage access controls and role-based permissions within a server.
Instructions
Get all permission overwrites for a channel
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| guildId | Yes | The ID of the server (guild) | |
| channelId | Yes | The ID of the channel |
Implementation Reference
- src/tools/permission-tools.ts:16-61 (handler)The handler function that implements the core logic of fetching channel permission overwrites, resolving names for roles/members, and returning formatted JSON.async ({ guildId, channelId }) => { const result = await withErrorHandling(async () => { const client = await getDiscordClient(); const guild = await client.guilds.fetch(guildId); const channel = await guild.channels.fetch(channelId); if (!channel) throw new Error('Channel not found'); const overwrites = (channel as GuildChannel).permissionOverwrites.cache.map((overwrite) => ({ id: overwrite.id, type: overwrite.type === OverwriteType.Role ? 'role' : 'member', allow: overwrite.allow.toArray(), deny: overwrite.deny.toArray(), })); // Get role/member names for context const resolvedOverwrites = await Promise.all( overwrites.map(async (ow) => { let name = 'Unknown'; if (ow.type === 'role') { const role = await guild.roles.fetch(ow.id); name = role?.name ?? 'Unknown Role'; } else { try { const member = await guild.members.fetch(ow.id); name = member.displayName; } catch { name = 'Unknown Member'; } } return { ...ow, name }; }) ); return { channelId, channelName: channel.name, overwrites: resolvedOverwrites, }; }); 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/permission-tools.ts:12-15 (schema)Input schema using Zod for validating guildId and channelId parameters.{ guildId: z.string().describe('The ID of the server (guild)'), channelId: z.string().describe('The ID of the channel'), },
- src/tools/permission-tools.ts:9-62 (registration)Registration of the 'get_channel_permissions' tool on the MCP server, including name, description, schema, and handler.server.tool( 'get_channel_permissions', 'Get all permission overwrites for a channel', { guildId: z.string().describe('The ID of the server (guild)'), channelId: z.string().describe('The ID of the channel'), }, async ({ guildId, channelId }) => { const result = await withErrorHandling(async () => { const client = await getDiscordClient(); const guild = await client.guilds.fetch(guildId); const channel = await guild.channels.fetch(channelId); if (!channel) throw new Error('Channel not found'); const overwrites = (channel as GuildChannel).permissionOverwrites.cache.map((overwrite) => ({ id: overwrite.id, type: overwrite.type === OverwriteType.Role ? 'role' : 'member', allow: overwrite.allow.toArray(), deny: overwrite.deny.toArray(), })); // Get role/member names for context const resolvedOverwrites = await Promise.all( overwrites.map(async (ow) => { let name = 'Unknown'; if (ow.type === 'role') { const role = await guild.roles.fetch(ow.id); name = role?.name ?? 'Unknown Role'; } else { try { const member = await guild.members.fetch(ow.id); name = member.displayName; } catch { name = 'Unknown Member'; } } return { ...ow, name }; }) ); return { channelId, channelName: channel.name, overwrites: resolvedOverwrites, }; }); if (!result.success) { return { content: [{ type: 'text', text: result.error }], isError: true }; } return { content: [{ type: 'text', text: JSON.stringify(result.data, null, 2) }] }; } );