TypeScriptADK-TS

MCP NEAR Agent

Interact with the NEAR Protocol blockchain with AI-driven event processing and account management.

Overview

The NEAR Agent MCP server lets your agent interact with the NEAR Protocol blockchain. It supports account management, transaction execution, and AI-driven event processing using your NEAR account credentials.

Getting Started

Install the package:

pnpm add @iqai/mcp-near-agent

Use the server in your agent:

import { McpNearAgent } from "@iqai/adk";

const toolset = McpNearAgent({
  env: {
    ACCOUNT_ID: process.env.NEAR_ACCOUNT_ID,
    ACCOUNT_KEY: process.env.NEAR_ACCOUNT_KEY,
  },
});

const tools = await toolset.getTools();
import { McpToolset } from "@iqai/adk";

const toolset = new McpToolset({
  name: "NEAR Agent MCP Client",
  description: "Client for NEAR Protocol blockchain integration",
  transport: {
    mode: "stdio",
    command: "npx",
    args: ["-y", "@iqai/mcp-near-agent"],
    env: {
      ACCOUNT_ID: process.env.NEAR_ACCOUNT_ID,
      ACCOUNT_KEY: process.env.NEAR_ACCOUNT_KEY,
      NEAR_NETWORK_ID: process.env.NEAR_NETWORK_ID,
      NEAR_NODE_URL: process.env.NEAR_NODE_URL,
      PATH: process.env.PATH || "",
    },
  },
});

const tools = await toolset.getTools();
{
  "mcpServers": {
    "near-agent-mcp-server": {
      "command": "npx",
      "args": ["-y", "@iqai/mcp-near-agent"],
      "env": {
        "ACCOUNT_ID": "your_near_account_id",
        "ACCOUNT_KEY": "your_near_account_private_key"
      }
    }
  }
}

Environment Variables

VariableRequiredDescription
ACCOUNT_IDYesYour NEAR account ID (e.g. myaccount.near)
ACCOUNT_KEYYesYour NEAR account private key
NEAR_NETWORK_IDNoNetwork to connect to (default: mainnet)
NEAR_NODE_URLNoCustom NEAR RPC node URL
NEAR_GAS_LIMITNoGas limit for transactions (default: protocol limit)

Credentials

To get your NEAR account credentials:

  1. Create a NEAR account at wallet.near.org or app.mynearwallet.com
  2. Export your account's private key from the wallet or NEAR CLI
  3. Your ACCOUNT_ID is your NEAR account name (e.g. yourname.near)

Available Tools

watch_near_event
eventName:stringcontractId:stringresponseMethodName:stringresponseParameterName:stringcronExpression:string

Description

Start watching for specific events on a NEAR contract and process them with AI responses

stop_watching_near_event
contractId:stringeventName:string

Description

Stop watching for specific events on a NEAR contract

list_watched_near_events
includeStats:boolean

Description

List all currently watched NEAR events and their status

Integration Example

import { AgentBuilder, McpNearAgent } from "@iqai/adk";
import * as dotenv from "dotenv";

dotenv.config();

async function main() {
  // Initialize McpNearAgent toolset
  const toolset = McpNearAgent({
    env: {
      ACCOUNT_ID: process.env.NEAR_ACCOUNT_ID,
      ACCOUNT_KEY: process.env.NEAR_ACCOUNT_KEY,
    },
  });

  // Get available McpNearAgent tools
  const nearAgentTools = await toolset.getTools();

  // Create agent with McpNearAgent tools
  const { runner } = await AgentBuilder.create("near_agent")
    .withModel("gemini-2.5-flash")
    .withDescription(
      "An agent that interacts with the NEAR Protocol blockchain",
    )
    .withTools(...nearAgentTools)
    .build();

  const response = await runner.ask("What is the balance of my NEAR account?");

  console.log(response);
}

main().catch(console.error);

Further Resources