@bankofai/mcp-server-tron 1.1.4 → 1.1.6
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.
- package/README.md +34 -7
- package/build/core/prompts.js +1 -2
- package/build/core/prompts.js.map +1 -1
- package/build/core/services/account.d.ts +2 -10
- package/build/core/services/account.js +8 -14
- package/build/core/services/account.js.map +1 -1
- package/build/core/services/agent-wallet.d.ts +17 -27
- package/build/core/services/agent-wallet.js +82 -158
- package/build/core/services/agent-wallet.js.map +1 -1
- package/build/core/services/clients.d.ts +0 -5
- package/build/core/services/clients.js +0 -18
- package/build/core/services/clients.js.map +1 -1
- package/build/core/services/wallet.d.ts +1 -5
- package/build/core/services/wallet.js +2 -8
- package/build/core/services/wallet.js.map +1 -1
- package/build/core/tools/index.js +1 -2
- package/build/core/tools/index.js.map +1 -1
- package/build/core/tools/wallet.js +2 -2
- package/build/core/tools/wallet.js.map +1 -1
- package/build/server/http-app.d.ts +9 -0
- package/build/server/http-app.js +69 -0
- package/build/server/http-app.js.map +1 -0
- package/build/server/http-server.js +12 -174
- package/build/server/http-server.js.map +1 -1
- package/build/server/server.js +1 -1
- package/build/server/server.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -91,8 +91,8 @@ Key capabilities:
|
|
|
91
91
|
|
|
92
92
|
### Wallet & Security
|
|
93
93
|
|
|
94
|
-
- **Agent
|
|
95
|
-
- **
|
|
94
|
+
- **Agent Wallet (Recommended)**: Encrypted key storage via agent-wallet SDK — private keys never leave the keystore.
|
|
95
|
+
- **Static Wallet**: Configure via `TRON_PRIVATE_KEY` or `TRON_MNEMONIC` environment variables.
|
|
96
96
|
- **HD Wallet**: Supports BIP-44 derivation path `m/44'/195'/0'/0/{index}`.
|
|
97
97
|
- **Signing**: Sign arbitrary messages and transactions.
|
|
98
98
|
|
|
@@ -150,7 +150,7 @@ export AGENT_WALLET_PASSWORD="<YOUR_MASTER_PASSWORD>"
|
|
|
150
150
|
export AGENT_WALLET_DIR="<YOUR_WALLET_DIR>" # Optional, default: ~/.agent-wallet
|
|
151
151
|
```
|
|
152
152
|
|
|
153
|
-
> `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
|
|
153
|
+
> `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.
|
|
154
154
|
|
|
155
155
|
**Option 2: Private Key**
|
|
156
156
|
|
|
@@ -165,7 +165,7 @@ export TRON_MNEMONIC="<WORD1> <WORD2> ... <WORD12>"
|
|
|
165
165
|
export TRON_ACCOUNT_INDEX="0" # Optional, default: 0
|
|
166
166
|
```
|
|
167
167
|
|
|
168
|
-
> **Security Note**:
|
|
168
|
+
> **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.
|
|
169
169
|
|
|
170
170
|
> See [`.env.example`](.env.example) for a complete list of all supported environment variables.
|
|
171
171
|
|
|
@@ -184,10 +184,36 @@ npm start
|
|
|
184
184
|
# Start in readonly mode (disables write tools)
|
|
185
185
|
npm start -- --readonly
|
|
186
186
|
|
|
187
|
-
# Start in HTTP mode (Streamable HTTP)
|
|
187
|
+
# Start in stateless HTTP mode (Streamable HTTP)
|
|
188
188
|
npm run start:http
|
|
189
189
|
```
|
|
190
190
|
|
|
191
|
+
### Docker
|
|
192
|
+
|
|
193
|
+
Build the image:
|
|
194
|
+
|
|
195
|
+
```bash
|
|
196
|
+
docker build -t mcp-server-tron:test .
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
Run the container with local logs mounted:
|
|
200
|
+
|
|
201
|
+
```bash
|
|
202
|
+
docker run -d \
|
|
203
|
+
--name mcp-tron \
|
|
204
|
+
-p 3001:3001 \
|
|
205
|
+
-e MCP_HOST=0.0.0.0 \
|
|
206
|
+
-e MCP_PORT=3001 \
|
|
207
|
+
-e MCP_LOG_DIR=/app/logs \
|
|
208
|
+
-v "$(pwd)/logs:/app/logs" \
|
|
209
|
+
mcp-server-tron:test
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
Docker logs are written to the mounted `logs/` directory and are named by date, for example:
|
|
213
|
+
|
|
214
|
+
- `logs/mcp-server-tron-2026-03-18-combined.log`
|
|
215
|
+
- `logs/mcp-server-tron-2026-03-18-error.log`
|
|
216
|
+
|
|
191
217
|
### Testing
|
|
192
218
|
|
|
193
219
|
The project includes a comprehensive test suite with unit tests and integration tests (using the Nile testnet).
|
|
@@ -248,7 +274,7 @@ claude mcp add -e AGENT_WALLET_PASSWORD=xxx -e TRONGRID_API_KEY=xxx mcp-server-t
|
|
|
248
274
|
|
|
249
275
|
#### Option B: Official Hosted Server (Remote)
|
|
250
276
|
|
|
251
|
-
Connect to the official hosted server at `https://tron-mcp-server.bankofai.io`. No installation required, readonly mode.
|
|
277
|
+
Connect to the official hosted server at `https://tron-mcp-server.bankofai.io`. No installation required, readonly mode, stateless HTTP.
|
|
252
278
|
|
|
253
279
|
**Claude Code:**
|
|
254
280
|
|
|
@@ -471,7 +497,8 @@ claude mcp add -transport http mcp-server-tron https://tron-mcp-server.bankofai.
|
|
|
471
497
|
## Security Considerations
|
|
472
498
|
|
|
473
499
|
- **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.
|
|
474
|
-
- **
|
|
500
|
+
- **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).
|
|
501
|
+
- **Shared Machines**: Be aware that on shared systems, environment variables might be visible to other users via `/proc` or system monitoring tools.
|
|
475
502
|
- **Testnets**: Always test on Nile or Shasta before performing operations on Mainnet.
|
|
476
503
|
- **Approvals**: Be cautious when approving token allowances via `write_contract`. Only approve what is necessary.
|
|
477
504
|
|
package/build/core/prompts.js
CHANGED
|
@@ -16,7 +16,6 @@ import * as services from "./services/index.js";
|
|
|
16
16
|
* @param options Registration options
|
|
17
17
|
*/
|
|
18
18
|
export function registerTRONPrompts(server, options = {}) {
|
|
19
|
-
const { isWalletConfigured } = services;
|
|
20
19
|
/**
|
|
21
20
|
* Helper to register a prompt with automatic wallet requirement detection.
|
|
22
21
|
* Prompts that guide write operations should only be registered if a wallet
|
|
@@ -33,7 +32,7 @@ export function registerTRONPrompts(server, options = {}) {
|
|
|
33
32
|
return;
|
|
34
33
|
}
|
|
35
34
|
// 2. Skip if the prompt needs a wallet but none is configured
|
|
36
|
-
if (walletNeeded &&
|
|
35
|
+
if (walletNeeded && services.getActiveWalletId() === null) {
|
|
37
36
|
return;
|
|
38
37
|
}
|
|
39
38
|
server.registerPrompt(name, definition, handler);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompts.js","sourceRoot":"","sources":["../../src/core/prompts.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,QAAQ,MAAM,qBAAqB,CAAC;AAEhD;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,mBAAmB,CAAC,MAAiB,EAAE,UAAkC,EAAE;IACzF
|
|
1
|
+
{"version":3,"file":"prompts.js","sourceRoot":"","sources":["../../src/core/prompts.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,QAAQ,MAAM,qBAAqB,CAAC;AAEhD;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,mBAAmB,CAAC,MAAiB,EAAE,UAAkC,EAAE;IACzF;;;;OAIG;IACH,MAAM,cAAc,GAAG,CACrB,IAAY,EACZ,UAGC,EACD,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EAAE;oBACP,IAAI,EAAE,MAAM;oBACZ,IAAI,EAAE;;yDAEuC,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;2BA2BrC,OAAO;;;;;;;;;;;;;;;;CAgBjC;iBACU;aACF;SACF;KACF,CAAC,CACH,CAAC;AACJ,CAAC"}
|
|
@@ -19,21 +19,13 @@ export declare function getAccountBalance(address: string, blockHash: string, bl
|
|
|
19
19
|
}>;
|
|
20
20
|
/**
|
|
21
21
|
* Generate a new account.
|
|
22
|
-
*
|
|
23
|
-
* - legacy mode: generates offline keypair (no network interaction)
|
|
22
|
+
* Unified interface that returns a new keypair (ephemeral).
|
|
24
23
|
*/
|
|
25
24
|
export declare function generateAccount(): Promise<{
|
|
26
|
-
privateKey: string;
|
|
27
|
-
publicKey: string;
|
|
28
|
-
address: {
|
|
29
|
-
base58: string;
|
|
30
|
-
hex: string;
|
|
31
|
-
};
|
|
32
|
-
} | {
|
|
33
|
-
walletId: string;
|
|
34
25
|
address: {
|
|
35
26
|
base58: string;
|
|
36
27
|
};
|
|
28
|
+
privateKey: string;
|
|
37
29
|
message: string;
|
|
38
30
|
}>;
|
|
39
31
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { TronWeb } from "tronweb";
|
|
2
2
|
import { getTronWeb } from "./clients.js";
|
|
3
|
-
import { getOwnerAddress, buildSignBroadcast,
|
|
3
|
+
import { getOwnerAddress, buildSignBroadcast, generateAccountKeypair as generateAccountService, } from "./agent-wallet.js";
|
|
4
4
|
/**
|
|
5
5
|
* Get full account information from the TRON network
|
|
6
6
|
* @param address Account address (Base58 or Hex)
|
|
@@ -41,22 +41,16 @@ export async function getAccountBalance(address, blockHash, blockNumber, network
|
|
|
41
41
|
}
|
|
42
42
|
/**
|
|
43
43
|
* Generate a new account.
|
|
44
|
-
*
|
|
45
|
-
* - legacy mode: generates offline keypair (no network interaction)
|
|
44
|
+
* Unified interface that returns a new keypair (ephemeral).
|
|
46
45
|
*/
|
|
47
46
|
export async function generateAccount() {
|
|
48
47
|
try {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
// Legacy mode: generate offline keypair
|
|
58
|
-
const account = await TronWeb.createAccount();
|
|
59
|
-
return account;
|
|
48
|
+
const result = await generateAccountService();
|
|
49
|
+
return {
|
|
50
|
+
address: { base58: result.address },
|
|
51
|
+
privateKey: result.privateKey,
|
|
52
|
+
message: result.message,
|
|
53
|
+
};
|
|
60
54
|
}
|
|
61
55
|
catch (error) {
|
|
62
56
|
throw new Error(`Failed to generate account: ${error.message}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"account.js","sourceRoot":"","sources":["../../../src/core/services/account.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,
|
|
1
|
+
{"version":3,"file":"account.js","sourceRoot":"","sources":["../../../src/core/services/account.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,sBAAsB,IAAI,sBAAsB,GACjD,MAAM,mBAAmB,CAAC;AAE3B;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,OAAe,EAAE,OAAO,GAAG,SAAS;IACnE,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;IACpC,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;QACtD,OAAO,OAAO,CAAC;IACjB,CAAC;IAAC,OAAO,KAAU,EAAE,CAAC;QACpB,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AAC,OAAO,EAAE,CAAC,CAAC;IAC5E,CAAC;AACH,CAAC"}
|
|
@@ -1,36 +1,29 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Agent-wallet integration layer for mcp-server-tron.
|
|
3
3
|
*
|
|
4
|
-
* Provides a unified signing interface
|
|
5
|
-
*
|
|
6
|
-
* - **
|
|
7
|
-
*
|
|
8
|
-
* Priority: agent-wallet env vars take precedence over legacy env vars.
|
|
4
|
+
* Provides a unified signing interface via agent-wallet SDK.
|
|
5
|
+
* Supports:
|
|
6
|
+
* - **Encrypted Storage mode**: Keys encrypted at rest (password-protected).
|
|
7
|
+
* - **Static/Env mode**: Keys provided via environment variables.
|
|
9
8
|
*/
|
|
10
9
|
import { type BaseWallet } from "@bankofai/agent-wallet";
|
|
11
|
-
/** True when agent-wallet is configured (password is required). */
|
|
12
|
-
export declare function isAgentWalletConfigured(): boolean;
|
|
13
|
-
/** True when legacy TRON_PRIVATE_KEY / TRON_MNEMONIC env vars are set. */
|
|
14
|
-
export declare function isLegacyMode(): boolean;
|
|
15
10
|
/**
|
|
16
|
-
* Get the currently active agent-wallet.
|
|
17
|
-
* uses the active wallet from agent-wallet config (or first available wallet).
|
|
11
|
+
* Get the currently active agent-wallet.
|
|
18
12
|
*/
|
|
19
13
|
export declare function getActiveWallet(): Promise<BaseWallet>;
|
|
20
14
|
/**
|
|
21
|
-
* Get the address of the active wallet.
|
|
15
|
+
* Get the address of the active wallet.
|
|
22
16
|
*/
|
|
23
17
|
export declare function getOwnerAddress(): Promise<string>;
|
|
24
18
|
/**
|
|
25
|
-
* Switch the active wallet at runtime (
|
|
26
|
-
* Persists the choice to agent-wallet config.
|
|
19
|
+
* Switch the active wallet at runtime (Encrypted Storage mode only).
|
|
27
20
|
*/
|
|
28
21
|
export declare function selectWallet(walletId: string): Promise<{
|
|
29
22
|
id: string;
|
|
30
23
|
address: string;
|
|
31
24
|
}>;
|
|
32
25
|
/**
|
|
33
|
-
* List all available wallets.
|
|
26
|
+
* List all available wallets.
|
|
34
27
|
*/
|
|
35
28
|
export declare function listAgentWallets(): Promise<Array<{
|
|
36
29
|
id: string;
|
|
@@ -39,22 +32,18 @@ export declare function listAgentWallets(): Promise<Array<{
|
|
|
39
32
|
}>>;
|
|
40
33
|
/**
|
|
41
34
|
* Get the currently active wallet ID.
|
|
42
|
-
* Reads from agent-wallet config's `active_wallet` field.
|
|
43
35
|
*/
|
|
44
36
|
export declare function getActiveWalletId(): string | null;
|
|
45
37
|
/**
|
|
46
|
-
* Sign an unsigned transaction.
|
|
47
|
-
* Returns the signed transaction object (with `signature` array appended).
|
|
38
|
+
* Sign an unsigned transaction.
|
|
48
39
|
*/
|
|
49
40
|
export declare function signTransaction(unsignedTx: Record<string, unknown>): Promise<any>;
|
|
50
41
|
/**
|
|
51
|
-
* Sign using raw crypto
|
|
52
|
-
* Needed for transaction types not in TronWeb's txJsonToPb mapping
|
|
53
|
-
* (e.g., WitnessUpdateContract).
|
|
42
|
+
* Sign using raw crypto.
|
|
54
43
|
*/
|
|
55
|
-
export declare function signTransactionRaw(unsignedTx: Record<string, unknown>,
|
|
44
|
+
export declare function signTransactionRaw(unsignedTx: Record<string, unknown>, _network?: string): Promise<any>;
|
|
56
45
|
/**
|
|
57
|
-
* Sign an unsigned transaction and broadcast it.
|
|
46
|
+
* Sign an unsigned transaction and broadcast it.
|
|
58
47
|
*/
|
|
59
48
|
export declare function buildSignBroadcast(unsignedTx: Record<string, unknown>, network?: string): Promise<string>;
|
|
60
49
|
/**
|
|
@@ -66,10 +55,11 @@ export declare function signMessageWithWallet(message: string): Promise<string>;
|
|
|
66
55
|
*/
|
|
67
56
|
export declare function signTypedDataWithWallet(domain: object, types: object, value: object): Promise<string>;
|
|
68
57
|
/**
|
|
69
|
-
*
|
|
70
|
-
*
|
|
58
|
+
* Unified account generation.
|
|
59
|
+
* Generates a keypair and returns it directly. It is NOT stored in agent-wallet.
|
|
71
60
|
*/
|
|
72
|
-
export declare function
|
|
73
|
-
walletId: string;
|
|
61
|
+
export declare function generateAccountKeypair(): Promise<{
|
|
74
62
|
address: string;
|
|
63
|
+
privateKey: string;
|
|
64
|
+
message: string;
|
|
75
65
|
}>;
|
|
@@ -1,19 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Agent-wallet integration layer for mcp-server-tron.
|
|
3
3
|
*
|
|
4
|
-
* Provides a unified signing interface
|
|
5
|
-
*
|
|
6
|
-
* - **
|
|
7
|
-
*
|
|
8
|
-
* Priority: agent-wallet env vars take precedence over legacy env vars.
|
|
4
|
+
* Provides a unified signing interface via agent-wallet SDK.
|
|
5
|
+
* Supports:
|
|
6
|
+
* - **Encrypted Storage mode**: Keys encrypted at rest (password-protected).
|
|
7
|
+
* - **Static/Env mode**: Keys provided via environment variables.
|
|
9
8
|
*/
|
|
10
|
-
import {
|
|
9
|
+
import { resolveWalletProvider, } from "@bankofai/agent-wallet";
|
|
11
10
|
import { TronWeb } from "tronweb";
|
|
12
|
-
import {
|
|
13
|
-
import { join } from "path";
|
|
14
|
-
import { getTronWeb, getWallet } from "./clients.js";
|
|
15
|
-
// Default agent-wallet directory (same as agent-wallet CLI)
|
|
16
|
-
const DEFAULT_WALLET_DIR = join(homedir(), ".agent-wallet");
|
|
11
|
+
import { getTronWeb } from "./clients.js";
|
|
17
12
|
// ---------------------------------------------------------------------------
|
|
18
13
|
// Module-level singleton state
|
|
19
14
|
// ---------------------------------------------------------------------------
|
|
@@ -21,58 +16,58 @@ let provider = null;
|
|
|
21
16
|
let activeWallet = null;
|
|
22
17
|
let activeAddress = null;
|
|
23
18
|
// ---------------------------------------------------------------------------
|
|
24
|
-
// Mode detection
|
|
25
|
-
// ---------------------------------------------------------------------------
|
|
26
|
-
/** Resolve the agent-wallet secrets directory. */
|
|
27
|
-
function getWalletDir() {
|
|
28
|
-
return process.env.AGENT_WALLET_DIR || DEFAULT_WALLET_DIR;
|
|
29
|
-
}
|
|
30
|
-
/** True when agent-wallet is configured (password is required). */
|
|
31
|
-
export function isAgentWalletConfigured() {
|
|
32
|
-
return !!process.env.AGENT_WALLET_PASSWORD;
|
|
33
|
-
}
|
|
34
|
-
/** True when legacy TRON_PRIVATE_KEY / TRON_MNEMONIC env vars are set. */
|
|
35
|
-
export function isLegacyMode() {
|
|
36
|
-
if (isAgentWalletConfigured())
|
|
37
|
-
return false;
|
|
38
|
-
return !!(process.env.TRON_PRIVATE_KEY || process.env.TRON_MNEMONIC);
|
|
39
|
-
}
|
|
40
|
-
// ---------------------------------------------------------------------------
|
|
41
19
|
// Provider initialization (lazy)
|
|
42
20
|
// ---------------------------------------------------------------------------
|
|
21
|
+
/**
|
|
22
|
+
* Configure environment variables for backward compatibility.
|
|
23
|
+
* Maps TRON_PRIVATE_KEY -> AGENT_WALLET_PRIVATE_KEY etc.
|
|
24
|
+
*/
|
|
25
|
+
function ensureEnvMapping() {
|
|
26
|
+
if (process.env.TRON_PRIVATE_KEY && !process.env.AGENT_WALLET_PRIVATE_KEY) {
|
|
27
|
+
process.env.AGENT_WALLET_PRIVATE_KEY = process.env.TRON_PRIVATE_KEY;
|
|
28
|
+
}
|
|
29
|
+
if (process.env.TRON_MNEMONIC && !process.env.AGENT_WALLET_MNEMONIC) {
|
|
30
|
+
process.env.AGENT_WALLET_MNEMONIC = process.env.TRON_MNEMONIC;
|
|
31
|
+
}
|
|
32
|
+
if (process.env.TRON_MNEMONIC_ACCOUNT_INDEX && !process.env.AGENT_WALLET_MNEMONIC_ACCOUNT_INDEX) {
|
|
33
|
+
process.env.AGENT_WALLET_MNEMONIC_ACCOUNT_INDEX = process.env.TRON_MNEMONIC_ACCOUNT_INDEX;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
43
36
|
function getProvider() {
|
|
44
37
|
if (provider)
|
|
45
38
|
return provider;
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
39
|
+
ensureEnvMapping();
|
|
40
|
+
try {
|
|
41
|
+
// resolveWalletProvider detects mode from AGENT_WALLET_* env vars
|
|
42
|
+
provider = resolveWalletProvider({ network: "tron" });
|
|
43
|
+
return provider;
|
|
44
|
+
}
|
|
45
|
+
catch (_e) {
|
|
46
|
+
// Config missing or invalid - SDK throws ValueError
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
50
49
|
}
|
|
51
50
|
// ---------------------------------------------------------------------------
|
|
52
51
|
// Active wallet management
|
|
53
52
|
// ---------------------------------------------------------------------------
|
|
54
53
|
/**
|
|
55
|
-
* Get the currently active agent-wallet.
|
|
56
|
-
* uses the active wallet from agent-wallet config (or first available wallet).
|
|
54
|
+
* Get the currently active agent-wallet.
|
|
57
55
|
*/
|
|
58
56
|
export async function getActiveWallet() {
|
|
59
57
|
if (activeWallet)
|
|
60
58
|
return activeWallet;
|
|
61
59
|
const p = getProvider();
|
|
62
|
-
|
|
60
|
+
if (!p) {
|
|
61
|
+
throw new Error("Wallet not configured. Please set AGENT_WALLET_PASSWORD, TRON_PRIVATE_KEY, TRON_MNEMONIC, or TRON_MNEMONIC_ACCOUNT_INDEX.");
|
|
62
|
+
}
|
|
63
|
+
activeWallet = await p.getActiveWallet();
|
|
63
64
|
activeAddress = await activeWallet.getAddress();
|
|
64
65
|
return activeWallet;
|
|
65
66
|
}
|
|
66
67
|
/**
|
|
67
|
-
* Get the address of the active wallet.
|
|
68
|
+
* Get the address of the active wallet.
|
|
68
69
|
*/
|
|
69
70
|
export async function getOwnerAddress() {
|
|
70
|
-
if (isLegacyMode()) {
|
|
71
|
-
// Legacy: derive address from env-var private key
|
|
72
|
-
const privateKey = getLegacyPrivateKey();
|
|
73
|
-
const cleanKey = privateKey.startsWith("0x") ? privateKey.slice(2) : privateKey;
|
|
74
|
-
return TronWeb.address.fromPrivateKey(cleanKey);
|
|
75
|
-
}
|
|
76
71
|
if (activeAddress)
|
|
77
72
|
return activeAddress;
|
|
78
73
|
const wallet = await getActiveWallet();
|
|
@@ -80,17 +75,17 @@ export async function getOwnerAddress() {
|
|
|
80
75
|
return activeAddress;
|
|
81
76
|
}
|
|
82
77
|
/**
|
|
83
|
-
* Switch the active wallet at runtime (
|
|
84
|
-
* Persists the choice to agent-wallet config.
|
|
78
|
+
* Switch the active wallet at runtime (Encrypted Storage mode only).
|
|
85
79
|
*/
|
|
86
80
|
export async function selectWallet(walletId) {
|
|
87
|
-
if (isLegacyMode()) {
|
|
88
|
-
throw new Error("select_wallet is not available in legacy mode. " +
|
|
89
|
-
"Configure AGENT_WALLET_PASSWORD to use agent-wallet.");
|
|
90
|
-
}
|
|
91
81
|
const p = getProvider();
|
|
92
|
-
p.setActive
|
|
93
|
-
|
|
82
|
+
if (!p || typeof p.setActive !== "function") {
|
|
83
|
+
throw new Error("select_wallet is not available. " +
|
|
84
|
+
"Ensure AGENT_WALLET_PASSWORD is configured for encrypted storage mode.");
|
|
85
|
+
}
|
|
86
|
+
const lp = p;
|
|
87
|
+
lp.setActive(walletId);
|
|
88
|
+
const wallet = await lp.getWallet(walletId);
|
|
94
89
|
const address = await wallet.getAddress();
|
|
95
90
|
// Update cached state
|
|
96
91
|
activeWallet = wallet;
|
|
@@ -98,71 +93,61 @@ export async function selectWallet(walletId) {
|
|
|
98
93
|
return { id: walletId, address };
|
|
99
94
|
}
|
|
100
95
|
/**
|
|
101
|
-
* List all available wallets.
|
|
96
|
+
* List all available wallets.
|
|
102
97
|
*/
|
|
103
98
|
export async function listAgentWallets() {
|
|
104
|
-
if (isLegacyMode()) {
|
|
105
|
-
const address = await getOwnerAddress();
|
|
106
|
-
return [{ id: "default", type: "env_configured", address }];
|
|
107
|
-
}
|
|
108
99
|
const p = getProvider();
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
const
|
|
113
|
-
const
|
|
114
|
-
result
|
|
100
|
+
if (!p)
|
|
101
|
+
return [];
|
|
102
|
+
if (typeof p.listWallets === "function") {
|
|
103
|
+
const lp = p;
|
|
104
|
+
const wallets = await lp.listWallets();
|
|
105
|
+
const result = [];
|
|
106
|
+
for (const w of wallets) {
|
|
107
|
+
const wallet = await lp.getWallet(w.id);
|
|
108
|
+
const address = await wallet.getAddress();
|
|
109
|
+
result.push({ id: w.id, type: w.type, address });
|
|
110
|
+
}
|
|
111
|
+
return result;
|
|
115
112
|
}
|
|
116
|
-
|
|
113
|
+
// Static/Env mode
|
|
114
|
+
const wallet = await p.getActiveWallet();
|
|
115
|
+
const address = await wallet.getAddress();
|
|
116
|
+
return [{ id: "default", type: "static", address }];
|
|
117
117
|
}
|
|
118
118
|
/**
|
|
119
119
|
* Get the currently active wallet ID.
|
|
120
|
-
* Reads from agent-wallet config's `active_wallet` field.
|
|
121
120
|
*/
|
|
122
121
|
export function getActiveWalletId() {
|
|
123
|
-
if (isLegacyMode())
|
|
124
|
-
return "default";
|
|
125
|
-
if (!isAgentWalletConfigured())
|
|
126
|
-
return null;
|
|
127
122
|
const p = getProvider();
|
|
128
|
-
|
|
123
|
+
if (!p)
|
|
124
|
+
return null;
|
|
125
|
+
if (typeof p.getActiveId === "function") {
|
|
126
|
+
return p.getActiveId();
|
|
127
|
+
}
|
|
128
|
+
return "default";
|
|
129
129
|
}
|
|
130
130
|
// ---------------------------------------------------------------------------
|
|
131
131
|
// Signing
|
|
132
132
|
// ---------------------------------------------------------------------------
|
|
133
133
|
/**
|
|
134
|
-
* Sign an unsigned transaction.
|
|
135
|
-
* Returns the signed transaction object (with `signature` array appended).
|
|
134
|
+
* Sign an unsigned transaction.
|
|
136
135
|
*/
|
|
137
136
|
export async function signTransaction(unsignedTx) {
|
|
138
|
-
if (isLegacyMode()) {
|
|
139
|
-
const privateKey = getLegacyPrivateKey();
|
|
140
|
-
const network = "mainnet"; // legacy sign uses any network for signing
|
|
141
|
-
const tronWeb = getWallet(privateKey, network);
|
|
142
|
-
return await tronWeb.trx.sign(unsignedTx, privateKey);
|
|
143
|
-
}
|
|
144
137
|
const wallet = await getActiveWallet();
|
|
145
138
|
const signedJson = await wallet.signTransaction(unsignedTx);
|
|
146
139
|
return JSON.parse(signedJson);
|
|
147
140
|
}
|
|
148
141
|
/**
|
|
149
|
-
* Sign using raw crypto
|
|
150
|
-
* Needed for transaction types not in TronWeb's txJsonToPb mapping
|
|
151
|
-
* (e.g., WitnessUpdateContract).
|
|
142
|
+
* Sign using raw crypto.
|
|
152
143
|
*/
|
|
153
|
-
export async function signTransactionRaw(unsignedTx,
|
|
154
|
-
if (isLegacyMode()) {
|
|
155
|
-
const privateKey = getLegacyPrivateKey();
|
|
156
|
-
const tronWeb = getTronWeb(network);
|
|
157
|
-
return tronWeb.utils.crypto.signTransaction(privateKey, unsignedTx);
|
|
158
|
-
}
|
|
159
|
-
// agent-wallet signs raw_data_hex directly — no txCheck needed
|
|
144
|
+
export async function signTransactionRaw(unsignedTx, _network = "mainnet") {
|
|
160
145
|
const wallet = await getActiveWallet();
|
|
161
146
|
const signedJson = await wallet.signTransaction(unsignedTx);
|
|
162
147
|
return JSON.parse(signedJson);
|
|
163
148
|
}
|
|
164
149
|
/**
|
|
165
|
-
* Sign an unsigned transaction and broadcast it.
|
|
150
|
+
* Sign an unsigned transaction and broadcast it.
|
|
166
151
|
*/
|
|
167
152
|
export async function buildSignBroadcast(unsignedTx, network = "mainnet") {
|
|
168
153
|
const signedTx = await signTransaction(unsignedTx);
|
|
@@ -177,10 +162,6 @@ export async function buildSignBroadcast(unsignedTx, network = "mainnet") {
|
|
|
177
162
|
* Sign a message using the active wallet.
|
|
178
163
|
*/
|
|
179
164
|
export async function signMessageWithWallet(message) {
|
|
180
|
-
if (isLegacyMode()) {
|
|
181
|
-
const tronWeb = getWallet(getLegacyPrivateKey());
|
|
182
|
-
return await tronWeb.trx.sign(message);
|
|
183
|
-
}
|
|
184
165
|
const wallet = await getActiveWallet();
|
|
185
166
|
const msgBytes = Buffer.from(message, "utf-8");
|
|
186
167
|
return await wallet.signMessage(msgBytes);
|
|
@@ -189,13 +170,6 @@ export async function signMessageWithWallet(message) {
|
|
|
189
170
|
* Sign typed data (EIP-712) using the active wallet.
|
|
190
171
|
*/
|
|
191
172
|
export async function signTypedDataWithWallet(domain, types, value) {
|
|
192
|
-
if (isLegacyMode()) {
|
|
193
|
-
const tronWeb = getWallet(getLegacyPrivateKey());
|
|
194
|
-
if (typeof tronWeb.trx._signTypedData === "function") {
|
|
195
|
-
return await tronWeb.trx._signTypedData(domain, types, value);
|
|
196
|
-
}
|
|
197
|
-
throw new Error("signTypedData not supported by this TronWeb version");
|
|
198
|
-
}
|
|
199
173
|
const wallet = await getActiveWallet();
|
|
200
174
|
const eip712Wallet = wallet;
|
|
201
175
|
if (typeof eip712Wallet.signTypedData !== "function") {
|
|
@@ -204,69 +178,19 @@ export async function signTypedDataWithWallet(domain, types, value) {
|
|
|
204
178
|
return await eip712Wallet.signTypedData({ domain, types, value });
|
|
205
179
|
}
|
|
206
180
|
// ---------------------------------------------------------------------------
|
|
207
|
-
// Account generation
|
|
181
|
+
// Account generation
|
|
208
182
|
// ---------------------------------------------------------------------------
|
|
209
183
|
/**
|
|
210
|
-
*
|
|
211
|
-
*
|
|
184
|
+
* Unified account generation.
|
|
185
|
+
* Generates a keypair and returns it directly. It is NOT stored in agent-wallet.
|
|
212
186
|
*/
|
|
213
|
-
export async function
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
const walletId = walletName || `tron-${Date.now()}`;
|
|
221
|
-
const kvStore = new SecureKVStore(secretsDir, password);
|
|
222
|
-
const privateKeyBytes = kvStore.generateKey(walletId);
|
|
223
|
-
// Derive TRON address
|
|
224
|
-
const tempWallet = new TronWallet(privateKeyBytes);
|
|
225
|
-
const address = await tempWallet.getAddress();
|
|
226
|
-
// Update config
|
|
227
|
-
const config = loadConfig(secretsDir);
|
|
228
|
-
config.wallets[walletId] = {
|
|
229
|
-
type: "tron_local",
|
|
230
|
-
identity_file: walletId,
|
|
187
|
+
export async function generateAccountKeypair() {
|
|
188
|
+
// Generate keypair via TronWeb
|
|
189
|
+
const account = await TronWeb.createAccount();
|
|
190
|
+
return {
|
|
191
|
+
address: account.address.base58,
|
|
192
|
+
privateKey: account.privateKey,
|
|
193
|
+
message: "Account generated successfully. Note: This account is NOT stored. Please save your private key manually.",
|
|
231
194
|
};
|
|
232
|
-
saveConfig(secretsDir, config);
|
|
233
|
-
// Refresh provider to pick up new wallet (do not switch active wallet)
|
|
234
|
-
provider = null;
|
|
235
|
-
activeWallet = null;
|
|
236
|
-
activeAddress = null;
|
|
237
|
-
return { walletId, address };
|
|
238
|
-
}
|
|
239
|
-
// ---------------------------------------------------------------------------
|
|
240
|
-
// Legacy helpers (internal)
|
|
241
|
-
// ---------------------------------------------------------------------------
|
|
242
|
-
import * as bip39 from "@scure/bip39";
|
|
243
|
-
import { wordlist } from "@scure/bip39/wordlists/english.js";
|
|
244
|
-
import { HDKey } from "@scure/bip32";
|
|
245
|
-
function getLegacyPrivateKey() {
|
|
246
|
-
const privateKey = process.env.TRON_PRIVATE_KEY;
|
|
247
|
-
const mnemonic = process.env.TRON_MNEMONIC;
|
|
248
|
-
const accountIndexStr = process.env.TRON_ACCOUNT_INDEX || "0";
|
|
249
|
-
const accountIndex = parseInt(accountIndexStr, 10);
|
|
250
|
-
if (isNaN(accountIndex) || accountIndex < 0 || !Number.isInteger(accountIndex)) {
|
|
251
|
-
throw new Error(`Invalid TRON_ACCOUNT_INDEX: "${accountIndexStr}". Must be a non-negative integer.`);
|
|
252
|
-
}
|
|
253
|
-
if (privateKey) {
|
|
254
|
-
const cleanKey = privateKey.startsWith("0x") ? privateKey.slice(2) : privateKey;
|
|
255
|
-
return cleanKey;
|
|
256
|
-
}
|
|
257
|
-
else if (mnemonic) {
|
|
258
|
-
if (!bip39.validateMnemonic(mnemonic, wordlist)) {
|
|
259
|
-
throw new Error("Invalid mnemonic provided in TRON_MNEMONIC");
|
|
260
|
-
}
|
|
261
|
-
const seed = bip39.mnemonicToSeedSync(mnemonic);
|
|
262
|
-
const hdKey = HDKey.fromMasterSeed(seed);
|
|
263
|
-
const child = hdKey.derive(`m/44'/195'/0'/0/${accountIndex}`);
|
|
264
|
-
if (!child.privateKey) {
|
|
265
|
-
throw new Error("Failed to derive private key from mnemonic");
|
|
266
|
-
}
|
|
267
|
-
return Buffer.from(child.privateKey).toString("hex");
|
|
268
|
-
}
|
|
269
|
-
throw new Error("Neither TRON_PRIVATE_KEY nor TRON_MNEMONIC environment variable is set. " +
|
|
270
|
-
"Configure one of them, or use agent-wallet mode with AGENT_WALLET_PASSWORD.");
|
|
271
195
|
}
|
|
272
196
|
//# sourceMappingURL=agent-wallet.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-wallet.js","sourceRoot":"","sources":["../../../src/core/services/agent-wallet.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"agent-wallet.js","sourceRoot":"","sources":["../../../src/core/services/agent-wallet.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAEL,qBAAqB,GAGtB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,8EAA8E;AAC9E,+BAA+B;AAC/B,8EAA8E;AAE9E,IAAI,QAAQ,GAA0B,IAAI,CAAC;AAC3C,IAAI,YAAY,GAAsB,IAAI,CAAC;AAC3C,IAAI,aAAa,GAAkB,IAAI,CAAC;AAExC,8EAA8E;AAC9E,iCAAiC;AACjC,8EAA8E;AAE9E;;;GAGG;AACH,SAAS,gBAAgB;IACvB,IAAI,OAAO,CAAC,GAAG,CAAC,gBAAgB,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,wBAAwB,EAAE,CAAC;QAC1E,OAAO,CAAC,GAAG,CAAC,wBAAwB,GAAG,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC;IACtE,CAAC;IACD,IAAI,OAAO,CAAC,GAAG,CAAC,aAAa,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,qBAAqB,EAAE,CAAC;QACpE,O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AAU,sBAAsB;IAK1C,+BAA+B;IAC/B,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,aAAa,EAAE,CAAC;IAE9C,OAAO;QACL,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,MAAM;QAC/B,UAAU,EAAE,OAAO,CAAC,UAAU;QAC9B,OAAO,EACL,0GAA0G;KAC7G,CAAC;AACJ,CAAC"}
|
|
@@ -3,8 +3,3 @@ import { TronWeb } from "tronweb";
|
|
|
3
3
|
* Get a TronWeb instance for a specific network
|
|
4
4
|
*/
|
|
5
5
|
export declare function getTronWeb(network?: string): TronWeb;
|
|
6
|
-
/**
|
|
7
|
-
* @deprecated Use signTransaction / buildSignBroadcast from agent-wallet.ts instead.
|
|
8
|
-
* Only used internally by agent-wallet.ts for legacy mode signing.
|
|
9
|
-
*/
|
|
10
|
-
export declare function getWallet(privateKey: string, network?: string): TronWeb;
|
|
@@ -26,22 +26,4 @@ export function getTronWeb(network = "mainnet") {
|
|
|
26
26
|
clientCache.set(cacheKey, client);
|
|
27
27
|
return client;
|
|
28
28
|
}
|
|
29
|
-
/**
|
|
30
|
-
* @deprecated Use signTransaction / buildSignBroadcast from agent-wallet.ts instead.
|
|
31
|
-
* Only used internally by agent-wallet.ts for legacy mode signing.
|
|
32
|
-
*/
|
|
33
|
-
export function getWallet(privateKey, network = "mainnet") {
|
|
34
|
-
const config = getNetworkConfig(network);
|
|
35
|
-
const apiKey = process.env.TRONGRID_API_KEY;
|
|
36
|
-
// TronWeb expects private key without 0x prefix usually, but handles it if present?
|
|
37
|
-
// Let's strip 0x to be safe as TronWeb often prefers clean hex
|
|
38
|
-
const cleanKey = privateKey.startsWith("0x") ? privateKey.slice(2) : privateKey;
|
|
39
|
-
return new TronWeb({
|
|
40
|
-
fullHost: config.fullNode,
|
|
41
|
-
solidityNode: config.solidityNode,
|
|
42
|
-
eventServer: config.eventServer,
|
|
43
|
-
privateKey: cleanKey,
|
|
44
|
-
headers: apiKey ? { "TRON-PRO-API-KEY": apiKey } : undefined,
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
29
|
//# sourceMappingURL=clients.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clients.js","sourceRoot":"","sources":["../../../src/core/services/clients.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEhD,8DAA8D;AAC9D,MAAM,WAAW,GAAG,IAAI,GAAG,EAAmB,CAAC;AAE/C;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,OAAO,GAAG,SAAS;IAC5C,MAAM,QAAQ,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;IAEjC,oCAAoC;IACpC,IAAI,WAAW,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC9B,OAAO,WAAW,CAAC,GAAG,CAAC,QAAQ,CAAE,CAAC;IACpC,CAAC;IAED,sBAAsB;IACtB,MAAM,MAAM,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAC;IACzC,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC;IAE5C,MAAM,MAAM,GAAG,IAAI,OAAO,CAAC;QACzB,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,YAAY,EAAE,MAAM,CAAC,YAAY;QACjC,WAAW,EAAE,MAAM,CAAC,WAAW;QAC/B,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,kBAAkB,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,SAAS;KAC7D,CAAC,CAAC;IAEH,kEAAkE;IAClE,MAAM,CAAC,UAAU,CAAC,oCAAoC,CAAC,CAAC;IAExD,mBAAmB;IACnB,WAAW,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IAElC,OAAO,MAAM,CAAC;AAChB,CAAC
|
|
1
|
+
{"version":3,"file":"clients.js","sourceRoot":"","sources":["../../../src/core/services/clients.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEhD,8DAA8D;AAC9D,MAAM,WAAW,GAAG,IAAI,GAAG,EAAmB,CAAC;AAE/C;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,OAAO,GAAG,SAAS;IAC5C,MAAM,QAAQ,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;IAEjC,oCAAoC;IACpC,IAAI,WAAW,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC9B,OAAO,WAAW,CAAC,GAAG,CAAC,QAAQ,CAAE,CAAC;IACpC,CAAC;IAED,sBAAsB;IACtB,MAAM,MAAM,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAC;IACzC,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC;IAE5C,MAAM,MAAM,GAAG,IAAI,OAAO,CAAC;QACzB,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,YAAY,EAAE,MAAM,CAAC,YAAY;QACjC,WAAW,EAAE,MAAM,CAAC,WAAW;QAC/B,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,kBAAkB,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,SAAS;KAC7D,CAAC,CAAC;IAEH,kEAAkE;IAClE,MAAM,CAAC,UAAU,CAAC,oCAAoC,CAAC,CAAC;IAExD,mBAAmB;IACnB,WAAW,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IAElC,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
import { getOwnerAddress } from "./agent-wallet.js";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*/
|
|
5
|
-
export declare const isWalletConfigured: () => boolean;
|
|
6
|
-
/**
|
|
7
|
-
* Get the address of the active wallet (works in both modes).
|
|
3
|
+
* Get the address of the active wallet (works in all modes).
|
|
8
4
|
*/
|
|
9
5
|
export declare const getWalletAddress: typeof getOwnerAddress;
|
|
10
6
|
/**
|
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getOwnerAddress, signMessageWithWallet, signTypedDataWithWallet } from "./agent-wallet.js";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*/
|
|
5
|
-
export const isWalletConfigured = () => {
|
|
6
|
-
return isAgentWalletConfigured() || !!(process.env.TRON_PRIVATE_KEY || process.env.TRON_MNEMONIC);
|
|
7
|
-
};
|
|
8
|
-
/**
|
|
9
|
-
* Get the address of the active wallet (works in both modes).
|
|
3
|
+
* Get the address of the active wallet (works in all modes).
|
|
10
4
|
*/
|
|
11
5
|
export const getWalletAddress = getOwnerAddress;
|
|
12
6
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wallet.js","sourceRoot":"","sources":["../../../src/core/services/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"wallet.js","sourceRoot":"","sources":["../../../src/core/services/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAEpG;;GAEG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,eAAe,CAAC;AAEhD;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,KAAK,EAAE,OAAe,EAAmB,EAAE;IACpE,OAAO,qBAAqB,CAAC,OAAO,CAAC,CAAC;AACxC,CAAC,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,KAAK,EAChC,MAAc,EACd,KAAa,EACb,KAAa,EACI,EAAE;IACnB,OAAO,uBAAuB,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;AACvD,CAAC,CAAC"}
|
|
@@ -35,7 +35,6 @@ import { registerAccountResourceTools } from "./account-resource.js";
|
|
|
35
35
|
* @param options Registration options (e.g., readOnly mode)
|
|
36
36
|
*/
|
|
37
37
|
export function registerTRONTools(server, options = {}) {
|
|
38
|
-
const { isWalletConfigured } = services;
|
|
39
38
|
/**
|
|
40
39
|
* Helper to register a tool with automatic wallet requirement detection.
|
|
41
40
|
* If a tool is not read-only or explicitly requires a wallet, it will only be
|
|
@@ -53,7 +52,7 @@ export function registerTRONTools(server, options = {}) {
|
|
|
53
52
|
return;
|
|
54
53
|
}
|
|
55
54
|
// 2. Skip if the tool needs a wallet but none is configured
|
|
56
|
-
if (walletNeeded &&
|
|
55
|
+
if (walletNeeded && services.getActiveWalletId() === null) {
|
|
57
56
|
return;
|
|
58
57
|
}
|
|
59
58
|
// Strip custom `requiresWallet` before passing to SDK (not a standard MCP annotation)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/tools/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,QAAQ,MAAM,sBAAsB,CAAC;AAEjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,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CAAC,EAAE,GAAG,mBAAmB,EAAE,GAAG,UAAU,CAAC,WAAW,CAAC;YAC7E,UAAU,GAAG,EAAE,GAAG,UAAU,EAAE,WAAW,EAAE,mBAAmB,EAAE,CAAC;QACnE,CAAC;QAED,MAAM,CAAC,YAAY,CAAC,IAAI,EAAE,UAAiB,EAAE,OAAc,CAAC,CAAC;IAC/D,CAAC,CAAC;IAEF,mBAAmB,CAAC,YAAY,CAAC,CAAC;IAClC,oBAAoB,CAAC,YAAY,CAAC,CAAC;IACnC,oBAAoB,CAAC,YAAY,CAAC,CAAC;IACnC,kBAAkB,CAAC,YAAY,CAAC,CAAC;IACjC,oBAAoB,CAAC,YAAY,CAAC,CAAC;IACnC,wBAAwB,CAAC,YAAY,CAAC,CAAC;IACvC,qBAAqB,CAAC,YAAY,CAAC,CAAC;IACpC,qBAAqB,CAAC,YAAY,CAAC,CAAC;IACpC,oBAAoB,CAAC,YAAY,CAAC,CAAC;IACnC,4BAA4B,CAAC,YAAY,CAAC,CAAC;IAC3C,kBAAkB,CAAC,YAAY,CAAC,CAAC;IACjC,sBAAsB,CAAC,YAAY,CAAC,CAAC;IACrC,iBAAiB,CAAC,YAAY,CAAC,CAAC;IAChC,oBAAoB,CAAC,YAAY,CAAC,CAAC;IACnC,kBAAkB,CAAC,YAAY,CAAC,CAAC;IACjC,oBAAoB,CAAC,YAAY,CAAC,CAAC;IACnC,uBAAuB,CAAC,YAAY,CAAC,CAAC;IACtC,qBAAqB,CAAC,YAAY,CAAC,CAAC;IACpC,wBAAwB,CAAC,YAAY,CAAC,CAAC;IACvC,yBAAyB,CAAC,YAAY,CAAC,CAAC;AAC1C,CAAC"}
|
|
@@ -66,7 +66,7 @@ export function registerWalletTools(registerTool) {
|
|
|
66
66
|
activeWalletId: activeId,
|
|
67
67
|
wallets,
|
|
68
68
|
message: wallets.length === 1 && wallets[0].id === "default"
|
|
69
|
-
? "
|
|
69
|
+
? "Using static wallet configured via environment variables."
|
|
70
70
|
: `Found ${wallets.length} wallet(s). Use select_wallet to switch the active wallet.`,
|
|
71
71
|
}, null, 2),
|
|
72
72
|
},
|
|
@@ -86,7 +86,7 @@ export function registerWalletTools(registerTool) {
|
|
|
86
86
|
}
|
|
87
87
|
});
|
|
88
88
|
registerTool("select_wallet", {
|
|
89
|
-
description: "Switch the active wallet at runtime. Use list_wallets to see available wallet IDs. Only available in
|
|
89
|
+
description: "Switch the active wallet at runtime. Use list_wallets to see available wallet IDs. Only available in Encrypted Storage mode.",
|
|
90
90
|
inputSchema: {
|
|
91
91
|
walletId: z.string().describe("The wallet ID to switch to"),
|
|
92
92
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wallet.js","sourceRoot":"","sources":["../../../src/core/tools/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,QAAQ,MAAM,sBAAsB,CAAC;AAGjD,MAAM,UAAU,mBAAmB,CAAC,YAA4B;IAC9D,YAAY,CACV,oBAAoB,EACpB;QACE,WAAW,EACT,sFAAsF;QACxF,WAAW,EAAE,EAAE;QACf,WAAW,EAAE;YACX,KAAK,EAAE,oBAAoB;YAC3B,YAAY,EAAE,IAAI;YAClB,cAAc,EAAE,IAAI;YACpB,eAAe,EAAE,KAAK;YACtB,cAAc,EAAE,IAAI;YACpB,aAAa,EAAE,KAAK;SACrB;KACF,EACD,KAAK,IAAI,EAAE;QACT,IAAI,CAAC;YACH,MAAM,OAAO,GAAG,MAAM,QAAQ,CAAC,eAAe,EAAE,CAAC;YACjD,MAAM,QAAQ,GAAG,QAAQ,CAAC,iBAAiB,EAAE,CAAC;YAC9C,OAAO;gBACL,OAAO,EAAE;oBACP;wBACE,IAAI,EAAE,MAAM;wBACZ,IAAI,EAAE,IAAI,CAAC,SAAS,CAClB;4BACE,QAAQ,EAAE,QAAQ,IAAI,SAAS;4BAC/B,OAAO;4BACP,MAAM,EAAE,QAAQ,CAAC,eAAe,CAAC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O,EAAE,EAAE,EAAE;QACpB,IAAI,CAAC;YACH,MAAM,aAAa,GAAG,MAAM,QAAQ,CAAC,eAAe,EAAE,CAAC;YACvD,MAAM,SAAS,GAAG,MAAM,QAAQ,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;YACtD,OAAO;gBACL,OAAO,EAAE;oBACP;wBACE,IAAI,EAAE,MAAM;wBACZ,IAAI,EAAE,IAAI,CAAC,SAAS,CAClB;4BACE,OAAO;4BACP,SAAS;4BACT,MAAM,EAAE,aAAa;4BACrB,WAAW,EAAE,eAAe;yBAC7B,EACD,IAAI,EACJ,CAAC,CACF;qBACF;iBACF;aACF,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO;gBACL,OAAO,EAAE;oBACP;wBACE,IAAI,EAAE,MAAM;wBACZ,IAAI,EAAE,0BAA0B,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;qBACzF;iBACF;gBACD,OAAO,EAAE,IAAI;aACd,CAAC;QACJ,CAAC;IACH,CAAC,CACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import express from "express";
|
|
2
|
+
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
|
|
3
|
+
import startServer, { MCP_PROTOCOL_VERSION, version } from "./server.js";
|
|
4
|
+
export function createHttpApp(options = {}) {
|
|
5
|
+
const app = express();
|
|
6
|
+
app.use(express.json({ limit: "10mb" })); // Prevent DoS attacks with huge payloads
|
|
7
|
+
app.post("/mcp", async (req, res) => {
|
|
8
|
+
console.log(`Received POST /mcp request from ${req.ip}`);
|
|
9
|
+
let server;
|
|
10
|
+
const transport = new StreamableHTTPServerTransport({
|
|
11
|
+
sessionIdGenerator: undefined,
|
|
12
|
+
});
|
|
13
|
+
try {
|
|
14
|
+
server = await startServer({ readOnly: options.readOnly });
|
|
15
|
+
await server.connect(transport);
|
|
16
|
+
await transport.handleRequest(req, res, req.body);
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
console.error(`Error handling request: ${error}`);
|
|
20
|
+
if (!res.headersSent) {
|
|
21
|
+
res.status(500).json({ error: "Internal server error" });
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
finally {
|
|
25
|
+
if (server) {
|
|
26
|
+
await server.close().catch((closeError) => {
|
|
27
|
+
console.error(`Error closing stateless server: ${closeError}`);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
app.get("/mcp", async (_req, res) => {
|
|
33
|
+
res.setHeader("Allow", "POST");
|
|
34
|
+
res.status(405).json({ error: "GET not supported for stateless Streamable HTTP" });
|
|
35
|
+
});
|
|
36
|
+
app.delete("/mcp", async (_req, res) => {
|
|
37
|
+
res.setHeader("Allow", "POST");
|
|
38
|
+
res.status(405).json({ error: "DELETE not supported for stateless Streamable HTTP" });
|
|
39
|
+
});
|
|
40
|
+
app.get("/health", (_req, res) => {
|
|
41
|
+
res.status(200).json({
|
|
42
|
+
status: "ok",
|
|
43
|
+
server: "ready",
|
|
44
|
+
mode: "stateless",
|
|
45
|
+
activeSessions: 0,
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
app.get("/", (_req, res) => {
|
|
49
|
+
res.status(200).json({
|
|
50
|
+
name: "mcp-server-tron",
|
|
51
|
+
version,
|
|
52
|
+
protocol: `MCP ${MCP_PROTOCOL_VERSION}`,
|
|
53
|
+
transport: "Streamable HTTP",
|
|
54
|
+
mode: "stateless",
|
|
55
|
+
endpoints: {
|
|
56
|
+
mcp: "/mcp",
|
|
57
|
+
health: "/health",
|
|
58
|
+
},
|
|
59
|
+
status: "ready",
|
|
60
|
+
activeSessions: 0,
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
return {
|
|
64
|
+
app,
|
|
65
|
+
shutdown: async () => { },
|
|
66
|
+
getActiveSessionCount: () => 0,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=http-app.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-app.js","sourceRoot":"","sources":["../../src/server/http-app.ts"],"names":[],"mappings":"AAAA,OAAO,OAA8B,MAAM,SAAS,CAAC;AACrD,OAAO,EAAE,6BAA6B,EAAE,MAAM,oDAAoD,CAAC;AACnG,OAAO,WAAW,EAAE,EAAE,oBAAoB,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAQzE,MAAM,UAAU,aAAa,CAAC,UAAkC,EAAE;IAChE,MAAM,GAAG,GAAG,OAAO,EAAE,CAAC;IACtB,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC,yCAAyC;IAEnF,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,GAAY,EAAE,GAAa,EAAE,EAAE;QACrD,OAAO,CAAC,GAAG,CAAC,mCAAmC,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC;QACzD,IAAI,MAA2D,CAAC;QAChE,MAAM,SAAS,GAAG,IAAI,6BAA6B,CAAC;YAClD,kBAAkB,EAAE,SAAS;SAC9B,CAAC,CAAC;QAEH,IAAI,CAAC;YACH,MAAM,GAAG,MAAM,WAAW,CAAC,EAAE,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;YAC3D,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;YAChC,MAAM,SAAS,CAAC,aAAa,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC;QACpD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,2BAA2B,KAAK,EAAE,CAAC,CAAC;YAClD,IAAI,CAAC,GAAG,CAAC,WAAW,EA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C,GAAG,CAAC,GAAG,EAAE,CAAC,IAAa,EAAE,GAAa,EAAE,EAAE;QAC5C,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;YACnB,IAAI,EAAE,iBAAiB;YACvB,OAAO;YACP,QAAQ,EAAE,OAAO,oBAAoB,EAAE;YACvC,SAAS,EAAE,iBAAiB;YAC5B,IAAI,EAAE,WAAW;YACjB,SAAS,EAAE;gBACT,GAAG,EAAE,MAAM;gBACX,MAAM,EAAE,SAAS;aAClB;YACD,MAAM,EAAE,OAAO;YACf,cAAc,EAAE,CAAC;SAClB,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,OAAO;QACL,GAAG;QACH,QAAQ,EAAE,KAAK,IAAI,EAAE,GAAE,CAAC;QACxB,qBAAqB,EAAE,GAAG,EAAE,CAAC,CAAC;KAC/B,CAAC;AACJ,CAAC"}
|
|
@@ -1,191 +1,29 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import startServer, { MCP_PROTOCOL_VERSION, version } from "./server.js";
|
|
4
|
-
import express from "express";
|
|
1
|
+
import { createHttpApp } from "./http-app.js";
|
|
2
|
+
import { MCP_PROTOCOL_VERSION } from "./server.js";
|
|
5
3
|
// Environment variables
|
|
6
4
|
const PORT = parseInt(process.env.MCP_PORT || "3001", 10);
|
|
7
5
|
const HOST = process.env.MCP_HOST || "0.0.0.0";
|
|
8
|
-
console.
|
|
9
|
-
// Setup Express
|
|
10
|
-
const app = express();
|
|
11
|
-
app.use(express.json({ limit: "10mb" })); // Prevent DoS attacks with huge payloads
|
|
12
|
-
// Track active transports by session ID with cleanup
|
|
13
|
-
const transports = new Map();
|
|
14
|
-
const sessionTimestamps = new Map();
|
|
15
|
-
const SESSION_TIMEOUT_MS = 30 * 60 * 1000; // 30 minutes
|
|
16
|
-
// Cleanup stale sessions periodically
|
|
17
|
-
setInterval(() => {
|
|
18
|
-
const now = Date.now();
|
|
19
|
-
for (const [sessionId, timestamp] of sessionTimestamps.entries()) {
|
|
20
|
-
if (now - timestamp > SESSION_TIMEOUT_MS) {
|
|
21
|
-
console.error(`Cleaning up stale session: ${sessionId}`);
|
|
22
|
-
const transport = transports.get(sessionId);
|
|
23
|
-
if (transport) {
|
|
24
|
-
transport
|
|
25
|
-
.close()
|
|
26
|
-
.catch((err) => console.error(`Error closing stale session ${sessionId}:`, err));
|
|
27
|
-
}
|
|
28
|
-
transports.delete(sessionId);
|
|
29
|
-
sessionTimestamps.delete(sessionId);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}, 5 * 60 * 1000); // Check every 5 minutes
|
|
33
|
-
// Initialize the MCP server
|
|
34
|
-
let server = null;
|
|
6
|
+
console.log(`Configured to listen on ${HOST}:${PORT}`);
|
|
35
7
|
const isReadOnly = process.argv.includes("--readonly") || process.argv.includes("-r");
|
|
36
|
-
|
|
37
|
-
.then((s) => {
|
|
38
|
-
server = s;
|
|
39
|
-
console.error(`MCP Server initialized successfully${isReadOnly ? " in readonly mode" : ""}`);
|
|
40
|
-
})
|
|
41
|
-
.catch((error) => {
|
|
42
|
-
console.error("Failed to initialize server:", error);
|
|
43
|
-
process.exit(1);
|
|
44
|
-
});
|
|
45
|
-
// Handle all MCP requests through POST /mcp
|
|
46
|
-
app.post("/mcp", async (req, res) => {
|
|
47
|
-
console.error(`Received POST /mcp request from ${req.ip}`);
|
|
48
|
-
if (!server) {
|
|
49
|
-
console.error("Server not initialized yet");
|
|
50
|
-
res.status(503).json({ error: "Server not initialized" });
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
// Check for existing session
|
|
54
|
-
const sessionId = req.headers["mcp-session-id"];
|
|
55
|
-
let transport;
|
|
56
|
-
if (sessionId && transports.has(sessionId)) {
|
|
57
|
-
// Reuse existing transport for this session
|
|
58
|
-
transport = transports.get(sessionId);
|
|
59
|
-
sessionTimestamps.set(sessionId, Date.now()); // Update last activity
|
|
60
|
-
console.error(`Reusing transport for session: ${sessionId}`);
|
|
61
|
-
}
|
|
62
|
-
else if (!sessionId) {
|
|
63
|
-
// New session - create transport with session ID generator
|
|
64
|
-
transport = new StreamableHTTPServerTransport({
|
|
65
|
-
sessionIdGenerator: () => randomUUID(),
|
|
66
|
-
onsessioninitialized: (newSessionId) => {
|
|
67
|
-
console.error(`Session initialized: ${newSessionId}`);
|
|
68
|
-
transports.set(newSessionId, transport);
|
|
69
|
-
sessionTimestamps.set(newSessionId, Date.now());
|
|
70
|
-
},
|
|
71
|
-
onsessionclosed: (closedSessionId) => {
|
|
72
|
-
console.error(`Session closed: ${closedSessionId}`);
|
|
73
|
-
transports.delete(closedSessionId);
|
|
74
|
-
sessionTimestamps.delete(closedSessionId);
|
|
75
|
-
},
|
|
76
|
-
});
|
|
77
|
-
// Connect the transport to the server
|
|
78
|
-
await server.connect(transport);
|
|
79
|
-
console.error("New transport connected to server");
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
// Invalid session ID provided
|
|
83
|
-
console.error(`Invalid session ID: ${sessionId}`);
|
|
84
|
-
res.status(404).json({ error: "Session not found" });
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
// Handle the request
|
|
88
|
-
try {
|
|
89
|
-
await transport.handleRequest(req, res, req.body);
|
|
90
|
-
}
|
|
91
|
-
catch (error) {
|
|
92
|
-
console.error(`Error handling request: ${error}`);
|
|
93
|
-
if (!res.headersSent) {
|
|
94
|
-
res.status(500).json({ error: "Internal server error" });
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
// Handle GET requests for SSE streams (server-to-client notifications)
|
|
99
|
-
app.get("/mcp", async (req, res) => {
|
|
100
|
-
console.error(`Received GET /mcp request from ${req.ip}`);
|
|
101
|
-
if (!server) {
|
|
102
|
-
res.status(503).json({ error: "Server not initialized" });
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
const sessionId = req.headers["mcp-session-id"];
|
|
106
|
-
if (!sessionId || !transports.has(sessionId)) {
|
|
107
|
-
res.status(400).json({ error: "Invalid or missing session ID" });
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
const transport = transports.get(sessionId);
|
|
111
|
-
try {
|
|
112
|
-
await transport.handleRequest(req, res);
|
|
113
|
-
}
|
|
114
|
-
catch (error) {
|
|
115
|
-
console.error(`Error handling SSE request: ${error}`);
|
|
116
|
-
if (!res.headersSent) {
|
|
117
|
-
res.status(500).json({ error: "Internal server error" });
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
// Handle DELETE requests to close sessions
|
|
122
|
-
app.delete("/mcp", async (req, res) => {
|
|
123
|
-
const sessionId = req.headers["mcp-session-id"];
|
|
124
|
-
if (!sessionId || !transports.has(sessionId)) {
|
|
125
|
-
res.status(404).json({ error: "Session not found" });
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
const transport = transports.get(sessionId);
|
|
129
|
-
try {
|
|
130
|
-
await transport.handleRequest(req, res);
|
|
131
|
-
}
|
|
132
|
-
catch (error) {
|
|
133
|
-
console.error(`Error closing session: ${error}`);
|
|
134
|
-
if (!res.headersSent) {
|
|
135
|
-
res.status(500).json({ error: "Internal server error" });
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
// Health check endpoint
|
|
140
|
-
app.get("/health", (_req, res) => {
|
|
141
|
-
res.status(200).json({
|
|
142
|
-
status: "ok",
|
|
143
|
-
server: server ? "initialized" : "initializing",
|
|
144
|
-
activeSessions: transports.size,
|
|
145
|
-
});
|
|
146
|
-
});
|
|
147
|
-
// Root endpoint for basic info
|
|
148
|
-
app.get("/", (_req, res) => {
|
|
149
|
-
res.status(200).json({
|
|
150
|
-
name: "mcp-server-tron",
|
|
151
|
-
version,
|
|
152
|
-
protocol: `MCP ${MCP_PROTOCOL_VERSION}`,
|
|
153
|
-
transport: "Streamable HTTP",
|
|
154
|
-
endpoints: {
|
|
155
|
-
mcp: "/mcp",
|
|
156
|
-
health: "/health",
|
|
157
|
-
},
|
|
158
|
-
status: server ? "ready" : "initializing",
|
|
159
|
-
activeSessions: transports.size,
|
|
160
|
-
});
|
|
161
|
-
});
|
|
8
|
+
const { app, shutdown } = createHttpApp({ readOnly: isReadOnly });
|
|
162
9
|
// Handle process termination gracefully
|
|
163
10
|
process.on("SIGINT", async () => {
|
|
164
|
-
console.
|
|
165
|
-
|
|
166
|
-
for (const [sessionId, transport] of transports) {
|
|
167
|
-
console.error(`Closing transport for session: ${sessionId}`);
|
|
168
|
-
await transport.close();
|
|
169
|
-
}
|
|
170
|
-
transports.clear();
|
|
11
|
+
console.log("Shutting down server...");
|
|
12
|
+
await shutdown();
|
|
171
13
|
process.exit(0);
|
|
172
14
|
});
|
|
173
15
|
process.on("SIGTERM", async () => {
|
|
174
|
-
console.
|
|
175
|
-
|
|
176
|
-
console.error(`Closing transport for session: ${sessionId}`);
|
|
177
|
-
await transport.close();
|
|
178
|
-
}
|
|
179
|
-
transports.clear();
|
|
16
|
+
console.log("Received SIGTERM, shutting down...");
|
|
17
|
+
await shutdown();
|
|
180
18
|
process.exit(0);
|
|
181
19
|
});
|
|
182
20
|
// Start the HTTP server
|
|
183
21
|
const httpServer = app
|
|
184
22
|
.listen(PORT, HOST, () => {
|
|
185
|
-
console.
|
|
186
|
-
console.
|
|
187
|
-
console.
|
|
188
|
-
console.
|
|
23
|
+
console.log(`mcp-server-tron running at http://${HOST}:${PORT}`);
|
|
24
|
+
console.log(`MCP endpoint: http://${HOST}:${PORT}/mcp`);
|
|
25
|
+
console.log(`Health check: http://${HOST}:${PORT}/health`);
|
|
26
|
+
console.log(`Protocol: MCP ${MCP_PROTOCOL_VERSION} (Streamable HTTP)`);
|
|
189
27
|
})
|
|
190
28
|
.on("error", (err) => {
|
|
191
29
|
console.error(`Server error: ${err}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http-server.js","sourceRoot":"","sources":["../../src/server/http-server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
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,CAAC,KAAK,CAAC,wCAAwC,CAAC,CAAC;QAC1D,CAAC;QACD,OAAO,CAAC,KAAK,CAAC,iBAAiB,oBAAoB,EAAE,CAAC,CAAC;QACvD,OAAO,CAAC,KAAK,CAAC,uBAAuB,oBAAoB,EAAE,CAAC,MAAM,WAAW,CAAC,CAAC;QAC/E,OAAO,CAAC,KAAK,CAAC,oCAAoC,CAAC,CAAC;QAEpD,OAAO,MAAM,CAAC;IAChB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,8BAA8B,EAAE,KAAK,CAAC,CAAC;QACrD,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC;AAED,sCAAsC;AACtC,eAAe,WAAW,CAAC"}
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"mcpName": "io.github.bankofai/mcp-server-tron",
|
|
4
4
|
"module": "src/index.ts",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"version": "1.1.
|
|
6
|
+
"version": "1.1.6",
|
|
7
7
|
"description": "MCP server for TRON blockchain. Supports TRX/TRC20 transfers, smart contracts, and AI prompts.",
|
|
8
8
|
"bin": {
|
|
9
9
|
"mcp-server-tron": "./bin/cli.js"
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"typescript": "^5.8.2"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@bankofai/agent-wallet": "^2.
|
|
56
|
+
"@bankofai/agent-wallet": "^2.2.0",
|
|
57
57
|
"@modelcontextprotocol/sdk": "^1.22.0",
|
|
58
58
|
"@scure/bip32": "^2.0.1",
|
|
59
59
|
"@scure/bip39": "^2.0.1",
|