Skip to main content
Glama
scarecr0w12

discord-mcp

list_servers

Retrieve all Discord servers where the bot is a member. Use this tool to view accessible guilds for management tasks.

Instructions

List all Discord servers (guilds) the bot has access to

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The handler function for the 'list_servers' tool. It uses the Discord client to fetch all guilds (servers) the bot is in, extracts basic information (id, name, memberCount, ownerId, icon), handles errors with withErrorHandling, and returns the list as a formatted JSON string.
    async () => {
      const result = await withErrorHandling(async () => {
        const client = await getDiscordClient();
        const guilds = client.guilds.cache.map((guild) => ({
          id: guild.id,
          name: guild.name,
          memberCount: guild.memberCount,
          ownerId: guild.ownerId,
          icon: guild.iconURL(),
        }));
        return guilds;
      });
    
      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_servers' tool: empty object, indicating no input parameters are required.
    {},
  • Direct registration of the 'list_servers' tool on the MCP server within the registerServerTools function, including name, description, schema, and handler.
    server.tool(
      'list_servers',
      'List all Discord servers (guilds) the bot has access to',
      {},
      async () => {
        const result = await withErrorHandling(async () => {
          const client = await getDiscordClient();
          const guilds = client.guilds.cache.map((guild) => ({
            id: guild.id,
            name: guild.name,
            memberCount: guild.memberCount,
            ownerId: guild.ownerId,
            icon: guild.iconURL(),
          }));
          return guilds;
        });
    
        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 registerServerTools to register the server tools module (including 'list_servers') on the main MCP server instance.
    registerServerTools(server);

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