Skip to main content
Glama
scarecr0w12

discord-mcp

list_roles

Retrieve all role names and IDs from a Discord server using the server's guild ID to manage permissions and member assignments.

Instructions

List all roles in a Discord server

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
guildIdYesThe ID of the server (guild)

Implementation Reference

  • Executes the list_roles tool: fetches Discord guild roles using discord.js, extracts key properties (id, name, color, position, hoist, mentionable, managed, permissions array, member count), sorts by descending position, handles errors with withErrorHandling, and returns JSON-formatted list or error.
      async ({ guildId }) => {
        const result = await withErrorHandling(async () => {
          const client = await getDiscordClient();
          const guild = await client.guilds.fetch(guildId);
          const roles = await guild.roles.fetch();
    
          return roles.map((role) => ({
            id: role.id,
            name: role.name,
            color: role.hexColor,
            position: role.position,
            hoist: role.hoist,
            mentionable: role.mentionable,
            managed: role.managed,
            permissions: role.permissions.toArray(),
            memberCount: role.members.size,
          })).sort((a, b) => b.position - a.position);
        });
    
        if (!result.success) {
          return { content: [{ type: 'text', text: result.error }], isError: true };
        }
    
        return { content: [{ type: 'text', text: JSON.stringify(result.data, null, 2) }] };
      }
    );
  • Input schema for list_roles tool: requires 'guildId' as a string, described as the ID of the server (guild). Uses Zod for validation.
    {
      guildId: z.string().describe('The ID of the server (guild)'),
    },
  • Registers the 'list_roles' tool on the MCP server with name, description, input schema (guildId), and inline handler function.
    server.tool(
      'list_roles',
      'List all roles 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 roles = await guild.roles.fetch();
    
          return roles.map((role) => ({
            id: role.id,
            name: role.name,
            color: role.hexColor,
            position: role.position,
            hoist: role.hoist,
            mentionable: role.mentionable,
            managed: role.managed,
            permissions: role.permissions.toArray(),
            memberCount: role.members.size,
          })).sort((a, b) => b.position - a.position);
        });
    
        if (!result.success) {
          return { content: [{ type: 'text', text: result.error }], isError: true };
        }
    
        return { content: [{ type: 'text', text: JSON.stringify(result.data, null, 2) }] };
      }
    );
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden for behavioral disclosure. It states it's a list operation, implying read-only behavior, but doesn't mention whether it requires specific permissions, returns paginated results, includes default roles, or provides any metadata about the roles beyond their names/IDs.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that directly states the tool's purpose with zero wasted words. It's appropriately sized for a simple list operation and front-loads the essential information.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a simple read operation with one well-documented parameter and no output schema, the description is minimally adequate. However, without annotations or output schema, it should ideally mention what information is returned (e.g., role names, IDs, permissions) to help the agent understand the result structure.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 100% description coverage, with the single parameter 'guildId' clearly documented as 'The ID of the server (guild)'. The description doesn't add any additional semantic context beyond what's in the schema, so the baseline score of 3 is appropriate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('List all roles') and the target resource ('in a Discord server'), providing a specific verb+resource combination. However, it doesn't explicitly differentiate from sibling tools like 'get_role_info' or 'list_permissions', which prevents a perfect score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like 'get_role_info' (for a single role) or 'list_permissions' (which might include role-based permissions). There's no mention of prerequisites, context, or exclusions.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/scarecr0w12/discord-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server