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
| Name | Required | Description | Default |
|---|---|---|---|
| address | Yes | Wallet address to get conversation with | |
| limit | No | Maximum number of messages to retrieve |
Implementation Reference
- src/index.ts:339-380 (handler)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);
- src/index.ts:150-168 (schema)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"], }, },