get_messages
Retrieve encrypted messages from a conversation with a specific wallet address on the XMTP decentralized messaging network, limiting results as needed.
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 handler function that implements the get_messages tool logic: checks XMTP client connection, creates conversation with target address, syncs, retrieves up to 'limit' messages, formats them as JSON, and returns as tool response.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:153-167 (schema)Input schema definition for the get_messages tool, specifying 'address' as required string and optional 'limit' number (default 50). No explicit output schema.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"], },
- src/index.ts:150-168 (registration)Tool registration in the ListToolsRequestHandler response, defining name, description, and input schema for discovery by MCP clients.{ 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"], }, },
- src/index.ts:220-222 (registration)Registration in the CallToolRequestHandler switch statement that dispatches 'get_messages' calls to the specific handler method.case "get_messages": return await this.getMessages(args);