stream_messages
Stream real-time messages from all conversations on the XMTP decentralized messaging network. Use an optional callback to handle incoming messages instantly for AI agents or connected wallets.
Instructions
Start streaming new messages from all conversations
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| callback | No | Optional callback function name for message handling |
Implementation Reference
- src/index.ts:439-476 (handler)The main handler function that implements the stream_messages tool. It streams messages from all XMTP conversations, collects up to 10 recent messages, and returns them in the response.private async streamMessages(args: any) { if (!this.state.client) { throw new Error("XMTP client not connected. Use connect_xmtp tool first."); } try { // Start streaming all messages const stream = await this.state.client.conversations.streamAllMessages(); let messageCount = 0; const messages: any[] = []; // Collect first few messages for demonstration for await (const message of stream) { messages.push({ id: message.id, sender: message.senderInboxId, content: message.content, timestamp: message.sentAt?.toISOString(), conversationId: message.conversationId, }); messageCount++; if (messageCount >= 10) break; // Limit for demonstration } return { content: [ { type: "text", text: `Started streaming messages. Recent messages:\n${JSON.stringify(messages, null, 2)}`, }, ], }; } catch (error) { throw new Error(`Failed to stream messages: ${error}`); } }
- src/index.ts:191-203 (schema)The tool descriptor in the listTools response, including name, description, and inputSchema for the stream_messages tool.{ name: "stream_messages", description: "Start streaming new messages from all conversations", inputSchema: { type: "object", properties: { callback: { type: "string", description: "Optional callback function name for message handling", }, }, }, },
- src/index.ts:229-230 (registration)The switch case in the CallToolRequest handler that registers and dispatches to the streamMessages handler for the stream_messages tool.case "stream_messages": return await this.streamMessages(args);
- src/index.ts:110-206 (registration)The ListToolsRequest handler registration that includes the stream_messages tool in the available tools list.this.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: [ { name: "connect_xmtp", description: "Connect to XMTP network with wallet key", inputSchema: { type: "object", properties: { privateKey: { type: "string", description: "Wallet private key (optional, uses env WALLET_KEY if not provided)", }, environment: { type: "string", description: "XMTP environment: local, dev, or production", enum: ["local", "dev", "production"], default: "production", }, }, }, }, { name: "send_message", description: "Send a message to an address via XMTP", inputSchema: { type: "object", properties: { recipient: { type: "string", description: "Wallet address or ENS name to send message to", }, message: { type: "string", description: "Message content to send", }, }, required: ["recipient", "message"], }, }, { 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"], }, }, { name: "list_conversations", description: "List all active XMTP conversations", inputSchema: { type: "object", properties: {}, }, }, { name: "check_can_message", description: "Check if an address can receive XMTP messages", inputSchema: { type: "object", properties: { address: { type: "string", description: "Wallet address to check", }, }, required: ["address"], }, }, { name: "stream_messages", description: "Start streaming new messages from all conversations", inputSchema: { type: "object", properties: { callback: { type: "string", description: "Optional callback function name for message handling", }, }, }, }, ], }; });