Skip to main content
The NEAR MCP Server is an open-source toolkit that offers a standardized way for AI applications to integrate with NEAR. It provides 23 tools which enable agents to sign on-chain transactions, manage access keys, exchange tokens, interact with contracts, and more.
MCP stands for Model Context Protocol, an open-source standard for connecting AI agents with external services.Not to be confused with the MPC (Multi-Party Computation) service used by chain signatures.

Usage guide

Since the NEAR MCP Server needs to handle private keys, it is designed to run locally on your machine or on a trusted remote server. Currently there is no hosted version of the NEAR MCP server.

Quickstart

You can either install the MCP server globally and start it, or run it directly using npx.
# Install and Run
npm install -g @nearai/near-mcp@latest
near-mcp run

# Without Installing
npx @nearai/near-mcp@latest run
By default the MCP server will run a local input/output server. To start a web server instead add the --port 4000 --remote flags:
npx @nearai/near-mcp@latest run --port 4000 --remote

Local MCP server

Once the NEAR MCP starts locally it creates what is called a stdio server. To connect your AI agent to the server you will need to use an MCP client library:
from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client

# Connect to NEAR MCP server
server_params = StdioServerParameters(
    command="npx",
    args=["-y", "@nearai/near-mcp@latest", "run"]
)

async with stdio_client(server_params) as (read, write):
    async with ClientSession(read, write) as session:
        # Use the session to call tools
        pass
In order to use the NEAR MCP server, you will need to manually parse its tools and make them available to your AI agent as part of your prompt.
Accounts: By default the MCP server will have no accounts loaded. Your agent can either import an account using the system_import_account tool, or you can specify which keystore to load by setting the NEAR_KEYSTORE environment variable:
NEAR_KEYSTORE=/path/to/keystore npx @nearai/near-mcp@latest run

Example prompts

The Agent using the MCP server will readily have tools to answer prompts like:
  • What is the balance of agency.testnet?
  • Add the account example.testnet using the private key ed25519:...
  • Transfer 0.1 NEAR from agency.testnet to example.testnet
  • Call the ft_transfer method on the usdc.fakes.testnet contract
  • What are the public methods of social.near?

Integrate with AI clients

You can use the NEAR MCP server with any standard MCP client. Here are instructions for some popular clients:
Go to Settings > MCP Servers, and add a new server with the following details:
  • Name: near-mcp
  • Command: npx
  • Arguments: [“-y”, “@nearai/near-mcp@latest”, “run”]
  • Environment Variables: (optional) Add any necessary environment variables, e.g., NEAR_KEYSTORE.
You can now use the NEAR MCP tools in your prompts.

Remote MCP server

Read these instructions to deploy the MCP server remotely on Phala Cloud.

Contributing

Visit NEAR AI’s GitHub repository to create issues or submit pull requests.

Build docs developers (and LLMs) love