create_token
Generate a new Solana token by specifying name, symbol, supply, and decimals. Designed for HR teams using Crossmint HR Airdrop MCP to facilitate role-based token distribution and email notifications.
Instructions
Create a new Solana token
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| decimals | No | Token decimals (default: 9) | |
| name | Yes | Token name | |
| supply | Yes | Total token supply | |
| symbol | Yes | Token symbol |
Input Schema (JSON Schema)
{
"properties": {
"decimals": {
"description": "Token decimals (default: 9)",
"type": "number"
},
"name": {
"description": "Token name",
"type": "string"
},
"supply": {
"description": "Total token supply",
"type": "number"
},
"symbol": {
"description": "Token symbol",
"type": "string"
}
},
"required": [
"name",
"symbol",
"supply"
],
"type": "object"
}
Implementation Reference
- src/server.ts:159-184 (registration)Registration of the 'create_token' MCP tool including its input schema definition.{ name: 'create_token', description: 'Create a new Solana token', inputSchema: { type: 'object', properties: { name: { type: 'string', description: 'Token name', }, symbol: { type: 'string', description: 'Token symbol', }, supply: { type: 'number', description: 'Total token supply', }, decimals: { type: 'number', description: 'Token decimals (default: 9)', }, }, required: ['name', 'symbol', 'supply'], }, },
- src/server.ts:540-609 (handler)MCP tool handler for 'create_token' that validates parameters, calls the createToken utility, updates server state, and returns success response.private async handleCreateToken(args: any) { if (!this.state.connectedWallet) { throw new McpError( ErrorCode.InvalidRequest, 'No wallet connected. Please connect a wallet first.' ); } // Validate input const schema = z.object({ name: z.string(), symbol: z.string(), supply: z.number().positive(), decimals: z.number().min(0).max(9).default(9), }); const { name, symbol, supply, decimals } = schema.parse(args); try { // Create a dummy connection and keypair for simulation const connection = new Connection('https://api.mainnet-beta.solana.com', 'confirmed'); const keypair = Keypair.generate(); // In a real implementation, this would be the user's wallet // Call the token creation utility const result = await createToken( connection, keypair, name, symbol, supply, decimals ); if (!result.mintAddress) { throw new Error('Token creation failed: No mint address returned'); } // Update state this.state.createdToken = { name, symbol, mintAddress: result.mintAddress, supply, decimals, }; } catch (error) { throw new McpError( ErrorCode.InternalError, `Token creation failed: ${error instanceof Error ? error.message : String(error)}` ); } return { content: [ { type: 'text', text: ` Token created successfully: Name: ${name} Symbol: ${symbol} Supply: ${supply.toLocaleString()} Decimals: ${decimals} Mint Address: ${this.state.createdToken?.mintAddress} Next step: Add liquidity to give the token value. `.trim(), }, ], }; }
- src/utils/deployToken.ts:33-133 (helper)Core implementation of token creation logic using SPL Token program; exported as createToken from tokenUtils.ts and called by the MCP handler.export async function deployToken( connection: Connection, payer: Keypair, name: string, symbol: string, supply: number, decimals: number = 9 ): Promise<{ mintAddress: string }> { try { console.log(`Creating token: ${name} (${symbol}) with supply ${supply}`); // Check payer balance const balance = await connection.getBalance(payer.publicKey); console.log(`Payer balance: ${balance / LAMPORTS_PER_SOL} SOL`); if (balance < 0.05 * LAMPORTS_PER_SOL) { throw new Error(`Insufficient balance: ${balance / LAMPORTS_PER_SOL} SOL. Need at least 0.05 SOL.`); } // Generate a new keypair for the mint account const mintKeypair = Keypair.generate(); console.log(`Mint keypair generated: ${mintKeypair.publicKey.toString()}`); // Get the minimum lamports required for the mint const lamports = await getMinimumBalanceForRentExemptMint(connection); // Create a transaction to create the mint account const transaction = new Transaction(); // Add instruction to create the mint account transaction.add( SystemProgram.createAccount({ fromPubkey: payer.publicKey, newAccountPubkey: mintKeypair.publicKey, space: MINT_SIZE, lamports, programId: TOKEN_PROGRAM_ID, }) ); // Add instruction to initialize the mint account transaction.add( createInitializeMintInstruction( mintKeypair.publicKey, decimals, payer.publicKey, payer.publicKey ) ); // If supply is greater than 0, mint tokens to the payer if (supply > 0) { // Get the associated token account for the payer const associatedTokenAccount = await getAssociatedTokenAddress( mintKeypair.publicKey, payer.publicKey ); // Add instruction to create the associated token account if it doesn't exist transaction.add( createAssociatedTokenAccountInstruction( payer.publicKey, associatedTokenAccount, payer.publicKey, mintKeypair.publicKey ) ); // Add instruction to mint tokens to the payer's associated token account transaction.add( createMintToInstruction( mintKeypair.publicKey, associatedTokenAccount, payer.publicKey, supply * Math.pow(10, decimals) ) ); } // Send and confirm the transaction const signature = await sendAndConfirmTransaction( connection, transaction, [payer, mintKeypair] ); console.log(`Transaction signature: ${signature}`); // Return the mint address const mint = mintKeypair.publicKey; console.log(`Token mint created: ${mint.toString()}`); return { mintAddress: mint.toString() }; } catch (error: any) { console.error('Error deploying token:', error); throw new Error(`Token deployment failed: ${error.message}`); } }
- src/utils/tokenUtils.ts:26-29 (helper)Re-export of deployToken as createToken for use in server.ts./** * Create a new token on Solana */ export { deployToken as createToken };