Skip to main content
Glama
scarecr0w12

discord-mcp

list_invites

Retrieve all active invitation links for a Discord server to manage access and monitor invite usage.

Instructions

List all invites in a server

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
guildIdYesThe ID of the server (guild)

Implementation Reference

  • Handler function that executes the list_invites tool: fetches all invites for the given guild using Discord.js, maps them to a structured format, handles errors with withErrorHandling, and returns JSON string.
    async ({ guildId }) => {
      const result = await withErrorHandling(async () => {
        const client = await getDiscordClient();
        const guild = await client.guilds.fetch(guildId);
        const invites = await guild.invites.fetch();
    
        return invites.map((invite) => ({
          code: invite.code,
          url: invite.url,
          channelId: invite.channelId,
          channelName: invite.channel?.name,
          inviterId: invite.inviterId,
          inviterUsername: invite.inviter?.username,
          uses: invite.uses,
          maxUses: invite.maxUses,
          maxAge: invite.maxAge,
          temporary: invite.temporary,
          createdAt: invite.createdAt?.toISOString(),
          expiresAt: invite.expiresAt?.toISOString(),
          targetType: invite.targetType,
          targetUserId: invite.targetUser?.id,
        }));
      });
    
      if (!result.success) {
        return { content: [{ type: 'text', text: result.error }], isError: true };
      }
    
      return { content: [{ type: 'text', text: JSON.stringify(result.data, null, 2) }] };
    }
  • Zod input schema defining the guildId parameter required for the list_invites tool.
    {
      guildId: z.string().describe('The ID of the server (guild)'),
    },
  • Direct registration of the list_invites tool on the MCP server within the registerInviteTools function.
    server.tool(
      'list_invites',
      'List all invites in a 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 invites = await guild.invites.fetch();
    
          return invites.map((invite) => ({
            code: invite.code,
            url: invite.url,
            channelId: invite.channelId,
            channelName: invite.channel?.name,
            inviterId: invite.inviterId,
            inviterUsername: invite.inviter?.username,
            uses: invite.uses,
            maxUses: invite.maxUses,
            maxAge: invite.maxAge,
            temporary: invite.temporary,
            createdAt: invite.createdAt?.toISOString(),
            expiresAt: invite.expiresAt?.toISOString(),
            targetType: invite.targetType,
            targetUserId: invite.targetUser?.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:62-62 (registration)
    Invocation of registerInviteTools in the main MCP server creation, which registers the list_invites tool among others.
    registerInviteTools(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