connect_xmtp
Connect to the XMTP decentralized messaging network using wallet authentication to enable encrypted communication between AI agents and XMTP-enabled wallets.
Instructions
Connect to XMTP network with wallet key
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| privateKey | No | Wallet private key (optional, uses env WALLET_KEY if not provided) | |
| environment | No | XMTP environment: local, dev, or production | production |
Implementation Reference
- src/index.ts:250-294 (handler)The main handler function that implements the connect_xmtp tool logic: creates a wallet signer from private key, initializes XMTP Client, and stores it in 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:113-131 (registration)Registers the connect_xmtp tool in the list of available tools, 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:116-130 (schema)Defines the input schema for the connect_xmtp tool, specifying privateKey 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:214-215 (handler)Dispatcher switch case that routes connect_xmtp tool calls to the connectXMTP handler.case "connect_xmtp": return await this.connectXMTP(args);