Skip to main content
Glama

discord_read_messages

Retrieve messages from Discord text channels to monitor conversations, analyze discussions, or gather information with configurable limits for efficient data collection.

Instructions

Retrieves messages from a Discord text channel with a configurable limit

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
channelIdYes
limitNo

Implementation Reference

  • Main handler function that parses arguments, fetches the Discord channel, retrieves the specified number of recent messages, formats them with details like author, timestamp, attachments, and returns structured JSON response.
    export async function readMessagesHandler(
      args: unknown,
      context: ToolContext
    ): Promise<ToolResponse> {
      const { channelId, limit } = ReadMessagesSchema.parse(args);
      try {
        if (!context.client.isReady()) {
          return {
            content: [{ type: 'text', text: 'Discord client not logged in.' }],
            isError: true,
          };
        }
    
        const channel = await context.client.channels.fetch(channelId);
        if (!channel) {
          return {
            content: [
              { type: 'text', text: `Cannot find channel with ID: ${channelId}` },
            ],
            isError: true,
          };
        }
    
        // Check if channel has messages (text channel, thread, etc.)
        if (!(channel.isTextBased() && 'messages' in channel)) {
          return {
            content: [
              {
                type: 'text',
                text: 'Channel type does not support reading messages',
              },
            ],
            isError: true,
          };
        }
    
        // Fetch messages
        const messages = await channel.messages.fetch({ limit });
    
        if (messages.size === 0) {
          return {
            content: [{ type: 'text', text: 'No messages found in channel' }],
          };
        }
    
        // Format messages
        const formattedMessages = messages
          .map((msg) => ({
            id: msg.id,
            content: msg.content,
            author: {
              id: msg.author.id,
              username: msg.author.username,
              bot: msg.author.bot,
            },
            timestamp: msg.createdAt,
            attachments: msg.attachments.size,
            embeds: msg.embeds.length,
            replyTo: msg.reference ? msg.reference.messageId : null,
          }))
          .sort((a, b) => a.timestamp.getTime() - b.timestamp.getTime());
    
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(
                {
                  channelId,
                  messageCount: formattedMessages.length,
                  messages: formattedMessages,
                },
                null,
                2
              ),
            },
          ],
        };
      } catch (error) {
        return handleDiscordError(error);
      }
    }
  • MCP tool schema defining the name, description, input parameters (channelId required, limit optional 1-100 default 50), and validation.
    {
      name: 'discord_read_messages',
      description:
        'Retrieves messages from a Discord text channel with a configurable limit',
      inputSchema: {
        type: 'object',
        properties: {
          channelId: { type: 'string' },
          limit: {
            type: 'number',
            minimum: 1,
            maximum: 100,
            default: 50,
          },
        },
        required: ['channelId'],
      },
    },
  • src/server.ts:151-154 (registration)
    Registers and dispatches the discord_read_messages tool call to the readMessagesHandler function within the MCP server's CallToolRequestSchema handler.
    case 'discord_read_messages':
      this.logClientState('before discord_read_messages handler');
      toolResponse = await readMessagesHandler(args, this.toolContext);
      return toolResponse;
  • Re-exports the readMessagesHandler from channel.ts for convenient import in server.ts and transport.ts.
    export {
      createCategoryHandler,
      createTextChannelHandler,
      deleteCategoryHandler,
      deleteChannelHandler,
      editCategoryHandler,
      getServerInfoHandler,
      readMessagesHandler,
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions a 'configurable limit' but lacks critical details: whether this is a read-only operation (implied by 'Retrieves' but not explicit), authentication requirements, rate limits, pagination behavior, or error handling. For a tool with potential API constraints, this is a significant gap in transparency.

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 front-loads the core functionality ('Retrieves messages from a Discord text channel') and adds a key detail ('with a configurable limit'). There is no wasted verbiage, and every word contributes to understanding the tool's basic operation.

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 complexity of a Discord API tool with no annotations, no output schema, and low parameter documentation, the description is incomplete. It misses essential context like return format (e.g., message objects with timestamps), error cases (e.g., invalid channelId), and behavioral constraints (e.g., rate limits). This leaves the agent under-informed for reliable invocation.

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 description adds minimal semantics beyond the input schema. It implies 'limit' controls the number of messages retrieved, but doesn't explain ordering (e.g., most recent first), what 'channelId' represents, or default behavior. With 0% schema description coverage, the description doesn't adequately compensate for the lack of parameter documentation, though it hints at the purpose of 'limit'.

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 ('Retrieves messages') and resource ('from a Discord text channel'), making the purpose immediately understandable. It distinguishes from siblings like discord_send or discord_delete_message by focusing on reading rather than writing or deleting. However, it doesn't explicitly differentiate from potential read-related siblings (none exist in the provided list), keeping it from 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. It doesn't mention prerequisites (e.g., needing channel access), compare to other read operations (none in siblings), or specify scenarios where it's appropriate (e.g., for monitoring vs. analysis). This leaves the agent with minimal context for selection.

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/IQAIcom/mcp-discord'

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