#
tokens: 4977/50000 6/6 files
lines: off (toggle) GitHub
raw markdown copy
# Directory Structure

```
├── .gitignore
├── assets
│   ├── claude-desktop-edit-config-button.png
│   ├── claude-desktop-settings-in-menu.png
│   ├── claude-desktop-tool-descriptions.png
│   └── claude-desktop-tools-installed.png
├── Dockerfile
├── LICENSE
├── nano-currency.js
├── package-lock.json
├── package.json
├── README.md
└── smithery.yaml
```

# Files

--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------

```
node_modules
```

--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------

```markdown
# Nano Currency MCP Server
[![smithery badge](https://smithery.ai/badge/@kilkelly/nano-currency-mcp-server)](https://smithery.ai/server/@kilkelly/nano-currency-mcp-server)

This Model Context Protocol (MCP) server gives MCP-compatible clients (which include some AI agents) the ability to send Nano currency and retrieve account & block information via the Nano node RPC.

<a href="https://glama.ai/mcp/servers/@kilkelly/nano-currency-mcp-server">
  <img width="380" height="200" src="https://glama.ai/mcp/servers/@kilkelly/nano-currency-mcp-server/badge" alt="Nano Currency Server MCP server" />
</a>

AI agents are increasingly adopting the MCP standard so this server can give them the ability to send Nano at their owner's request or possibility autonomously in some setups 🤖

## ❔ What is MCP?

The Model Context Protocol (MCP) is an open framework that defines a standardized approach for applications to deliver context to Large Language Models (LLMs).

## ❔ What is Nano Currency?

Nano is a digital currency designed to enable fast, scalable, and feeless transactions. It aims to address common issues in traditional cryptocurrencies, such as high fees and slow processing times, making it an efficient option for everyday peer-to-peer payments. Learn more at [nano.org](https://nano.org)

## 🚨 Before Proceeding 🚨

Caution: LLMs can hallucinate and not always perform as you want so test this server with small amounts of Nano.

## 🛠️ Tools Provided by the MCP Server

🔧 `nano_send` - Sends a specified amount of Nano currency

🔧 `nano_account_info` - Retrieves detailed information about a specific Nano account/address

🔧 `nano_my_account_info` - Retrieves detailed information about your predefined Nano account/address

🔧 `block_info` - Retrieves detailed information about a specific Nano block

## Prerequisites

Make sure you have [Node.js](https://nodejs.org/) with NPM installed. 

## Setup

```
git clone https://github.com/kilkelly/nano-currency-mcp-server.git
cd nano-currency-mcp-server
npm install
```


You will need an MCP client to connect to the MCP server (see the Claude Desktop setup later as an example MCP client). Each client will have its own way to connect to MCP servers. For your chosen client you will have to find out how environment variables for a MCP server are set. When you know how you will need to set the following environment variables to use the Nano Currency MCP Server.

### Environment Variables

`NANO_RPC_URL` - URL which should be used to communicate with a Nano node RPC. This can be a local or remotely hosted endpoint.
This URL value is **required**.

`NANO_WORK_GENERATION_URL` - URL which should be used to communicate with an endpoint that supports the [work_generate](https://docs.nano.org/commands/rpc-protocol/#work_generate) RPC command for work generation. If not specified, defaults to `NANO_RPC_URL`. Used by tool 🔧 `nano_send`

`NANO_PRIVATE_KEY` - Nano private key which will be used to sign send transactions and to derive the Nano address from. Caution: 🚨*NOT THE WALLET SEED*🚨. Test with the private key of an account with a small Nano balance. Used by tools 🔧 `nano_send` and 🔧 `nano_my_account_info`

`NANO_MAX_SEND_AMOUNT` - Maximum amount (in nano/Ӿ units) which can be sent in a single transaction. For safety purposes the default maximum send amount is 0.01 nano (Ӿ0.01). You must set this variable explicitly to grant the power to send higher amounts. Used by tools: 🔧 `nano_send`

## Claude Desktop Setup

### 1. Install and run [Claude Desktop](https://claude.ai/download)


### 2. Open the Settings menu

![Settings menu](assets/claude-desktop-settings-in-menu.png)


### 3. Click the `Developer` tab and then `Edit Config` button to open the location of the Claude config file `claude_desktop_config.json`

![Edit Config button](assets/claude-desktop-edit-config-button.png)


### 4. Open up `claude_desktop_config.json` in your text editor of choice and enter the following but swapping out the values for your unique configuration:

```
{
  "mcpServers": {
    "nano_currency": {
      "command": "ENTER_FULL_FILE_PATH_TO_NODE_DOT_EXE_ON_YOUR_SYSTEM",
      "args": [
        "ENTER_FULL_FILE_PATH_TO_NANO_CURRENCY_JS_FILE_FROM_THIS_REPOSITORY"
      ],
      "env": {
        "NANO_RPC_URL": "ENTER_YOUR_NANO_RPC_URL",
        "NANO_WORK_GENERATION_URL": "ENTER_YOUR_NANO_WORK_GENERATION_URL",
        "NANO_PRIVATE_KEY": "ENTER_YOUR_NANO_PRIVATE_KEY",
        "NANO_MAX_SEND_AMOUNT": "ENTER_A_NEW_MAX_SEND_AMOUNT"
      }      
    }    
  }
}
```

Notes:

- ENTER_FULL_FILE_PATH_TO_NODE_DOT_EXE_ON_YOUR_SYSTEM should point to the `node.exe` executable in your Node.js installation e.g. `C:\\Program Files\\nodejs\\node.exe`
- ENTER_FULL_FILE_PATH_TO_NANO_CURRENCY_JS_FILE_FROM_THIS_REPOSITORY should point to the `nano-currency.js` file in this repository e.g. `C:\\projects\\nano-currency-mcp-server\\nano-currency.js`
- If you are using Windows you need to use double-backslashes in your file paths e.g. `C:\\Program Files\\nodejs\\node.exe`
- ENTER_YOUR_NANO_RPC_URL and ENTER_YOUR_NANO_WORK_GENERATION_URL may often be the same value, in that case just omit the NANO_WORK_GENERATION_URL line entirely. An example ENTER_YOUR_NANO_RPC_URL may look something like `http://localhost:7076`
- ENTER_YOUR_NANO_PRIVATE_KEY - This is 🚨*NOT A WALLET SEED*🚨 but rather the **private key** for a Nano address you control. This key is used when signing Nano transactions and to derive your Nano address from. Please test with a private key for an address containing a small amount of Nano.
- ENTER_A_NEW_MAX_SEND_AMOUNT is optional but you may use it if you want to override the default send maximum which is 0.01 nano (Ӿ0.01). Enter a numeric value only (without "nano" or "Ӿ"). It is recommended to not set this or set it lower than the default when testing, as it will prevent sending higher amounts of Nano than expected due to possible LLM hallucinations.


### 5. Save your changes to `claude_desktop_config.json` and restart Claude Desktop

### 6. If you have configured everything correctly you will see the following icon when you start up Claude Desktop

![Tools installed](assets/claude-desktop-tools-installed.png)

### Click on the icon to get a description of the tools installed

![Tool Descriptions](assets/claude-desktop-tool-descriptions.png)

### 7. Try out the tools by prompting Claude Desktop with nano-related prompts

https://github.com/user-attachments/assets/c877cc5a-0847-416c-b169-a988cac796f9

## 🚨 Disclaimer 🚨
As always when working with real world value, in this case Nano, **be careful** when using this software. The authors and contributors shall not be held liable for any use of this software's functionality, intentional or unintentional, that leads to an undesired lose of funds.

## License
MIT
```

--------------------------------------------------------------------------------
/Dockerfile:
--------------------------------------------------------------------------------

```dockerfile
# Generated by https://smithery.ai. See: https://smithery.ai/docs/config#dockerfile
FROM node:lts-alpine

WORKDIR /app

# install only production dependencies
COPY package*.json ./
RUN npm install --production

# copy source
COPY . .

# default command
CMD ["node", "nano-currency.js"]

```

--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------

```json
{
  "name": "nano-currency-mcp-server",
  "version": "1.0.1",
  "description": "Send Nano currency from AI agents/LLMs",
  "main": "nano-currency.js",
  "type": "module",
  "repository": {
    "type": "git",
    "url": "git+ssh://[email protected]/kilkelly/nano-currency-mcp-server.git"
  },
  "keywords": [
    "nano",
    "nanocurrency",
    "mcp",
    "model-context-protocol",
    "ai",
    "ai-agent",
    "ai-agents",
    "ai-assistant",
    "ai-assistants",
    "agent",
    "agents",
    "assistant",   
    "assistants",
    "llm",
    "llms",
    "crypto"
  ],
  "author": "Frank Kilkelly",
  "license": "MIT",
  "bugs": {
    "url": "https://github.com/kilkelly/nano-currency-mcp-server/issues"
  },
  "homepage": "https://github.com/kilkelly/nano-currency-mcp-server#readme",
  "dependencies": {
    "@modelcontextprotocol/sdk": "1.7.0",
    "bignumber.js": "9.1.2",
    "nanocurrency": "2.5.0",
    "zod": "3.24.2"
  }
}

```

--------------------------------------------------------------------------------
/smithery.yaml:
--------------------------------------------------------------------------------

```yaml
# Smithery configuration file: https://smithery.ai/docs/config#smitheryyaml

startCommand:
  type: stdio
  configSchema:
    # JSON Schema defining the configuration options for the MCP.
    type: object
    required:
      - nanoRpcUrl
    properties:
      nanoRpcUrl:
        type: string
        description: URL to communicate with a Nano node RPC (required)
      nanoWorkGenerationUrl:
        type: string
        description: URL to communicate with a Nano work generation RPC (optional)
      nanoPrivateKey:
        type: string
        description: Nano private key for signing transactions (optional for info tools,
          required for send)
      nanoMaxSendAmount:
        type: number
        description: Maximum amount of Nano allowed per transaction (optional)
  commandFunction:
    # A JS function that produces the CLI command based on the given config to start the MCP on stdio.
    |-
    (config) => ({
      command: 'node',
      args: ['nano-currency.js'],
      env: {
        NANO_RPC_URL: config.nanoRpcUrl,
        ...(config.nanoWorkGenerationUrl ? { NANO_WORK_GENERATION_URL: config.nanoWorkGenerationUrl } : {}),
        ...(config.nanoPrivateKey ? { NANO_PRIVATE_KEY: config.nanoPrivateKey } : {}),
        ...(config.nanoMaxSendAmount !== undefined ? { NANO_MAX_SEND_AMOUNT: String(config.nanoMaxSendAmount) } : {})
      }
    })
  exampleConfig:
    nanoRpcUrl: http://localhost:7076
    nanoWorkGenerationUrl: http://localhost:7076
    nanoPrivateKey: E3F2A1D4B7C89E6F1A2B3C4D5E6F7G8H9I0J1K2L3M4N5O6P7Q8R9S0T1U2V3W4
    nanoMaxSendAmount: 0.05

```

--------------------------------------------------------------------------------
/nano-currency.js:
--------------------------------------------------------------------------------

```javascript
/*
 * Nano Currency MCP Server
 * Provides tools to send Nano and retrieve account / block info via Nano node RPC
 *   nano_send - Send a specified amount of Nano currency
 *   nano_account_info - Retrieve detailed information about a specific Nano account/address
 *   nano_my_account_info - Retrieve detailed information about your predefined Nano account/address
 *   block_info - Retrieve detailed information about a specific Nano block
 * 
 * Required environment variables:
 *    - NANO_RPC_URL
 * 
 * Optional environment variables:
 *    - NANO_PRIVATE_KEY (Required for nano_send, nano_my_account_info. This is the private key for an address, NOT the wallet seed)
 *    - NANO_WORK_GENERATION_URL (Optional for nano_send; defaults to NANO_RPC_URL if not set)
 *    - NANO_MAX_SEND_AMOUNT (In nano units. Defaults to 0.01, use this variable to override the default)
 */

import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"
import { ErrorCode, McpError } from '@modelcontextprotocol/sdk/types.js'
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"
import z from 'zod'
import * as N from 'nanocurrency'
import BigNumber from "bignumber.js"

const SERVER_NAME = 'nano_currency'
const VERSION = '1.0.1'

const NANO_MAX_SEND_AMOUNT_DEFAULT = 0.01

const FETCH_COMMON = {
  method: "POST",
  headers: {
    'Content-Type': 'application/json'
  }
}

const ONE_SECOND = 1000 // in milliseconds
const ONE_MINUTE = 60 * ONE_SECOND

const NANO_RPC_URL_KEY = 'NANO_RPC_URL'
const NANO_WORK_GENERATION_URL_KEY = 'NANO_WORK_GENERATION_URL'

// -----

const NANO_PRIVATE_KEY_SCHEMA = z.string({
  required_error: `NANO_PRIVATE_KEY is required`,
})
.refine(val => N.checkKey(val), { message: `NANO_PRIVATE_KEY is not valid` })

// -----

try {
  const envVarsToCheck = ['NANO_RPC_URL']

  for (let i = 0; i < envVarsToCheck.length; i++) {
    z.string({
      required_error: `${envVarsToCheck[i]} is required`,
    }).parse(process.env[envVarsToCheck[i]])
  }

} catch (error) {
  console.error('Error:', error.message || error);
  process.exit(1);
}

// -----

async function rpcCall(envUrl, action, payload, timeout = ONE_MINUTE) {
  const controller = new AbortController()
  const timer = setTimeout(() => controller.abort(), timeout)
  try {
    const res = await fetch(process.env[envUrl], {
      ...FETCH_COMMON,
      signal: controller.signal,
      body: JSON.stringify({ action, ...payload }),
    })
    if (!res.ok) throw new Error(`HTTP ${res.status}: ${await res.text()}`)
    const json = await res.json()
    if (json.error) throw new Error(`RPC Error: ${json.error}`)
    return json
  } catch (error) {
    throw new Error(`[${envUrl}] ${error.message}`)
  } finally {
    clearTimeout(timer)
  }
}

// -----

function createTextResponse(text) {
  return {
    content: [
      {
        type: "text",
        text
      },
    ],
    metadata: { server: SERVER_NAME, version: VERSION }
  }
}

// -----

function createErrorResponse(error) {
  return {
    content: [
        {
            type: 'text',
            text: `Error: ${error instanceof Error ? error.message : String(error)}`
        },
    ],
    isError: true,
    errorCode: error instanceof McpError ? error.code : ErrorCode.INTERNAL_ERROR
  }
}

// -----

function convertRawToNano(amount) {
  return N.convert(String(amount), {from: 'raw', to: 'Nano'})
}

// -----

function convertNanoToRaw(amount) {  
  return N.convert(String(amount), {from: 'Nano', to: 'raw'})
}

// -----

function getAddress () {
  return N.deriveAddress(N.derivePublicKey(process.env.NANO_PRIVATE_KEY), { useNanoPrefix: true })
}

// -----

function friendlyAmount (balance) {
  return `${convertRawToNano(balance)} in nano units or ${balance} in raw units`
}

// -----

const server = new McpServer(
  {
    name: SERVER_NAME,
    version: VERSION
  }
)

// -----

async function getAccountInfo(address) {
  return (
    await rpcCall(
      NANO_RPC_URL_KEY,
      'account_info',
      {
        account: address,
        representative: 'true'
      }
    )
  )
}

// -----
// nano_send

const nano_send_parameters = {
  destination_address: z.string({
      required_error: `Destination address is required`,
    })
    .refine(address_ => N.checkAddress(address_), { message: 'Destination address is not valid' })
    .describe('Nano address to send the nano to'),
  amount: z.string({
      required_error: `Amount is required`,
    })
    .refine(amount_ => !isNaN(Number(amount_)) && Number(amount_) > 0, { message: 'Amount must be a positive number' })
    .transform(amount_ => Number(amount_))
    .refine(amount_ => amount_ <= (process.env.NANO_MAX_SEND_AMOUNT || NANO_MAX_SEND_AMOUNT_DEFAULT), { message: 'Maximum send amount exceeded' })
    .describe(`Amount of Nano to send (max ${(process.env.NANO_MAX_SEND_AMOUNT || NANO_MAX_SEND_AMOUNT_DEFAULT)} by default)`)
}

server.tool(
  'nano_send',
  'Send a specified amount of Nano currency from a predefined account to a destination Nano address.',
  nano_send_parameters,
  async function (parameters) {
    
    NANO_PRIVATE_KEY_SCHEMA.parse(process.env.NANO_PRIVATE_KEY)

    try {      
      let amountInRaw = convertNanoToRaw(parameters.amount)
      let sourceAddress = getAddress()
      let sourceAddressInfo = await getAccountInfo(sourceAddress)
      let balanceAfterSend = BigNumber(sourceAddressInfo.balance).minus(amountInRaw).toFixed()

      if (BigNumber(sourceAddressInfo.balance).lt(amountInRaw)) {
        throw new Error("Insufficient balance to perform Nano send transaction");
      }

      if (!sourceAddressInfo.frontier) {
        throw new Error("Source account has no frontier (unopened account)");
      }

      // ----- 

      let work = (
        await rpcCall(
          (process.env.NANO_WORK_GENERATION_URL ? NANO_WORK_GENERATION_URL_KEY : NANO_RPC_URL_KEY),
          'work_generate',
          { hash: sourceAddressInfo.frontier },
          5 * ONE_MINUTE
        )
      ).work      

      z.string({
        required_error: `Work is required`,
      }).refine(work_ => N.validateWork({ work: work_, blockHash: sourceAddressInfo.frontier }), { message: 'Computed Proof-of-Work for Nano transaction is not valid' }).parse(work)
  
      // -----
  
      let { block } = N.createBlock(process.env.NANO_PRIVATE_KEY, {
        representative: sourceAddressInfo.representative,
        balance: balanceAfterSend,
        work,
        link: parameters.destination_address,
        previous: sourceAddressInfo.frontier
      })

      let processJson = (
        await rpcCall(
          NANO_RPC_URL_KEY,
          'process',
          {
            json_block: 'true',
            subtype: 'send',
            block
          }
        )
      )        

      return createTextResponse(JSON.stringify(processJson))      
    }
    catch (error) {
      console.error('[nano_send] Error:', error.message || error);
      return createErrorResponse(error)
    }
  }
)

// -----
// nano_account_info

const nano_account_info_parameters = {
  address: z.string({ required_error: 'Address is required' })
    .refine(address_ => N.checkAddress(address_), { message: 'Nano address is not valid' })
    .describe("Nano address/account to get information about")
}

server.tool(
  'nano_account_info',
  'Retrieve detailed information about a specific Nano account/address, including balance (in Nano and raw units), representative, and frontier block.',
  nano_account_info_parameters,
  async function (parameters) {  
    try {
      let accountInfo =  await getAccountInfo(parameters.address)

      return createTextResponse(`The account information for ${parameters.address} is ` + JSON.stringify({ ...accountInfo, balance: friendlyAmount(accountInfo.balance) }))
    }
    catch (error) {
      console.error('[nano_account_info] Error:', error.message || error);
      return createErrorResponse(error)
    }    
  }
)

// -----
// nano_my_account_info

server.tool(
  'nano_my_account_info',
  'Retrieve detailed information about my Nano account/address, including balance (in Nano and raw units), representative, and frontier block. This is the account that is used to send Nano from.',
  {},
  async function () {  
    try {
      NANO_PRIVATE_KEY_SCHEMA.parse(process.env.NANO_PRIVATE_KEY)

      const myAddress = getAddress()
      let myAccountInfo =  await getAccountInfo(myAddress)

      return createTextResponse(`The account information for ${myAddress} is ` + JSON.stringify({ ...myAccountInfo, balance: friendlyAmount(myAccountInfo.balance) }))
    }
    catch (error) {
      console.error('[nano_my_account_info] Error:', error.message || error);
      return createErrorResponse(error)
    }    
  }
)

// -----
// block_info

const block_info_parameters = {
  hash: z.string({ required_error: 'Block hash is required' })
    .refine(hash_ => N.checkHash(hash_), { message: 'Block hash is not valid' })
    .describe("Hash for the Nano block to get information about")
}

server.tool(
  'block_info',
  'Retrieve detailed information about a specific Nano block.',
  block_info_parameters,
  async function (parameters) {  
    try {

      let blockInfoJson = (
        await rpcCall(
          NANO_RPC_URL_KEY,
          'block_info',
          {
            json_block: 'true',
            hash: parameters.hash
          }
        )
      )        

      return createTextResponse(
        `The block information for hash ${parameters.hash} is ` +
        JSON.stringify({
          ...blockInfoJson,
          amount: blockInfoJson.amount ? friendlyAmount(blockInfoJson.amount) : 'N/A',
          balance: blockInfoJson.balance ? friendlyAmount(blockInfoJson.balance) : 'N/A'
        })
      )
    }
    catch (error) {
      console.error('[block_info] Error:', error.message || error);
      return createErrorResponse(error)
    }    
  }
)

// -----
  
async function main() {
  const transport = new StdioServerTransport()
  await server.connect(transport)
  console.error(`${SERVER_NAME} MCP Server running on stdio`)
}

main().catch((error) => {
  console.error(`[startup] ${SERVER_NAME} MCP Server Error:`, error.message || error)
  process.exit(1)
});
```