Skip to main content
Glama
scarecr0w12

discord-mcp

get_audit_logs

Retrieve and filter Discord server audit logs by user, action type, or timeframe to monitor administrative activities and track changes.

Instructions

Get audit logs from a server

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
guildIdYesThe ID of the server (guild)
limitNoNumber of entries to fetch (1-100, default 50)
userIdNoFilter by user who performed action
actionTypeNoFilter by action type (e.g., MEMBER_BAN_ADD, CHANNEL_CREATE)
beforeNoGet entries before this audit log entry ID

Implementation Reference

  • The handler function that implements the core logic for fetching, filtering, formatting, and returning Discord audit logs as JSON.
    async ({ guildId, limit = 50, userId, actionType, before }) => {
      const result = await withErrorHandling(async () => {
        const client = await getDiscordClient();
        const guild = await client.guilds.fetch(guildId);
    
        const fetchOptions: { limit: number; user?: string; type?: AuditLogEvent; before?: string } = {
          limit: Math.min(Math.max(1, limit), 100),
        };
        if (userId) fetchOptions.user = userId;
        if (before) fetchOptions.before = before;
        if (actionType) {
          const eventType = AuditLogEvent[actionType as keyof typeof AuditLogEvent];
          if (eventType !== undefined) fetchOptions.type = eventType;
        }
    
        const auditLogs = await guild.fetchAuditLogs(fetchOptions);
    
        return auditLogs.entries.map((entry) => ({
          id: entry.id,
          action: AuditLogEvent[entry.action],
          actionType: entry.actionType,
          targetType: entry.targetType,
          targetId: entry.targetId,
          executorId: entry.executorId,
          executor: entry.executor ? {
            id: entry.executor.id,
            username: entry.executor.username,
          } : null,
          reason: entry.reason,
          createdAt: entry.createdAt.toISOString(),
          changes: entry.changes.map((change) => ({
            key: change.key,
            old: change.old,
            new: change.new,
          })),
          extra: entry.extra,
        }));
      });
    
      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 using Zod for validating parameters: guildId (required), limit, userId, actionType, before (optional).
    {
      guildId: z.string().describe('The ID of the server (guild)'),
      limit: z.number().optional().describe('Number of entries to fetch (1-100, default 50)'),
      userId: z.string().optional().describe('Filter by user who performed action'),
      actionType: z.string().optional().describe('Filter by action type (e.g., MEMBER_BAN_ADD, CHANNEL_CREATE)'),
      before: z.string().optional().describe('Get entries before this audit log entry ID'),
    },
  • Registers the 'get_audit_logs' tool on the MCP server with name, description, input schema, and handler function.
      'get_audit_logs',
      'Get audit logs from a server',
      {
        guildId: z.string().describe('The ID of the server (guild)'),
        limit: z.number().optional().describe('Number of entries to fetch (1-100, default 50)'),
        userId: z.string().optional().describe('Filter by user who performed action'),
        actionType: z.string().optional().describe('Filter by action type (e.g., MEMBER_BAN_ADD, CHANNEL_CREATE)'),
        before: z.string().optional().describe('Get entries before this audit log entry ID'),
      },
      async ({ guildId, limit = 50, userId, actionType, before }) => {
        const result = await withErrorHandling(async () => {
          const client = await getDiscordClient();
          const guild = await client.guilds.fetch(guildId);
    
          const fetchOptions: { limit: number; user?: string; type?: AuditLogEvent; before?: string } = {
            limit: Math.min(Math.max(1, limit), 100),
          };
          if (userId) fetchOptions.user = userId;
          if (before) fetchOptions.before = before;
          if (actionType) {
            const eventType = AuditLogEvent[actionType as keyof typeof AuditLogEvent];
            if (eventType !== undefined) fetchOptions.type = eventType;
          }
    
          const auditLogs = await guild.fetchAuditLogs(fetchOptions);
    
          return auditLogs.entries.map((entry) => ({
            id: entry.id,
            action: AuditLogEvent[entry.action],
            actionType: entry.actionType,
            targetType: entry.targetType,
            targetId: entry.targetId,
            executorId: entry.executorId,
            executor: entry.executor ? {
              id: entry.executor.id,
              username: entry.executor.username,
            } : null,
            reason: entry.reason,
            createdAt: entry.createdAt.toISOString(),
            changes: entry.changes.map((change) => ({
              key: change.key,
              old: change.old,
              new: change.new,
            })),
            extra: entry.extra,
          }));
        });
    
        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:65-65 (registration)
    Top-level call to register all audit tools, including get_audit_logs, on the MCP server instance.
    registerAuditTools(server);
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 'gets' logs (implying a read operation) but doesn't clarify if this requires specific permissions, how results are returned (e.g., pagination, format), rate limits, or what happens if the server doesn't exist. For a tool with 5 parameters and no annotation coverage, this is insufficient.

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, clear sentence with zero wasted words. It's front-loaded with the core purpose and appropriately sized for what it communicates.

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

Completeness2/5

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

Given the tool's complexity (5 parameters, no output schema, no annotations), the description is incomplete. It doesn't explain what audit logs are, their structure, or return format. For a data retrieval tool with filtering capabilities, more context about the data being retrieved is needed for the agent to use it effectively.

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?

Schema description coverage is 100%, so all parameters are documented in the schema itself. The description adds no additional parameter semantics beyond what's in the schema (e.g., it doesn't explain what 'audit logs' contain or provide examples beyond the schema's actionType examples). Baseline 3 is appropriate when the schema does the heavy lifting.

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 verb ('Get') and resource ('audit logs from a server'), making the purpose immediately understandable. However, it doesn't distinguish this tool from its sibling 'list_audit_log_types', which appears to be related to audit logs but serves a different function (listing types vs. fetching logs).

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. It doesn't mention the sibling 'list_audit_log_types' or explain prerequisites like required permissions. The agent must infer usage from the tool name and parameters alone.

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