Skip to main content
Glama
hanweg

mcp-discord

by hanweg

read_messages

Fetch recent messages from a specified Discord channel by providing the channel ID and limit. Integrated with the MCP server for Discord functionality.

Instructions

Read recent messages from a channel

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
channel_idYesDiscord channel ID
limitNoNumber of messages to fetch (max 100)

Implementation Reference

  • Handler function for the 'read_messages' tool within the call_tool method. Fetches recent messages from a Discord channel, including reactions, and formats them into a text response.
    elif name == "read_messages":
        channel = await discord_client.fetch_channel(int(arguments["channel_id"]))
        limit = min(int(arguments.get("limit", 10)), 100)
        fetch_users = arguments.get("fetch_reaction_users", False)  # Only fetch users if explicitly requested
        messages = []
        async for message in channel.history(limit=limit):
            reaction_data = []
            for reaction in message.reactions:
                emoji_str = str(reaction.emoji.name) if hasattr(reaction.emoji, 'name') and reaction.emoji.name else str(reaction.emoji.id) if hasattr(reaction.emoji, 'id') else str(reaction.emoji)
                reaction_info = {
                    "emoji": emoji_str,
                    "count": reaction.count
                }
                logger.error(f"Emoji: {emoji_str}")
                reaction_data.append(reaction_info)
            messages.append({
                "id": str(message.id),
                "author": str(message.author),
                "content": message.content,
                "timestamp": message.created_at.isoformat(),
                "reactions": reaction_data  # Add reactions to message dict
            })
        # Helper function to format reactions
        def format_reaction(r):
            return f"{r['emoji']}({r['count']})"
            
        return [TextContent(
            type="text",
            text=f"Retrieved {len(messages)} messages:\n\n" + 
                 "\n".join([
                     f"{m['author']} ({m['timestamp']}): {m['content']}\n" +
                     f"Reactions: {', '.join([format_reaction(r) for r in m['reactions']]) if m['reactions'] else 'No reactions'}"
                     for m in messages
                 ])
        )]
  • Input schema definition for the 'read_messages' tool, specifying parameters for channel_id (required) and optional limit (1-100).
    Tool(
        name="read_messages",
        description="Read recent messages from a channel",
        inputSchema={
            "type": "object",
            "properties": {
                "channel_id": {
                    "type": "string",
                    "description": "Discord channel ID"
                },
                "limit": {
                    "type": "number",
                    "description": "Number of messages to fetch (max 100)",
                    "minimum": 1,
                    "maximum": 100
                }
            },
            "required": ["channel_id"]
        }
    ),
  • Registration of the 'read_messages' tool in the list_tools handler via the Tool object returned by @app.list_tools().
    Tool(
        name="read_messages",
        description="Read recent messages from a channel",
        inputSchema={
            "type": "object",
            "properties": {
                "channel_id": {
                    "type": "string",
                    "description": "Discord channel ID"
                },
                "limit": {
                    "type": "number",
                    "description": "Number of messages to fetch (max 100)",
                    "minimum": 1,
                    "maximum": 100
                }
            },
            "required": ["channel_id"]
        }
    ),
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the action ('read') but doesn't cover critical aspects like permissions needed, rate limits, pagination behavior, or what 'recent' means (e.g., time-based or count-based). This is inadequate for a read operation in a collaborative environment like Discord.

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 with zero waste. It's front-loaded with the core action and resource, making it easy to parse quickly. Every word earns its place without redundancy or fluff.

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 lack of annotations and output schema, the description is incomplete. It doesn't explain what 'recent' entails, the return format, error handling, or how it fits with sibling tools. For a read operation in a complex system like Discord, this leaves significant gaps for an AI agent to operate 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 the schema fully documents both parameters ('channel_id' and 'limit'). The description adds no additional meaning beyond implying 'recent' messages, which doesn't clarify parameter usage or constraints beyond what the schema provides. 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 action ('read') and resource ('recent messages from a channel'), making the tool's purpose understandable. However, it doesn't differentiate from potential siblings like 'get_channels' or 'list_members' that might also involve reading data, leaving room for ambiguity in a crowded toolset.

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. With siblings like 'get_channels' and 'list_members' that might overlap in reading data, there's no indication of context, prerequisites, or exclusions, leaving the agent to guess based on tool names 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

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

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