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
| Name | Required | Description | Default |
|---|---|---|---|
| guildId | Yes | The ID of the server (guild) |
Implementation Reference
- src/tools/invite-tools.ts:17-46 (handler)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) }] }; }
- src/tools/invite-tools.ts:14-16 (schema)Zod input schema defining the guildId parameter required for the list_invites tool.{ guildId: z.string().describe('The ID of the server (guild)'), },
- src/tools/invite-tools.ts:11-47 (registration)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);