tokens_send_near
Send NEAR tokens from a signer account to a receiver account. Specify the amount in NEAR and choose between testnet or mainnet.
Instructions
Send NEAR tokens to an account (in NEAR). The signer account is the sender of the tokens, and the receiver account is the recipient of the tokens. Remember mainnet accounts are created with a .near suffix, and testnet accounts are created with a .testnet suffix. The user is sending tokens as the signer account. Please ensure that the sender and receiver accounts are in the same network.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| signerAccountId | Yes | ||
| receiverAccountId | Yes | ||
| amount | No | The amount of NEAR to send in NEAR. e.g. 1.5 | |
| networkId | No | mainnet |
Implementation Reference
- src/services.ts:1619-1681 (handler)The 'tokens_send_near' tool registration and handler implementation. This tool sends NEAR tokens from a signer account to a receiver account. It uses mcp.tool() to register with name 'tokens_send_near', defines a Zod schema for signerAccountId, receiverAccountId, amount (union of number/bigint), and networkId. The handler connects to the NEAR network, converts the amount to yoctoNEAR using NearToken, and calls account.sendMoney() to execute the transfer.
mcp.tool( 'tokens_send_near', noLeadingWhitespace` Send NEAR tokens to an account (in NEAR). The signer account is the sender of the tokens, and the receiver account is the recipient of the tokens. Remember mainnet accounts are created with a .near suffix, and testnet accounts are created with a .testnet suffix. The user is sending tokens as the signer account. Please ensure that the sender and receiver accounts are in the same network.`, { signerAccountId: z.string(), receiverAccountId: z.string(), amount: z .union([ z.number().describe('The amount of NEAR tokens (in NEAR)'), z.bigint().describe('The amount in yoctoNEAR'), ]) .default(NearToken.parse_yocto_near('1').as_near()) .describe('The amount of NEAR to send in NEAR. e.g. 1.5'), networkId: z.enum(['testnet', 'mainnet']).default('mainnet'), }, async (args, _) => { const connection = await connect({ networkId: args.networkId, keyStore: keystore, nodeUrl: getEndpointsByNetwork(args.networkId)[0]!, }); const sendResult: Result<FinalExecutionOutcome, Error> = await (async () => { try { const account = await connection.account(args.signerAccountId); const amount = typeof args.amount === 'number' ? NearToken.parse_near(args.amount.toString()).as_yocto_near() : args.amount; const sendMoneyResult = await account.sendMoney( args.receiverAccountId, amount, ); return { ok: true, value: sendMoneyResult, }; } catch (e) { return { ok: false, error: new Error(e as string) }; } })(); if (!sendResult.ok) { return { content: [{ type: 'text', text: `Error: ${sendResult.error}` }], }; } return { content: [ { type: 'text', text: `Transaction sent: ${stringify_bigint(sendResult.value)}`, }, ], }; }, ); - src/services.ts:1619-1640 (schema)Schema definition for the 'tokens_send_near' tool: requires signerAccountId (string), receiverAccountId (string), amount (union of number for NEAR or bigint for yoctoNEAR, defaulting to 1 NEAR), and networkId (enum testnet/mainnet, default mainnet).
mcp.tool( 'tokens_send_near', noLeadingWhitespace` Send NEAR tokens to an account (in NEAR). The signer account is the sender of the tokens, and the receiver account is the recipient of the tokens. Remember mainnet accounts are created with a .near suffix, and testnet accounts are created with a .testnet suffix. The user is sending tokens as the signer account. Please ensure that the sender and receiver accounts are in the same network.`, { signerAccountId: z.string(), receiverAccountId: z.string(), amount: z .union([ z.number().describe('The amount of NEAR tokens (in NEAR)'), z.bigint().describe('The amount in yoctoNEAR'), ]) .default(NearToken.parse_yocto_near('1').as_near()) .describe('The amount of NEAR to send in NEAR. e.g. 1.5'), networkId: z.enum(['testnet', 'mainnet']).default('mainnet'), }, - src/services.ts:411-459 (registration)The createMcpServer function is where all MCP tools including 'tokens_send_near' are registered via mcp.tool() calls. It's defined on line 411 and returns the mcp object with registered tools. The tokens_send_near registration is specifically at line 1619-1681.
export const createMcpServer = async (keyDir: string) => { const keystore = new UnencryptedFileSystemKeyStore(keyDir); const mcp = new McpServer( { name: MCP_SERVER_NAME, version: '1.0.0', }, { capabilities: { logging: {}, }, instructions: noLeadingWhitespace` # NEAR MCP Server Welcome to the NEAR Model Context Protocol (MCP) Server. This server provides a bridge between AI models and the NEAR blockchain ecosystem. ## What is NEAR? [NEAR](https://near.org/) is a layer-1 blockchain designed for usability and scalability. It features a proof-of-stake consensus mechanism, sharding for scalability, and developer-friendly tools for building decentralized applications. ## What this MCP server does: This server provides a way to interact with the NEAR blockchain through natural language interfaces. It enables: - Account management: Import, export, and manage NEAR accounts - Token operations: Send and receive NEAR tokens and NEAR Fungible Tokens (FTs) - Contract interactions: Query and interact with smart contracts on the NEAR blockchain ## Use cases: - Wallet management through conversational interfaces - Token transfers via natural language commands - Smart contract interactions without requiring technical blockchain knowledge - Blockchain data querying and analysis - Educational tool for learning about NEAR blockchain operations ## Guidelines - When a user refers to the USDC token, they commonly refer to the USDC native token. - When a user refers to the USDT token, they commonly refer to the USDT native token. ## Extra information This server is powered by the NEAR API SDK and serves as a bridge between AI assistants and the NEAR blockchain ecosystem. `, }, );