Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 2 additions & 28 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -27,33 +27,7 @@
# TRONGRID_API_KEY=your_trongrid_api_key_here

# ------------------------------------------------------------------------------
# Wallet Configuration (choose ONE mode)
# Wallet Configuration
# ------------------------------------------------------------------------------

# --- Option A: Local Mode (Recommended) ---
# Encrypted key storage via agent-wallet SDK.
# Private keys are never exposed in environment variables.
# See README.md for setup instructions.

# Master password (same as the one used during `agent-wallet init`)
# AGENT_WALLET_PASSWORD=your_master_password

# Path to agent-wallet secrets directory (default: ~/.agent-wallet)
# AGENT_WALLET_DIR=~/.agent-wallet

# --- Option B: Static Mode ---
# Direct private key via environment variable. Less secure — key is in plaintext.
# Only used when Agent-Wallet env vars are NOT set.

# Raw private key (hex, with or without 0x prefix)
# TRON_PRIVATE_KEY=your_private_key_here

# Or use a BIP39 mnemonic instead of a raw key
# TRON_MNEMONIC=your twelve word mnemonic phrase here

# HD wallet derivation index (default: 0, used with TRON_MNEMONIC)
# TRON_ACCOUNT_INDEX=0

# --- Option C: Read-Only Mode ---
# If neither Local nor Static env vars are set, the server runs in
# read-only mode. Write tools (transfer, staking, etc.) will not be registered.
# Wallets are managed through agent-wallet file-backed configuration. Please see the agent-wallet docs.
12 changes: 5 additions & 7 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,17 @@ This document provides essential information for AI agents working on this repos

- **Sensitive Data**: NEVER hardcode private keys or mnemonics.
- **Env Vars**:
- `AGENT_WALLET_PASSWORD`: Master password for agent-wallet encrypted keystore (recommended).
- `AGENT_WALLET_DIR`: Wallet directory (optional, default: `~/.agent-wallet`).
- `TRON_PRIVATE_KEY`: Hex key for write operations.
- `TRON_MNEMONIC`: 12/24 word phrase (alternative to key).
- `TRONGRID_API_KEY`: Optional but recommended for Mainnet.
- This repository no longer reads or maps legacy `TRON_*` wallet variables.
- Wallet setup should follow `agent-wallet` file-backed configuration and the SDK-supported `AGENT_WALLET_*` settings.

## 🤖 MCP Specifics

- **Tools**: Every tool must have a clear `description` and `inputSchema`.
- **Conditional Registration**: Tools are conditionally registered based on whether a wallet is configured.
- **Registration**: Tools are registered up front. `readOnly` only hides write tools at registration time; wallet availability is checked when the handler runs.
- "Write" tools (state-changing) are automatically identified by `readOnlyHint: false`.
- Special "Read" tools that depend on wallet configuration (e.g., `get_wallet_address`) must specify `requiresWallet: true` in their annotations.
- **Annotations**: Use `annotations` (`title`, `readOnlyHint`, `requiresWallet`, etc.) to help LLMs understand tool impact and to control registration logic.
- Tools that need a configured wallet should say so in `description` (and return a clear error at runtime if the wallet is missing).
- **Annotations**: Use `annotations` (`title`, `readOnlyHint`, etc.) to help LLMs understand tool impact and runtime expectations.
- **Serialization**: Use the `utils.formatJson` helper to handle `BigInt` when returning tool results.

---
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

All notable changes to this project will be documented in this file.

## [1.1.7] - 2026-03-21

### Changed

- Tools and prompts are now registered up front; wallet availability is checked at execution time.
- Removed legacy `TRON_*` wallet mapping from this repository while keeping `agent-wallet`-managed wallet flows.
- Updated docs and tests to match the new wallet semantics and no-wallet runtime behavior.

## [1.1.6] - 2026-03-18

### Changed
Expand Down
59 changes: 11 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ Key capabilities:
- **Smart Contracts**: Interact with any TRON smart contract (Read/Write).
- **Tokens**: Transfer TRX and TRC20 tokens; check balances.
- **Address Management**: Convert between Hex (0x...) and Base58 (T...) formats.
- **Wallet Integration**: Agent-wallet (encrypted keystore), Private Key, and Mnemonic (BIP-39) wallets.
- **Wallet Integration**: Agent-wallet-managed file-backed wallets.
- **Multi-Network**: Seamless support for Mainnet, Nile, and Shasta.
- **Dynamic Access Control**: Automatically hides write tools if no wallet is configured or if `--readonly` mode is active.
- **Dynamic Access Control**: Write-capable tools stay registered; `--readonly` hides them, and wallet-dependent handlers fail at execution time if no wallet is available.

## Features

Expand Down Expand Up @@ -91,8 +91,7 @@ Key capabilities:

### Wallet & Security

- **Agent Wallet (Recommended)**: Encrypted key storage via agent-wallet SDK — private keys never leave the keystore.
- **Static Wallet**: Configure via `TRON_PRIVATE_KEY` or `TRON_MNEMONIC` environment variables.
- **Agent Wallet**: File-backed wallet storage via `agent-wallet` SDK.
- **HD Wallet**: Supports BIP-44 derivation path `m/44'/195'/0'/0/{index}`.
- **Signing**: Sign arbitrary messages and transactions.

Expand Down Expand Up @@ -122,9 +121,7 @@ npm install

### Environment Variables

**CRITICAL SECURITY NOTE**: For your security, **NEVER** save your private keys or mnemonics directly in the MCP configuration JSON files (like `claude_desktop_config.json` or `mcp.json`). Instead, set them as environment variables in your operating system or shell configuration.

To enable write operations (transfers, contract calls) and ensure reliable API access, you should configure the following variables.
**CRITICAL SECURITY NOTE**: For your security, **NEVER** save your private keys or mnemonics directly in the MCP configuration JSON files (like `claude_desktop_config.json` or `mcp.json`). For wallet setup, follow `agent-wallet`'s file-backed configuration and the SDK-supported `AGENT_WALLET_*` settings; use environment variables only for non-secret operational settings like `TRONGRID_API_KEY`.

#### Network Configuration

Expand All @@ -137,37 +134,11 @@ To enable write operations (transfers, contract calls) and ensure reliable API a

#### Wallet Configuration

Choose **one** of the following modes. If none is configured, the server runs in **read-only mode**.

**Option 1: Agent-Wallet Mode (Recommended)**

Private keys are encrypted at rest and never exposed in environment variables.
Wallets are managed through `agent-wallet` file-backed configuration. This repository no longer reads or maps legacy `TRON_PRIVATE_KEY` / `TRON_MNEMONIC` / `TRON_ACCOUNT_INDEX` wallet variables.

> **Prerequisites**: Install and configure [agent-wallet](https://github.com/BofAI/agent-wallet/blob/main/doc/getting-started.md)

```bash
export AGENT_WALLET_PASSWORD="<YOUR_MASTER_PASSWORD>"
export AGENT_WALLET_DIR="<YOUR_WALLET_DIR>" # Optional, default: ~/.agent-wallet
```

> `AGENT_WALLET_PASSWORD` must match the master password used during `agent-wallet`. If not set, agent-wallet mode is disabled and the server falls back to static mode or read-only mode.

**Option 2: Private Key**

```bash
export TRON_PRIVATE_KEY="<YOUR_PRIVATE_KEY_HERE>"
```

**Option 3: Mnemonic Phrase**

```bash
export TRON_MNEMONIC="<WORD1> <WORD2> ... <WORD12>"
export TRON_ACCOUNT_INDEX="0" # Optional, default: 0
```

> **Security Note**: Static modes expose keys in plaintext. **Only keep small amounts of funds** in these wallets — large balances carry a real **risk of theft**. Use Agent-Wallet Mode (Option 1) for any significant funds.

> See [`.env.example`](.env.example) for a complete list of all supported environment variables.
> See [`agent-wallet`](https://github.com/BofAI/agent-wallet) for wallet file formats, local setup, and the SDK-supported `AGENT_WALLET_*` settings.

### Server Configuration

Expand Down Expand Up @@ -228,14 +199,14 @@ npx vitest tests/core/services/contracts.test.ts # Contract services
npx vitest tests/core/services/account-resource.test.ts # Account resource services
npx vitest tests/core/services/staking.test.ts # Staking services

# Integration tests (real Nile RPC; write tests require AGENT_WALLET_PASSWORD or TRON_PRIVATE_KEY)
# Integration tests (real Nile RPC; write-operation coverage is skipped unless wallet support is explicitly enabled)
npx vitest tests/core/tools_integration.test.ts # Full tool flow on Nile
npx vitest tests/core/services/multicall.test.ts # Multicall integration
npx vitest tests/core/services/services.test.ts # Services integration
```

- **Unit tests** use mocks and do not need network or wallet.
- **Integration tests** (`tools_integration.test.ts`) call Nile RPC; most cases are read-only. Tests that broadcast transactions (e.g. `vote_witness`, `withdraw_balance`) run only when a wallet is configured (`AGENT_WALLET_PASSWORD` or `TRON_PRIVATE_KEY`) and are skipped otherwise.
- **Integration tests** (`tools_integration.test.ts`) call Nile RPC; most cases are read-only. Wallet-dependent handlers are exercised as runtime failures by default, while write-success paths require an explicit wallet fixture or equivalent setup.

### Client Configuration

Expand All @@ -249,12 +220,6 @@ Runs the latest version directly from npm via stdio transport.
claude mcp add mcp-server-tron -- npx -y @bankofai/mcp-server-tron
```

With environment variables:

```bash
claude mcp add -e AGENT_WALLET_PASSWORD=xxx -e TRONGRID_API_KEY=xxx mcp-server-tron -- npx -y @bankofai/mcp-server-tron
```

**Cursor** (`.cursor/mcp.json`):

```json
Expand All @@ -264,8 +229,7 @@ claude mcp add -e AGENT_WALLET_PASSWORD=xxx -e TRONGRID_API_KEY=xxx mcp-server-t
"command": "npx",
"args": ["-y", "@bankofai/mcp-server-tron"],
"env": {
"AGENT_WALLET_PASSWORD": "YOUR_PASSWORD (Or set in system env)",
"TRONGRID_API_KEY": "YOUR_KEY_HERE (Or set in system env)"
"TRONGRID_API_KEY": "YOUR_KEY_HERE"
}
}
}
Expand Down Expand Up @@ -496,9 +460,8 @@ claude mcp add -transport http mcp-server-tron https://tron-mcp-server.bankofai.

## Security Considerations

- **Private Keys & Mnemonics**: **NEVER** save your sensitive wallet information in plain text configuration files (like `mcp.json`). These files are often unencrypted and can be accidentally shared or committed to git. Use system environment variables which are more secure.
- **Fund Safety (Static Mode)**: If you use `TRON_PRIVATE_KEY` or `TRON_MNEMONIC`, keys are stored in plaintext environment variables. This carries a **real risk of fund theft** — environment variables can be leaked via shell history, process listings, or log files. **Only keep a small amount of funds** in these wallets. For wallets holding any significant value, always use [Agent-Wallet Mode](#option-1-agent-wallet-mode-recommended).
- **Shared Machines**: Be aware that on shared systems, environment variables might be visible to other users via `/proc` or system monitoring tools.
- **Private Keys & Mnemonics**: Keep wallet material inside `agent-wallet` file-backed configuration instead of plain text MCP config files. This repository no longer maps legacy `TRON_*` wallet variables; use `AGENT_WALLET_*` only when following the `agent-wallet` SDK documentation.
- **Shared Machines**: Be aware that plain environment variables can be visible to other users via `/proc` or system monitoring tools.
- **Testnets**: Always test on Nile or Shasta before performing operations on Mainnet.
- **Approvals**: Be cautious when approving token allowances via `write_contract`. Only approve what is necessary.

Expand Down
3 changes: 1 addition & 2 deletions mcp_example.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
"command": "npx",
"args": ["tsx", "src/index.ts"],
"env": {
"AGENT_WALLET_PASSWORD": "YOUR_PASSWORD_HERE",
"TRON_PRIVATE_KEY": "YOUR_PRIVATE_KEY_HERE (legacy, optional)"
"TRONGRID_API_KEY": "YOUR_KEY_HERE"
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "@bankofai/mcp-server-tron",
"mcpName": "io.github.bankofai/mcp-server-tron",
"module": "src/index.ts",
"module": "build/index.js",
"type": "module",
"version": "1.1.6",
"version": "1.1.7",
"description": "MCP server for TRON blockchain. Supports TRX/TRC20 transfers, smart contracts, and AI prompts.",
"bin": {
"mcp-server-tron": "./bin/cli.js"
Expand Down Expand Up @@ -53,7 +53,7 @@
"typescript": "^5.8.2"
},
"dependencies": {
"@bankofai/agent-wallet": "^2.2.0",
"@bankofai/agent-wallet": "^2.3.0",
"@modelcontextprotocol/sdk": "^1.22.0",
"@scure/bip32": "^2.0.1",
"@scure/bip39": "^2.0.1",
Expand Down
20 changes: 3 additions & 17 deletions server.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,16 @@
"url": "https://github.com/BofAI/mcp-server-tron",
"source": "github"
},
"version": "1.1.5",
"version": "1.1.7",
"packages": [
{
"registryType": "npm",
"identifier": "@bankofai/mcp-server-tron",
"version": "1.1.5",
"version": "1.1.7",
"transport": {
"type": "stdio"
},
"environmentVariables": [
{
"name": "AGENT_WALLET_PASSWORD",
"description": "Master password for agent-wallet encrypted keystore (recommended for write operations)",
"isRequired": false,
"format": "string",
"isSecret": true
},
{
"name": "TRON_PRIVATE_KEY",
"description": "Private key for the TRON wallet (legacy, optional)",
"isRequired": false,
"format": "string",
"isSecret": true
},
{
"name": "TRONGRID_API_KEY",
"description": "TronGrid API Key for higher rate limits (optional)",
Expand All @@ -40,4 +26,4 @@
]
}
]
}
}
19 changes: 6 additions & 13 deletions src/core/prompts.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { z } from "zod";
import * as services from "./services/index.js";

/**
* Register task-oriented prompts with the MCP server
Expand All @@ -19,9 +18,9 @@ import * as services from "./services/index.js";
*/
export function registerTRONPrompts(server: McpServer, options: { readOnly?: boolean } = {}) {
/**
* Helper to register a prompt with automatic wallet requirement detection.
* Prompts that guide write operations should only be registered if a wallet
* is configured and we are not in read-only mode.
* Helper to register a prompt with read-only gating.
* Prompts are registered up front; write guidance is hidden only in readonly
* mode and wallet availability is checked when the underlying tools run.
*/
const registerPrompt = <T extends z.ZodRawShape>(
name: string,
Expand All @@ -30,24 +29,18 @@ export function registerTRONPrompts(server: McpServer, options: { readOnly?: boo
argsSchema?: T;
},
handler: (args: z.infer<z.ZodObject<T>>) => any,
extra: { requiresWallet?: boolean; isReadOnly?: boolean } = {},
extra: { isReadOnly?: boolean } = {},
) => {
// Default to true: most prompts are informational and safe in readonly mode.
// This differs from tools.ts where the default is false (write-capable) because
// unregistered tools could mutate state, while prompts only guide the LLM.
const isReadOnly = extra.isReadOnly !== false;
const walletNeeded = extra.requiresWallet === true;

// 1. Skip if in read-only mode and the prompt is for write operations
if (options.readOnly && !isReadOnly) {
return;
}

// 2. Skip if the prompt needs a wallet but none is configured
if (walletNeeded && services.getActiveWalletId() === null) {
return;
}

server.registerPrompt(name, definition as any, handler as any);
};

Expand Down Expand Up @@ -122,7 +115,7 @@ ${
},
],
}),
{ requiresWallet: true, isReadOnly: false },
{ isReadOnly: false },
);

registerPrompt(
Expand Down Expand Up @@ -252,7 +245,7 @@ After execution:
],
};
},
{ requiresWallet: true, isReadOnly: false },
{ isReadOnly: false },
);

registerPrompt(
Expand Down
Loading
Loading