approve_delegate
Authorize a delegate to transfer specific tokens from your Solana wallet by setting transfer limits and permissions.
Instructions
Approve a delegate to transfer tokens on your behalf
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| walletName | Yes | Name of the wallet that owns the tokens | |
| tokenMint | Yes | Token mint address | |
| delegateAddress | Yes | Address of the delegate | |
| amount | Yes | Maximum amount delegate can transfer |
Implementation Reference
- src/index.ts:1177-1214 (handler)The handler function that implements the approve_delegate tool logic. It approves a delegate for a specified token account using the SPL Token program's approve instruction, after validating the wallet, calculating the raw amount based on token decimals, and deriving the associated token account.async function handleApproveDelegate(args: any) { const { walletName, tokenMint, delegateAddress, amount } = args; const wallet = wallets.get(walletName); if (!wallet) { throw new Error(`Wallet '${walletName}' not found`); } ensureConnection(); const tokenMintPubkey = new PublicKey(tokenMint); const delegatePubkey = new PublicKey(delegateAddress); const mintInfo = await getMint(connection, tokenMintPubkey); const rawAmount = BigInt(Math.floor(amount * Math.pow(10, mintInfo.decimals))); const tokenAccount = await getAssociatedTokenAddress( tokenMintPubkey, wallet.keypair.publicKey ); const signature = await approve( connection, wallet.keypair, tokenAccount, delegatePubkey, wallet.keypair, rawAmount ); return { success: true, signature, delegate: delegateAddress, amount, explorerUrl: `https://explorer.solana.com/tx/${signature}?cluster=${currentNetwork}` }; }
- src/index.ts:480-505 (schema)The input schema definition for the approve_delegate tool, specifying parameters and validation rules, registered in the MCP tools list.{ name: "approve_delegate", description: "Approve a delegate to transfer tokens on your behalf", inputSchema: { type: "object", properties: { walletName: { type: "string", description: "Name of the wallet that owns the tokens" }, tokenMint: { type: "string", description: "Token mint address" }, delegateAddress: { type: "string", description: "Address of the delegate" }, amount: { type: "number", description: "Maximum amount delegate can transfer" } }, required: ["walletName", "tokenMint", "delegateAddress", "amount"] } },
- src/index.ts:1354-1356 (registration)Registration in the switch statement that dispatches calls to the handleApproveDelegate function in the main CallToolRequest handler.case "approve_delegate": result = await handleApproveDelegate(args); break;