@missionsquad/mcp-server-tron 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (193) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +537 -0
  3. package/bin/cli.js +51 -0
  4. package/build/core/chains.d.ts +17 -0
  5. package/build/core/chains.js +87 -0
  6. package/build/core/chains.js.map +1 -0
  7. package/build/core/prompts.d.ts +19 -0
  8. package/build/core/prompts.js +485 -0
  9. package/build/core/prompts.js.map +1 -0
  10. package/build/core/resources.d.ts +14 -0
  11. package/build/core/resources.js +42 -0
  12. package/build/core/resources.js.map +1 -0
  13. package/build/core/services/account-data.d.ts +144 -0
  14. package/build/core/services/account-data.js +228 -0
  15. package/build/core/services/account-data.js.map +1 -0
  16. package/build/core/services/account-resource.d.ts +56 -0
  17. package/build/core/services/account-resource.js +133 -0
  18. package/build/core/services/account-resource.js.map +1 -0
  19. package/build/core/services/account.d.ts +141 -0
  20. package/build/core/services/account.js +191 -0
  21. package/build/core/services/account.js.map +1 -0
  22. package/build/core/services/address.d.ts +8 -0
  23. package/build/core/services/address.js +52 -0
  24. package/build/core/services/address.js.map +1 -0
  25. package/build/core/services/agent-wallet.d.ts +62 -0
  26. package/build/core/services/agent-wallet.js +234 -0
  27. package/build/core/services/agent-wallet.js.map +1 -0
  28. package/build/core/services/balance.d.ts +26 -0
  29. package/build/core/services/balance.js +60 -0
  30. package/build/core/services/balance.js.map +1 -0
  31. package/build/core/services/blocks.d.ts +25 -0
  32. package/build/core/services/blocks.js +65 -0
  33. package/build/core/services/blocks.js.map +1 -0
  34. package/build/core/services/broadcast.d.ts +13 -0
  35. package/build/core/services/broadcast.js +24 -0
  36. package/build/core/services/broadcast.js.map +1 -0
  37. package/build/core/services/clients.d.ts +5 -0
  38. package/build/core/services/clients.js +29 -0
  39. package/build/core/services/clients.js.map +1 -0
  40. package/build/core/services/contract-data.d.ts +31 -0
  41. package/build/core/services/contract-data.js +54 -0
  42. package/build/core/services/contract-data.js.map +1 -0
  43. package/build/core/services/contracts.d.ts +108 -0
  44. package/build/core/services/contracts.js +482 -0
  45. package/build/core/services/contracts.js.map +1 -0
  46. package/build/core/services/events.d.ts +56 -0
  47. package/build/core/services/events.js +99 -0
  48. package/build/core/services/events.js.map +1 -0
  49. package/build/core/services/governance.d.ts +78 -0
  50. package/build/core/services/governance.js +207 -0
  51. package/build/core/services/governance.js.map +1 -0
  52. package/build/core/services/index.d.ts +28 -0
  53. package/build/core/services/index.js +81 -0
  54. package/build/core/services/index.js.map +1 -0
  55. package/build/core/services/mempool.d.ts +12 -0
  56. package/build/core/services/mempool.js +32 -0
  57. package/build/core/services/mempool.js.map +1 -0
  58. package/build/core/services/multicall-abi.d.ts +55 -0
  59. package/build/core/services/multicall-abi.js +61 -0
  60. package/build/core/services/multicall-abi.js.map +1 -0
  61. package/build/core/services/nodes.d.ts +8 -0
  62. package/build/core/services/nodes.js +18 -0
  63. package/build/core/services/nodes.js.map +1 -0
  64. package/build/core/services/proposals.d.ts +33 -0
  65. package/build/core/services/proposals.js +95 -0
  66. package/build/core/services/proposals.js.map +1 -0
  67. package/build/core/services/query.d.ts +34 -0
  68. package/build/core/services/query.js +60 -0
  69. package/build/core/services/query.js.map +1 -0
  70. package/build/core/services/staking.d.ts +40 -0
  71. package/build/core/services/staking.js +113 -0
  72. package/build/core/services/staking.js.map +1 -0
  73. package/build/core/services/tokens.d.ts +22 -0
  74. package/build/core/services/tokens.js +68 -0
  75. package/build/core/services/tokens.js.map +1 -0
  76. package/build/core/services/transactions.d.ts +16 -0
  77. package/build/core/services/transactions.js +42 -0
  78. package/build/core/services/transactions.js.map +1 -0
  79. package/build/core/services/transfer.d.ts +24 -0
  80. package/build/core/services/transfer.js +84 -0
  81. package/build/core/services/transfer.js.map +1 -0
  82. package/build/core/services/trongrid-client.d.ts +14 -0
  83. package/build/core/services/trongrid-client.js +19 -0
  84. package/build/core/services/trongrid-client.js.map +1 -0
  85. package/build/core/services/utils.d.ts +13 -0
  86. package/build/core/services/utils.js +39 -0
  87. package/build/core/services/utils.js.map +1 -0
  88. package/build/core/services/wallet.d.ts +13 -0
  89. package/build/core/services/wallet.js +18 -0
  90. package/build/core/services/wallet.js.map +1 -0
  91. package/build/core/tools/account-data.d.ts +2 -0
  92. package/build/core/tools/account-data.js +253 -0
  93. package/build/core/tools/account-data.js.map +1 -0
  94. package/build/core/tools/account-resource.d.ts +2 -0
  95. package/build/core/tools/account-resource.js +269 -0
  96. package/build/core/tools/account-resource.js.map +1 -0
  97. package/build/core/tools/account.d.ts +2 -0
  98. package/build/core/tools/account.js +451 -0
  99. package/build/core/tools/account.js.map +1 -0
  100. package/build/core/tools/address.d.ts +2 -0
  101. package/build/core/tools/address.js +45 -0
  102. package/build/core/tools/address.js.map +1 -0
  103. package/build/core/tools/balance.d.ts +2 -0
  104. package/build/core/tools/balance.js +94 -0
  105. package/build/core/tools/balance.js.map +1 -0
  106. package/build/core/tools/block.d.ts +2 -0
  107. package/build/core/tools/block.js +74 -0
  108. package/build/core/tools/block.js.map +1 -0
  109. package/build/core/tools/broadcast.d.ts +2 -0
  110. package/build/core/tools/broadcast.js +102 -0
  111. package/build/core/tools/broadcast.js.map +1 -0
  112. package/build/core/tools/contract-data.d.ts +2 -0
  113. package/build/core/tools/contract-data.js +159 -0
  114. package/build/core/tools/contract-data.js.map +1 -0
  115. package/build/core/tools/contract.d.ts +2 -0
  116. package/build/core/tools/contract.js +600 -0
  117. package/build/core/tools/contract.js.map +1 -0
  118. package/build/core/tools/event.d.ts +2 -0
  119. package/build/core/tools/event.js +159 -0
  120. package/build/core/tools/event.js.map +1 -0
  121. package/build/core/tools/governance.d.ts +6 -0
  122. package/build/core/tools/governance.js +424 -0
  123. package/build/core/tools/governance.js.map +1 -0
  124. package/build/core/tools/index.d.ts +15 -0
  125. package/build/core/tools/index.js +93 -0
  126. package/build/core/tools/index.js.map +1 -0
  127. package/build/core/tools/mempool.d.ts +2 -0
  128. package/build/core/tools/mempool.js +116 -0
  129. package/build/core/tools/mempool.js.map +1 -0
  130. package/build/core/tools/network.d.ts +2 -0
  131. package/build/core/tools/network.js +114 -0
  132. package/build/core/tools/network.js.map +1 -0
  133. package/build/core/tools/node.d.ts +2 -0
  134. package/build/core/tools/node.js +75 -0
  135. package/build/core/tools/node.js.map +1 -0
  136. package/build/core/tools/proposals.d.ts +6 -0
  137. package/build/core/tools/proposals.js +219 -0
  138. package/build/core/tools/proposals.js.map +1 -0
  139. package/build/core/tools/query.d.ts +2 -0
  140. package/build/core/tools/query.js +399 -0
  141. package/build/core/tools/query.js.map +1 -0
  142. package/build/core/tools/staking.d.ts +2 -0
  143. package/build/core/tools/staking.js +281 -0
  144. package/build/core/tools/staking.js.map +1 -0
  145. package/build/core/tools/transaction.d.ts +2 -0
  146. package/build/core/tools/transaction.js +65 -0
  147. package/build/core/tools/transaction.js.map +1 -0
  148. package/build/core/tools/transfer.d.ts +2 -0
  149. package/build/core/tools/transfer.js +101 -0
  150. package/build/core/tools/transfer.js.map +1 -0
  151. package/build/core/tools/types.d.ts +13 -0
  152. package/build/core/tools/types.js +2 -0
  153. package/build/core/tools/types.js.map +1 -0
  154. package/build/core/tools/wallet.d.ts +2 -0
  155. package/build/core/tools/wallet.js +172 -0
  156. package/build/core/tools/wallet.js.map +1 -0
  157. package/build/index.d.ts +1 -0
  158. package/build/index.js +21 -0
  159. package/build/index.js.map +1 -0
  160. package/build/middleware/auth.d.ts +16 -0
  161. package/build/middleware/auth.js +44 -0
  162. package/build/middleware/auth.js.map +1 -0
  163. package/build/oauth/OAuthService.d.ts +100 -0
  164. package/build/oauth/OAuthService.js +507 -0
  165. package/build/oauth/OAuthService.js.map +1 -0
  166. package/build/oauth/page.d.ts +1 -0
  167. package/build/oauth/page.js +255 -0
  168. package/build/oauth/page.js.map +1 -0
  169. package/build/oauth/types.d.ts +65 -0
  170. package/build/oauth/types.js +2 -0
  171. package/build/oauth/types.js.map +1 -0
  172. package/build/server/http-app.d.ts +9 -0
  173. package/build/server/http-app.js +128 -0
  174. package/build/server/http-app.js.map +1 -0
  175. package/build/server/http-server.d.ts +1 -0
  176. package/build/server/http-server.js +35 -0
  177. package/build/server/http-server.js.map +1 -0
  178. package/build/server/oauth-routes.d.ts +7 -0
  179. package/build/server/oauth-routes.js +157 -0
  180. package/build/server/oauth-routes.js.map +1 -0
  181. package/build/server/server.d.ts +9 -0
  182. package/build/server/server.js +54 -0
  183. package/build/server/server.js.map +1 -0
  184. package/build/tenant/TenantManager.d.ts +35 -0
  185. package/build/tenant/TenantManager.js +167 -0
  186. package/build/tenant/TenantManager.js.map +1 -0
  187. package/build/tenant/context.d.ts +11 -0
  188. package/build/tenant/context.js +23 -0
  189. package/build/tenant/context.js.map +1 -0
  190. package/build/tenant/types.d.ts +16 -0
  191. package/build/tenant/types.js +2 -0
  192. package/build/tenant/types.js.map +1 -0
  193. package/package.json +95 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 bankofai
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,537 @@
1
+ # MCP Server Tron
2
+
3
+ ![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)
4
+ ![TRON Network](https://img.shields.io/badge/Network-TRON-red)
5
+ ![TypeScript](https://img.shields.io/badge/TypeScript-5.8+-3178C6)
6
+ ![MCP](https://img.shields.io/badge/MCP-1.22.0+-blue)
7
+ ![TronWeb](https://img.shields.io/badge/TronWeb-6.0+-green)
8
+
9
+ A comprehensive Model Context Protocol (MCP) server that provides blockchain services for the TRON network. This server enables AI agents to interact with TRON blockchain with a unified interface through tools and AI-guided prompts for TRX, TRC20 tokens and smart contracts.
10
+
11
+ ## Contents
12
+
13
+ - [Overview](#overview)
14
+ - [Features](#features)
15
+ - [Supported Networks](#supported-networks)
16
+ - [Prerequisites](#prerequisites)
17
+ - [Installation](#installation)
18
+ - [Configuration](#configuration)
19
+ - [Environment Variables](#environment-variables)
20
+ - [Server Configuration](#server-configuration)
21
+ - [Usage](#usage)
22
+ - [API Reference](#api-reference)
23
+ - [Tools](#tools)
24
+ - [Prompts](#prompts)
25
+ - [Security Considerations](#security-considerations)
26
+ - [Project Structure](#project-structure)
27
+ - [License](#license)
28
+
29
+ ## Overview
30
+
31
+ The MCP TRON Server leverages the Model Context Protocol to provide blockchain services to AI agents. It fully supports the TRON ecosystem using `tronweb`.
32
+
33
+ Key capabilities:
34
+
35
+ - **Blockchain Data**: Read blocks, transactions, and chain parameters (Energy/Bandwidth costs).
36
+ - **Smart Contracts**: Interact with any TRON smart contract (Read/Write).
37
+ - **Tokens**: Transfer TRX and TRC20 tokens; check balances.
38
+ - **Address Management**: Convert between Hex (0x...) and Base58 (T...) formats.
39
+ - **Wallet Integration**: Agent-wallet-managed file-backed wallets.
40
+ - **Multi-Network**: Seamless support for Mainnet, Nile, and Shasta.
41
+ - **Dynamic Access Control**: Write-capable tools stay registered; `--readonly` hides them, and wallet-dependent handlers fail at execution time if no wallet is available.
42
+
43
+ ## Features
44
+
45
+ ### Blockchain Data Access
46
+
47
+ - **TRON network support**: Mainnet, Nile, Shasta.
48
+ - **Chain information**: Block number, Chain ID, RPC endpoints.
49
+ - **Block data**: Access by number or hash.
50
+ - **Transaction details**: Detailed info including resource usage (Energy/Bandwidth).
51
+ - **Resource Costs**: Query current chain parameters for Energy and Bandwidth prices.
52
+
53
+ ### Token Services
54
+
55
+ - **Native TRX**: Check balance and transfer.
56
+ - **TRC20 Tokens**:
57
+ - Check balances.
58
+ - Transfer tokens.
59
+ - Get token metadata (name, symbol, decimals).
60
+
61
+ ### Address Services
62
+
63
+ - **Format Conversion**: Convert between Hex (`41...` or `0x...`) and Base58 (`T...`) formats.
64
+ - **Validation**: Verify if an address is valid on TRON.
65
+
66
+ ### Smart Contract Interactions
67
+
68
+ - **Read Contract**: Call `view` and `pure` functions.
69
+ - **Write Contract**: Execute state-changing functions.
70
+ - **ABI Fetching**: Automatically fetches ABI from the blockchain for verified contracts.
71
+
72
+ ### Governance & Proposals
73
+
74
+ - **Super Representatives**: List, vote, create/update witnesses, manage brokerage.
75
+ - **Proposals**: List, view, create, approve, and delete governance proposals.
76
+ - **Rewards**: Query and withdraw SR voting rewards.
77
+
78
+ ### Events & Data Queries
79
+
80
+ - **Contract Events**: Query events by transaction, contract address, or block number.
81
+ - **Account Data**: Transaction history, TRC20 transfers, internal transactions, token balances (via TronGrid).
82
+ - **Contract Data**: Contract transaction history, internal transactions, token holder lists.
83
+ - **Mempool**: View pending transactions and pool size.
84
+ - **Node Info**: List connected nodes and query node details.
85
+
86
+ ### Staking & Resource Delegation (Stake 2.0)
87
+
88
+ - **Staking**: Freeze/unfreeze TRX for Energy or Bandwidth.
89
+ - **Delegation**: Delegate and undelegate resources to other accounts.
90
+ - **Queries**: Available unfreeze count, withdrawable amounts, delegation details.
91
+
92
+ ### Wallet & Security
93
+
94
+ - **Agent Wallet**: File-backed wallet storage via `agent-wallet` SDK.
95
+ - **HD Wallet**: Supports BIP-44 derivation path `m/44'/195'/0'/0/{index}`.
96
+ - **Signing**: Sign arbitrary messages and transactions.
97
+
98
+ ## Supported Networks
99
+
100
+ - **Mainnet**: `mainnet` (Default)
101
+ - **Nile Testnet**: `nile`
102
+ - **Shasta Testnet**: `shasta`
103
+
104
+ ## Prerequisites
105
+
106
+ - [Node.js](https://nodejs.org/) 20.0.0 or higher
107
+ - Optional: [TronGrid API key](https://www.trongrid.io/) to avoid rate limiting on Mainnet.
108
+
109
+ ## Installation
110
+
111
+ ```bash
112
+ # Clone the repository
113
+ git clone https://github.com/MissionSquad/mcp-server-tron.git
114
+ cd mcp-server-tron
115
+
116
+ # Install dependencies
117
+ npm install
118
+ ```
119
+
120
+ ## Configuration
121
+
122
+ ### Environment Variables
123
+
124
+ **CRITICAL SECURITY NOTE**: For your security, **NEVER** save your private keys or mnemonics directly in MCP client configuration JSON files. In HTTP tenant mode, this server is now an OAuth2 authorization server and issues bearer access tokens after browser-wallet proof. Managed tenant wallets are stored server-side using `agent-wallet`.
125
+
126
+ #### OAuth / HTTP Tenant Configuration
127
+
128
+ - `MCP_PUBLIC_ORIGIN`: Required in HTTP mode. Public origin used as OAuth issuer and resource base.
129
+ - `JWT_SECRET`: Required in HTTP mode. Signs OAuth access tokens.
130
+ - `MCP_TENANT_MASTER_SECRET`: Required in HTTP mode. Derives deterministic per-tenant wallet encryption passwords.
131
+ - `MCP_DATA_DIR`: Optional. Directory for tenant wallet storage and refresh-token persistence.
132
+ - `MCP_AUTH_CHALLENGE_TTL_SECONDS`: Optional. Wallet-sign challenge TTL.
133
+ - `MCP_OAUTH_AUTH_CODE_TTL_SECONDS`: Optional. Authorization-code TTL.
134
+ - `MCP_OAUTH_ACCESS_TOKEN_TTL_SECONDS`: Optional. OAuth access-token TTL.
135
+ - `MCP_OAUTH_REFRESH_TOKEN_TTL_SECONDS`: Optional. OAuth refresh-token TTL.
136
+
137
+ #### Network Configuration
138
+
139
+ - `TRONGRID_API_KEY`: (Optional) Your TronGrid API key.
140
+ - **Why**: TRON mainnet RPCs have strict rate limits. When `TRONGRID_API_KEY` is set (and non-empty), the server uses `https://api.trongrid.io` as the default RPC hosts.
141
+ - **Fallback**: When `TRONGRID_API_KEY` is not set, the server uses `https://hptg.bankofai.io` as the default RPC hosts for `mainnet`.
142
+ - **Usage**:
143
+ ```bash
144
+ export TRONGRID_API_KEY="<YOUR_TRONGRID_API_KEY_HERE>"
145
+ ```
146
+ - Optional explicit RPC overrides are also supported:
147
+ - `TRON_MAINNET_FULL_NODE`
148
+ - `TRON_MAINNET_SOLIDITY_NODE`
149
+ - `TRON_MAINNET_EVENT_SERVER`
150
+ - `TRON_NILE_FULL_NODE`
151
+ - `TRON_NILE_SOLIDITY_NODE`
152
+ - `TRON_NILE_EVENT_SERVER`
153
+ - `TRON_SHASTA_FULL_NODE`
154
+ - `TRON_SHASTA_SOLIDITY_NODE`
155
+ - `TRON_SHASTA_EVENT_SERVER`
156
+
157
+ #### Wallet Configuration
158
+
159
+ Wallets are managed through `agent-wallet` file-backed configuration. In HTTP mode, the server also creates and stores one managed wallet per tenant under its own tenant directory. This repository no longer reads or maps legacy `TRON_PRIVATE_KEY` / `TRON_MNEMONIC` / `TRON_ACCOUNT_INDEX` wallet variables.
160
+
161
+ > **Prerequisites**: Install and configure [agent-wallet](https://github.com/MissionSquad/agent-wallet/blob/main/doc/getting-started.md)
162
+
163
+ > See [`agent-wallet`](https://github.com/MissionSquad/agent-wallet) for wallet file formats, local setup, and the SDK-supported `AGENT_WALLET_*` settings.
164
+
165
+ ### Server Configuration
166
+
167
+ The server runs on port **3001** by default in HTTP mode.
168
+
169
+ ## Usage
170
+
171
+ ### Running Locally
172
+
173
+ ```bash
174
+ # Start in stdio mode (for MCP clients like Claude Desktop/Cursor)
175
+ npm start
176
+
177
+ # Start in readonly mode (disables write tools)
178
+ npm start -- --readonly
179
+
180
+ # Start in stateless HTTP mode (Streamable HTTP)
181
+ npm run start:http
182
+ ```
183
+
184
+ ### OAuth2 Compatibility
185
+
186
+ HTTP mode is now designed for MissionSquad external MCP compatibility:
187
+
188
+ - transport: `streamable_http`
189
+ - auth mode: `oauth2`
190
+ - grant: authorization code + PKCE
191
+ - registration mode: CIMD
192
+
193
+ HTTP OAuth endpoints:
194
+
195
+ - `GET /.well-known/oauth-authorization-server`
196
+ - `GET /.well-known/oauth-protected-resource`
197
+ - `GET /oauth/authorize`
198
+ - `POST /oauth/authorize/challenge`
199
+ - `POST /oauth/authorize/verify`
200
+ - `POST /oauth/authorize/create-wallet`
201
+ - `POST /oauth/token`
202
+
203
+ The authorization page supports:
204
+
205
+ - connecting an existing managed wallet by browser-wallet signature proof
206
+ - creating a new managed wallet during authorization and revealing the private key once
207
+
208
+ ### Docker
209
+
210
+ Build the image:
211
+
212
+ ```bash
213
+ docker build -t mcp-server-tron:test .
214
+ ```
215
+
216
+ Run the container with local logs mounted:
217
+
218
+ ```bash
219
+ docker run -d \
220
+ --name mcp-tron \
221
+ -p 3001:3001 \
222
+ -e MCP_HOST=0.0.0.0 \
223
+ -e MCP_PORT=3001 \
224
+ -e MCP_LOG_DIR=/app/logs \
225
+ -v "$(pwd)/logs:/app/logs" \
226
+ mcp-server-tron:test
227
+ ```
228
+
229
+ Docker logs are written to the mounted `logs/` directory and are named by date, for example:
230
+
231
+ - `logs/mcp-server-tron-2026-03-18-combined.log`
232
+ - `logs/mcp-server-tron-2026-03-18-error.log`
233
+
234
+ ### Testing
235
+
236
+ The project includes a comprehensive test suite with unit tests and integration tests (using the Nile testnet).
237
+
238
+ ```bash
239
+ # Run all tests
240
+ npm test
241
+
242
+ # Unit tests (mocked services, no network)
243
+ npx vitest tests/core/tools.test.ts # All MCP tools registration & handlers
244
+ npx vitest tests/core/services/contracts.test.ts # Contract services
245
+ npx vitest tests/core/services/account-resource.test.ts # Account resource services
246
+ npx vitest tests/core/services/staking.test.ts # Staking services
247
+
248
+ # Integration tests (real Nile RPC; write-operation coverage is skipped unless wallet support is explicitly enabled)
249
+ npx vitest tests/core/tools_integration.test.ts # Full tool flow on Nile
250
+ npx vitest tests/core/services/multicall.test.ts # Multicall integration
251
+ npx vitest tests/core/services/services.test.ts # Services integration
252
+ ```
253
+
254
+ - **Unit tests** use mocks and do not need network or wallet.
255
+ - **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.
256
+
257
+ ### Client Configuration
258
+
259
+ #### Option A: Quick Start (Recommended)
260
+
261
+ Runs the latest version directly from npm via stdio transport.
262
+
263
+ **Claude Code:**
264
+
265
+ ```bash
266
+ claude mcp add mcp-server-tron -- npx -y @missionsquad/mcp-server-tron
267
+ ```
268
+
269
+ **Cursor** (`.cursor/mcp.json`):
270
+
271
+ ```json
272
+ {
273
+ "mcpServers": {
274
+ "mcp-server-tron": {
275
+ "command": "npx",
276
+ "args": ["-y", "@missionsquad/mcp-server-tron"],
277
+ "env": {
278
+ "TRONGRID_API_KEY": "YOUR_KEY_HERE"
279
+ }
280
+ }
281
+ }
282
+ }
283
+ ```
284
+
285
+ #### Option B: Official Hosted Server (Remote)
286
+
287
+ Connect to the official hosted server at `https://mcp-tron.missionsquad.ai`. No installation required, readonly mode, stateless HTTP.
288
+
289
+ **Claude Code:**
290
+
291
+ ```bash
292
+ claude mcp add -transport http mcp-tron https://mcp-tron.missionsquad.ai/mcp
293
+ ```
294
+
295
+ **Cursor** (`.cursor/mcp.json`):
296
+
297
+ ```json
298
+ {
299
+ "mcpServers": {
300
+ "mcp-tron": {
301
+ "url": "https://mcp-tron.missionsquad.ai/mcp"
302
+ }
303
+ }
304
+ }
305
+ ```
306
+
307
+ ## API Reference
308
+
309
+ ### Tools
310
+
311
+ #### Wallet & Address
312
+
313
+ | Tool Name | Description | Key Parameters |
314
+ | :------------------- | :-------------------------------------------------- | :------------- |
315
+ | `get_wallet_address` | Get the configured wallet's address (Base58 & Hex). | - |
316
+ | `list_wallets` | List all available wallets with IDs and addresses. | - |
317
+ | `select_wallet` | Switch the active wallet at runtime (agent-wallet mode). | `walletId` |
318
+ | `convert_address` | Convert between Hex and Base58 formats. | `address` |
319
+
320
+ #### Network & Resources
321
+
322
+ | Tool Name | Description | Key Parameters |
323
+ | :----------------------- | :-------------------------------------- | :------------- |
324
+ | `get_chain_info` | Get current block and chain ID. | `network` |
325
+ | `get_chain_parameters` | Get current Energy and Bandwidth costs. | `network` |
326
+ | `get_energy_prices` | Query historical energy unit price. | `network` |
327
+ | `get_bandwidth_prices` | Query historical bandwidth unit price. | `network` |
328
+ | `get_burn_trx` | Query total TRX burned from fees. | `network` |
329
+ | `get_supported_networks` | List available networks. | - |
330
+
331
+ #### Blocks & Transactions
332
+
333
+ | Tool Name | Description | Key Parameters |
334
+ | :--------------------- | :----------------------------------------- | :--------------------------- |
335
+ | `get_block` | Fetch block by number or hash. | `blockIdentifier`, `network` |
336
+ | `get_latest_block` | Get the latest block. | `network` |
337
+ | `get_transaction` | Get transaction details by hash. | `txHash`, `network` |
338
+ | `get_transaction_info` | Get receipt/info including resource usage. | `txHash`, `network` |
339
+ | `get_block_by_num` | Query block by block height. | `num`, `network` |
340
+ | `get_block_by_id` | Query block by block ID (hash). | `value`, `network` |
341
+ | `get_block_by_latest_num` | Get latest N blocks (solidified). | `num`, `network` |
342
+ | `get_block_by_limit_next` | Get blocks in range [startNum, endNum). | `startNum`, `endNum`, `network` |
343
+ | `get_now_block` | Get the current latest block info. | `network` |
344
+ | `get_transaction_by_id` | Query transaction status/content by txID. | `value`, `network` |
345
+ | `get_transaction_info_by_id` | Query transaction receipt by txID. | `value`, `network` |
346
+ | `get_transaction_info_by_block_num` | Get receipts for all txs in a block. | `num`, `network` |
347
+ | `get_approved_list` | Query the list of accounts that signed a transaction. | `transaction`, `network` |
348
+ | `get_block_balance` | Get all balance change operations in a block. | `hash`, `number`, `network` |
349
+
350
+ #### Broadcast & Transaction Building (Write)
351
+
352
+ | Tool Name | Description | Key Parameters |
353
+ | :---------------------- | :----------------------------------------------------------------- | :---------------------------------- |
354
+ | `create_transaction` | Create an unsigned TRX transfer transaction. | `ownerAddress`, `toAddress`, `amount`, `network` |
355
+ | `broadcast_transaction` | Broadcast a signed transaction JSON object to the TRON network. | `transaction`, `network` |
356
+ | `broadcast_hex` | Broadcast a signed protobuf-encoded transaction hex string. | `transaction`, `network` |
357
+
358
+ #### Balances
359
+
360
+ | Tool Name | Description | Key Parameters |
361
+ | :------------------ | :-------------------------------------- | :----------------------------------- |
362
+ | `get_balance` | Get TRX balance for an address. | `address`, `network` |
363
+ | `get_token_balance` | Get TRC20 token balance for an address. | `address`, `tokenAddress`, `network` |
364
+
365
+ #### Transfers (Write)
366
+
367
+ | Tool Name | Description | Key Parameters |
368
+ | :--------------- | :------------------------------- | :---------------------------------------- |
369
+ | `transfer_trx` | Send TRX (Native) to an address. | `to`, `amount`, `network` |
370
+ | `transfer_trc20` | Send TRC20 tokens to an address. | `tokenAddress`, `to`, `amount`, `network` |
371
+
372
+ #### Smart Contracts
373
+
374
+ | Tool Name | Description | Key Parameters |
375
+ | :------------------- | :-------------------------------------------------------- | :------------------------------------------------------------ |
376
+ | `read_contract` | Call read-only (`view`/`pure`) functions. | `contractAddress`, `functionName`, `args`, `network` |
377
+ | `get_contract` | Get raw contract metadata (ABI, bytecode) from chain. | `contractAddress`, `network` |
378
+ | `get_contract_info` | Get ABI, function list and raw metadata. | `contractAddress`, `network` |
379
+ | `fetch_contract_abi`| Fetch ABI entry array for verified contracts. | `contractAddress`, `network` |
380
+ | `multicall` | Execute multiple read calls in one batch. | `calls`, `network` |
381
+ | `write_contract` | Execute state-changing contract functions. | `contractAddress`, `functionName`, `args`, `value`, `network` |
382
+ | `deploy_contract` | Deploy a smart contract with ABI and bytecode. | `abi`, `bytecode`, `args`, `network` |
383
+ | `estimate_energy` | Estimate energy consumption for a contract call. | `address`, `functionName`, `abi`, `network` |
384
+ | `update_contract_setting` | Update consume_user_resource_percent (creator only). | `contractAddress`, `consumeUserResourcePercent`, `network` |
385
+ | `update_energy_limit` | Update originEnergyLimit (creator only). | `contractAddress`, `originEnergyLimit`, `network` |
386
+ | `clear_abi` | Clear on-chain ABI metadata (creator only). | `contractAddress`, `network` |
387
+
388
+ #### Account Management
389
+
390
+ | Tool Name | Description | Key Parameters |
391
+ | :------------------------------ | :-------------------------------------------------------------- | :----------------------------------------------------- |
392
+ | `get_account` | Get full account info (balance, resources, permissions, etc.). | `address`, `network` |
393
+ | `get_account_balance` | Get TRX balance at a specific block height. | `address`, `blockHash`, `blockNumber`, `network` |
394
+ | `generate_account` | Generate a new TRON keypair offline. | - |
395
+ | `validate_address` | Validate a TRON address and detect format. | `address` |
396
+ | `get_account_net` | Get bandwidth information for an account. | `address`, `network` |
397
+ | `get_account_resource` | Get energy, bandwidth, and delegation details. | `address`, `network` |
398
+ | `get_delegated_resource` | Query delegated resources between two accounts (Stake 2.0). | `fromAddress`, `toAddress`, `network` |
399
+ | `get_delegated_resource_index` | Query delegation index (who delegated to/from this account). | `address`, `network` |
400
+ | `create_account` | Activate a new account on-chain (costs bandwidth). | `address`, `network` |
401
+ | `update_account` | Set account name (can only be set once). | `accountName`, `network` |
402
+ | `account_permission_update` | Update multi-signature permissions. | `ownerPermission`, `activePermissions`, `network` |
403
+
404
+ #### Staking (Stake 2.0)
405
+
406
+ | Tool Name | Description | Key Parameters |
407
+ | :------------------------------ | :---------------------------------------------------------------- | :----------------------------- |
408
+ | `freeze_balance_v2` | Freeze TRX to get resources (BANDWIDTH/ENERGY). | `amount`, `resource`, `network` |
409
+ | `unfreeze_balance_v2` | Unfreeze TRX to release resources. | `amount`, `resource`, `network` |
410
+ | `withdraw_expire_unfreeze` | Withdraw expired unfrozen balance back to available. | `network` |
411
+ | `cancel_all_unfreeze_v2` | Re-stake pending unfreezes; withdraw expired ones. | `network` |
412
+ | `get_available_unfreeze_count` | Get remaining unstake operation quota (max 32). | `address`, `network` |
413
+ | `get_can_withdraw_unfreeze_amount` | Get withdrawable TRX from unfreeze at a timestamp. | `address`, `timestampMs`, `network` |
414
+
415
+ #### Account resource (Stake 2.0 delegation)
416
+
417
+ | Tool Name | Description | Key Parameters |
418
+ | :--------------------------------------- | :------------------------------------------------------------- | :----------------------------------------------- |
419
+ | `delegate_resource` | Delegate BANDWIDTH/ENERGY to another address. | `receiverAddress`, `amount`, `resource`, `network` |
420
+ | `undelegate_resource` | Revoke delegated resources. | `receiverAddress`, `amount`, `resource`, `network` |
421
+ | `get_can_delegated_max_size` | Get max delegatable amount for an address. | `address`, `resource`, `network` |
422
+ | `get_delegated_resource_v2` | Get delegation details between two addresses. | `fromAddress`, `toAddress`, `network` |
423
+ | `get_delegated_resource_account_index_v2`| Get who delegated to/from an address. | `address`, `network` |
424
+
425
+ #### Governance (Super Representatives)
426
+
427
+ | Tool Name | Description | Key Parameters |
428
+ | :------------------------- | :--------------------------------------------------------------- | :------------------------------ |
429
+ | `list_witnesses` | Get the full list of all Super Representatives on the network. | `network` |
430
+ | `get_paginated_witnesses` | Get a paginated list of current active Super Representatives. | `offset`, `limit`, `network` |
431
+ | `get_next_maintenance_time`| Get the next SR maintenance (vote tally) time. | `network` |
432
+ | `get_reward` | Get unclaimed SR voting reward for an address. | `address`, `network` |
433
+ | `get_brokerage` | Get SR brokerage ratio (reward split with voters). | `address`, `network` |
434
+ | `create_witness` | Apply to become a Super Representative candidate. | `url`, `network` |
435
+ | `update_witness` | Update Super Representative URL. | `url`, `network` |
436
+ | `vote_witness` | Vote for Super Representatives with frozen TRX. | `votes`, `network` |
437
+ | `withdraw_balance` | Withdraw accumulated SR block rewards. | `network` |
438
+ | `update_brokerage` | Update SR brokerage ratio. | `brokerage`, `network` |
439
+
440
+ #### Proposals
441
+
442
+ | Tool Name | Description | Key Parameters |
443
+ | :----------------- | :------------------------------------------ | :------------------------------------- |
444
+ | `list_proposals` | List all network governance proposals. | `network` |
445
+ | `get_proposal` | Get details of a specific proposal by ID. | `proposalId`, `network` |
446
+ | `create_proposal` | Create a new governance proposal (SR only). | `parameters`, `network` |
447
+ | `approve_proposal` | Approve or revoke a proposal (SR only). | `proposalId`, `hasApproval`, `network` |
448
+ | `delete_proposal` | Delete a proposal (creator only). | `proposalId`, `network` |
449
+
450
+ #### Events
451
+
452
+ | Tool Name | Description | Key Parameters |
453
+ | :------------------------------ | :---------------------------------------------------- | :--------------------------------------- |
454
+ | `get_events_by_transaction_id` | Get all events emitted by a specific transaction. | `transactionId`, `onlyConfirmed`, `network` |
455
+ | `get_events_by_contract_address`| Get events emitted by a specific contract. | `contractAddress`, `eventName`, `network` |
456
+ | `get_events_by_block_number` | Get all events emitted in a specific block. | `blockNumber`, `network` |
457
+ | `get_events_of_latest_block` | Get all events from the latest block. | `network` |
458
+
459
+ #### Account Data (TronGrid)
460
+
461
+ | Tool Name | Description | Key Parameters |
462
+ | :--------------------------------- | :----------------------------------------------------- | :------------------------------------- |
463
+ | `get_account_info` | Get account summary from TronGrid. | `address`, `network` |
464
+ | `get_account_transactions` | Get transaction history for an account. | `address`, `limit`, `network` |
465
+ | `get_account_trc20_transactions` | Get TRC20 transfer history for an account. | `address`, `limit`, `network` |
466
+ | `get_account_internal_transactions`| Get internal transaction history for an account. | `address`, `limit`, `network` |
467
+ | `get_account_trc20_balances` | Get all TRC20 token balances for an account. | `address`, `network` |
468
+
469
+ #### Contract Data (TronGrid)
470
+
471
+ | Tool Name | Description | Key Parameters |
472
+ | :--------------------------------- | :---------------------------------------------------- | :------------------------------------- |
473
+ | `get_contract_transactions` | Get transaction history for a contract. | `contractAddress`, `limit`, `network` |
474
+ | `get_contract_internal_transactions`| Get internal transactions for a contract. | `contractAddress`, `limit`, `network` |
475
+ | `get_trc20_token_holders` | Get holder list for a TRC20 token. | `contractAddress`, `limit`, `network` |
476
+
477
+ #### Mempool
478
+
479
+ | Tool Name | Description | Key Parameters |
480
+ | :------------------------------ | :------------------------------------------------------- | :-------------------- |
481
+ | `get_pending_transactions` | Get transaction IDs in the pending pool (mempool). | `network` |
482
+ | `get_transaction_from_pending` | Get a specific transaction from the pending pool. | `txId`, `network` |
483
+ | `get_pending_size` | Get the current size of the pending transaction pool. | `network` |
484
+
485
+ #### Node
486
+
487
+ | Tool Name | Description | Key Parameters |
488
+ | :------------- | :---------------------------------------------------- | :------------- |
489
+ | `list_nodes` | List all connected node addresses on the network. | `network` |
490
+ | `get_node_info`| Get detailed info about the connected full node. | `network` |
491
+
492
+ #### Signing & Security
493
+
494
+ | Tool Name | Description | Key Parameters |
495
+ | :------------- | :----------------------------------------- | :------------- |
496
+ | `sign_message` | Sign a message with the configured wallet. | `message` |
497
+
498
+ ### Prompts
499
+
500
+ - `prepare_transfer`: Interactive guide to prepare TRX/TRC20 transfers.
501
+ - `interact_with_contract`: Step-by-step guide to interact with a smart contract.
502
+ - `diagnose_transaction`: Analyze a transaction hash for status and errors.
503
+ - `explain_tron_concept`: Explain a TRON blockchain concept with examples.
504
+ - `analyze_wallet`: Comprehensive report of wallet assets.
505
+ - `check_network_status`: Report on network health and resource costs.
506
+
507
+ ## Security Considerations
508
+
509
+ - **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.
510
+ - **Shared Machines**: Be aware that plain environment variables can be visible to other users via `/proc` or system monitoring tools.
511
+ - **Testnets**: Always test on Nile or Shasta before performing operations on Mainnet.
512
+ - **Approvals**: Be cautious when approving token allowances via `write_contract`. Only approve what is necessary.
513
+
514
+ ## Project Structure
515
+
516
+ ```
517
+ mcp-server-tron/
518
+ ├── src/
519
+ │ ├── core/
520
+ │ │ ├── chains.ts # Network definitions
521
+ │ │ ├── tools/ # MCP Tool definitions (split by category)
522
+ │ │ ├── prompts.ts # MCP Prompt definitions
523
+ │ │ └── services/ # Business logic (TronWeb integration)
524
+ │ │ ├── wallet.ts # Wallet management
525
+ │ │ ├── transfer.ts # Transfer logic
526
+ │ │ ├── contracts.ts # Contract logic
527
+ │ │ ├── address.ts # Address conversion
528
+ │ │ └── ...
529
+ │ ├── server/ # HTTP/Stdio server setup
530
+ │ └── index.ts # Entry point
531
+ ├── tests/ # Unit tests
532
+ └── package.json
533
+ ```
534
+
535
+ ## License
536
+
537
+ MIT
package/bin/cli.js ADDED
@@ -0,0 +1,51 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { fileURLToPath } from "url";
4
+ import { dirname, resolve } from "path";
5
+ import { spawn } from "child_process";
6
+ import { createRequire } from "module";
7
+
8
+ const __filename = fileURLToPath(import.meta.url);
9
+ const __dirname = dirname(__filename);
10
+ const require = createRequire(import.meta.url);
11
+
12
+ // Parse command line arguments
13
+ const args = process.argv.slice(2);
14
+ const httpMode = args.includes("--http") || args.includes("-h");
15
+
16
+ console.error(`Starting mcp-server-tron in ${httpMode ? "HTTP" : "stdio"} mode...`);
17
+
18
+ // Determine which file to execute
19
+ const scriptPath = resolve(__dirname, "../build", httpMode ? "server/http-server.js" : "index.js");
20
+
21
+ try {
22
+ // Check if the built files exist
23
+ require.resolve(scriptPath);
24
+
25
+ // Execute the server
26
+ const server = spawn("node", [scriptPath, ...args], {
27
+ stdio: "inherit",
28
+ shell: false,
29
+ });
30
+
31
+ server.on("error", (err) => {
32
+ console.error("Failed to start server:", err);
33
+ process.exit(1);
34
+ });
35
+
36
+ // Handle clean shutdown
37
+ const cleanup = () => {
38
+ if (!server.killed) {
39
+ server.kill();
40
+ }
41
+ };
42
+
43
+ process.on("SIGINT", cleanup);
44
+ process.on("SIGTERM", cleanup);
45
+ process.on("exit", cleanup);
46
+ } catch (error) {
47
+ console.error("Error: Server files not found. The package may not be built correctly.");
48
+ console.error("Please try reinstalling the package or contact the maintainers.");
49
+ console.error(error);
50
+ process.exit(1);
51
+ }
@@ -0,0 +1,17 @@
1
+ export declare enum TronNetwork {
2
+ Mainnet = "mainnet",
3
+ Nile = "nile",
4
+ Shasta = "shasta"
5
+ }
6
+ export interface NetworkConfig {
7
+ name: string;
8
+ fullNode: string;
9
+ solidityNode: string;
10
+ eventServer: string;
11
+ explorer: string;
12
+ }
13
+ export declare const NETWORKS: Record<TronNetwork, NetworkConfig>;
14
+ export declare const DEFAULT_NETWORK = TronNetwork.Mainnet;
15
+ export declare function getNetworkConfig(network?: string): NetworkConfig;
16
+ export declare function getSupportedNetworks(): string[];
17
+ export declare function getRpcUrl(network?: string): string;