Skip to main content
Glama

get_messages

Retrieve encrypted messages from a conversation with a specific wallet address on the XMTP network. Specify the address and optionally limit the number of messages returned.

Instructions

Get messages from a conversation with an address

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
addressYesWallet address to get conversation with
limitNoMaximum number of messages to retrieve

Implementation Reference

  • The main handler function that implements the get_messages tool logic: creates a DM conversation with the given address, syncs, fetches up to 'limit' messages, formats them as JSON, and returns as text content.
    private async getMessages(args: any) {
      if (!this.state.client) {
        throw new Error("XMTP client not connected. Use connect_xmtp tool first.");
      }
    
      const { address, limit = 50 } = args;
    
      try {
        // Create conversation with proper identifier (back to original method)
        const addressIdentifier = {
          identifier: address,
          identifierKind: 0, // IdentifierKind.Ethereum
        };
        const conversation = await this.state.client.conversations.newDmWithIdentifier(addressIdentifier);
        
        // Sync conversations to ensure we get latest messages
        await this.state.client.conversations.syncAll();
        
        // Add brief delay after sync
        await new Promise(resolve => setTimeout(resolve, 500));
        
        const messages = await conversation.messages({ limit });
    
        const messageList = messages.map((msg: DecodedMessage<any>) => ({
          id: msg.id,
          sender: msg.senderInboxId,
          content: msg.content,
          timestamp: msg.sentAt?.toISOString(),
        }));
    
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify(messageList, null, 2),
            },
          ],
        };
      } catch (error) {
        throw new Error(`Failed to get messages: ${error}`);
      }
    }
  • src/index.ts:220-221 (registration)
    Tool dispatch/registration in the CallToolRequestSchema handler switch statement, which calls the getMessages method when 'get_messages' is requested.
    case "get_messages":
      return await this.getMessages(args);
  • Tool definition including name, description, and input schema (address required, limit optional default 50) in the ListToolsRequestSchema response.
    {
      name: "get_messages",
      description: "Get messages from a conversation with an address",
      inputSchema: {
        type: "object",
        properties: {
          address: {
            type: "string",
            description: "Wallet address to get conversation with",
          },
          limit: {
            type: "number",
            description: "Maximum number of messages to retrieve",
            default: 50,
          },
        },
        required: ["address"],
      },
    },

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/kwaude/xmtp-mcp'

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