connect_xmtp
Initiate a connection to the XMTP network using a wallet private key to enable AI agents to send encrypted messages, manage conversations, and stream real-time communication across XMTP-enabled wallets. Supports local, dev, and production environments.
Instructions
Connect to XMTP network with wallet key
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| environment | No | XMTP environment: local, dev, or production | production |
| privateKey | No | Wallet private key (optional, uses env WALLET_KEY if not provided) |
Implementation Reference
- src/index.ts:250-294 (handler)The primary handler function that implements the connect_xmtp tool logic: creates a signer from private key, initializes XMTP Client, and updates server state.private async connectXMTP(args: any) { try { const privateKey = args.privateKey || process.env.WALLET_KEY; const environment = args.environment || process.env.XMTP_ENV || "production"; if (!privateKey) { throw new Error("Private key required. Provide via parameter or WALLET_KEY env variable."); } // Create proper EOA signer for XMTP using viem account (exact same as working debug script) const account = privateKeyToAccount(privateKey as `0x${string}`); const signer = { type: "EOA" as const, signMessage: async (message: string) => { const signature = await account.signMessage({ message }); return toBytes(signature); }, getIdentifier: () => { return { identifier: account.address, identifierKind: 0, // IdentifierKind.Ethereum }; }, getChainId: () => BigInt(1), // Ethereum mainnet as bigint }; // Initialize XMTP client with proper signer this.state.client = await Client.create(signer, { env: environment as "local" | "dev" | "production", }); this.state.walletAddress = account.address; return { content: [ { type: "text", text: `Successfully connected to XMTP ${environment} network with address: ${account.address}`, }, ], }; } catch (error) { throw new Error(`XMTP connection failed: ${error}`); } }
- src/index.ts:116-130 (schema)Input schema definition for the connect_xmtp tool, specifying privateKey (optional) and environment parameters.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", }, }, },
- src/index.ts:113-131 (registration)Tool registration in the ListTools response, including name, description, and input schema.{ 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", }, }, }, },
- src/index.ts:214-215 (registration)Dispatch/registration of the connect_xmtp handler in the CallToolRequest switch statement.case "connect_xmtp": return await this.connectXMTP(args);