calculate_amounts
Calculate token amounts for employees based on uniform distribution or role-specific allocations using roleAmounts or uniformAmount inputs in the Crossmint HR Airdrop MCP server.
Instructions
Calculate token amounts for each employee
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "calculate_amounts"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| roleAmounts | No | Token amounts by role (if CSV with roles is used) | |
| uniformAmount | No | Uniform amount for all employees (if no CSV role-mapping is used) |
Implementation Reference
- src/server.ts:864-961 (handler)The main execution logic for the 'calculate_amounts' tool. Validates input, calculates token amounts per employee based on uniform or role-based allocation using defaults or provided values, updates employee state with tokenAmount, computes total, and returns formatted summary.
private async handleCalculateAmounts(args: any) { if (this.state.employees.length === 0) { throw new McpError( ErrorCode.InvalidRequest, 'No employees added. Please generate wallets first.' ); } // Validate input const schema = z.object({ uniformAmount: z.number().positive().optional(), roleAmounts: z .object({ operational: z.number().positive().optional(), developer: z.number().positive().optional(), manager: z.number().positive().optional(), VP: z.number().positive().optional(), VIP: z.number().positive().optional(), }) .optional(), }); const { uniformAmount, roleAmounts } = schema.parse(args); // Set default role amounts if not provided const defaultRoleTokens = { operational: 100, developer: 200, manager: 300, vp: 400, vip: 500, }; // Combine with provided role amounts const roleTokens: Record<string, number> = { ...defaultRoleTokens, ...(roleAmounts || {}), }; let totalAmount = 0; // Update employee records with token amounts this.state.employees = this.state.employees.map((employee) => { let tokenAmount: number; if (uniformAmount) { // Use uniform amount for all employees tokenAmount = uniformAmount; } else if (employee.role) { // Use role-based amount if role is available const role = employee.role.toLowerCase(); if (role === 'operational') tokenAmount = roleTokens.operational || 100; else if (role === 'developer') tokenAmount = roleTokens.developer || 200; else if (role === 'manager') tokenAmount = roleTokens.manager || 300; else if (role === 'vp') tokenAmount = roleTokens.vp || 400; else if (role === 'vip') tokenAmount = roleTokens.vip || 500; else tokenAmount = 100; // Default fallback } else { // Default amount if no role specified tokenAmount = 100; } totalAmount += tokenAmount; return { ...employee, tokenAmount, }; }); return { content: [ { type: 'text', text: ` Token amounts calculated successfully: ${this.state.employees .map( (employee) => `- ${employee.name || employee.email}: ${employee.tokenAmount} tokens (${ employee.role || 'No role' })` ) .join('\n')} Total tokens to be distributed: ${totalAmount} ${ this.state.createdToken ? `Token supply: ${this.state.createdToken.supply}` : 'No token created yet. Please create a token with sufficient supply.' } Next step: Calculate gas fees for the airdrop. `.trim(), }, ], }; } - src/server.ts:235-258 (registration)Tool registration in the ListToolsRequestSchema handler, defining the tool name, description, and input schema for MCP clients to discover and call the tool.
{ name: 'calculate_amounts', description: 'Calculate token amounts for each employee', inputSchema: { type: 'object', properties: { uniformAmount: { type: 'number', description: 'Uniform amount for all employees (if no CSV role-mapping is used)', }, roleAmounts: { type: 'object', properties: { operational: { type: 'number' }, developer: { type: 'number' }, manager: { type: 'number' }, VP: { type: 'number' }, VIP: { type: 'number' }, }, description: 'Token amounts by role (if CSV with roles is used)', }, }, }, }, - src/server.ts:873-884 (schema)Zod validation schema inside the handler matching the tool's inputSchema for runtime parameter validation.
const schema = z.object({ uniformAmount: z.number().positive().optional(), roleAmounts: z .object({ operational: z.number().positive().optional(), developer: z.number().positive().optional(), manager: z.number().positive().optional(), VP: z.number().positive().optional(), VIP: z.number().positive().optional(), }) .optional(), }); - src/server.ts:328-329 (registration)Dispatch case in the CallToolRequestSchema switch statement that routes tool calls to the specific handler.
case 'calculate_amounts': return await this.handleCalculateAmounts(args);