gate-mcp 0.4.1 → 0.5.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.
- package/README.md +71 -19
- package/dist/config.d.ts +9 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +45 -0
- package/dist/config.js.map +1 -0
- package/dist/index.js +31 -14
- package/dist/index.js.map +1 -1
- package/dist/tools/account.js +10 -10
- package/dist/tools/delivery.js +11 -11
- package/dist/tools/earn.d.ts.map +1 -1
- package/dist/tools/earn.js +378 -25
- package/dist/tools/earn.js.map +1 -1
- package/dist/tools/flash_swap.js +5 -5
- package/dist/tools/futures.js +45 -45
- package/dist/tools/margin.js +5 -5
- package/dist/tools/options.js +13 -13
- package/dist/tools/spot.js +28 -28
- package/dist/tools/sub_account.js +11 -11
- package/dist/tools/unified.js +16 -16
- package/dist/tools/wallet.js +12 -12
- package/dist/utils.d.ts +6 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +13 -0
- package/dist/utils.js.map +1 -1
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
# gate-local-mcp
|
|
2
2
|
|
|
3
|
-
A local (stdio) MCP server that exposes the full [Gate
|
|
3
|
+
A local (stdio) MCP server that exposes the full [Gate](https://www.gate.com) API v4 to any MCP-compatible client (Claude Desktop, etc.).
|
|
4
4
|
|
|
5
|
-
**Quickstart guides:** [English](quickstart.md) · [中文](quickstart_zh.md)
|
|
5
|
+
**Quickstart guides:** [English](docs/quickstart.md) · [中文](docs/quickstart_zh.md)
|
|
6
6
|
|
|
7
7
|
> **Looking for the remote MCP server?** If you need HTTP/SSE-based remote access instead of local stdio, see [gate/gate-mcp](https://github.com/gate/gate-mcp).
|
|
8
8
|
|
|
9
9
|
## Features
|
|
10
10
|
|
|
11
|
-
- **
|
|
11
|
+
- **161 tools** covering Spot, Futures, Delivery, Margin, Wallet, Account, Options, Earn, Flash Swap, Unified, and Sub-Account APIs
|
|
12
12
|
- **Zero config for public endpoints** — market data, tickers, order books work without any credentials
|
|
13
13
|
- **Authenticated endpoints** — trading, wallet, and account tools activate automatically when `GATE_API_KEY` + `GATE_API_SECRET` env vars are set
|
|
14
14
|
- **Testnet support** — set `GATE_BASE_URL` to use the testnet endpoint
|
|
15
|
+
- **Module filtering** — load only the modules you need via `GATE_MODULES` or `--modules`; use `GATE_READONLY` or `--readonly` to restrict to read-only tools
|
|
15
16
|
|
|
16
17
|
## Quick Start (Claude Desktop)
|
|
17
18
|
|
|
@@ -63,6 +64,53 @@ A local (stdio) MCP server that exposes the full [Gate.com](https://www.gate.com
|
|
|
63
64
|
}
|
|
64
65
|
```
|
|
65
66
|
|
|
67
|
+
## Module Filtering
|
|
68
|
+
|
|
69
|
+
By default all 161 tools (11 modules) are registered. To reduce the tool count (e.g. Cursor warns above 80), restrict to specific modules:
|
|
70
|
+
|
|
71
|
+
**CLI flags:**
|
|
72
|
+
```bash
|
|
73
|
+
# Load only spot and futures tools (73 tools)
|
|
74
|
+
GATE_API_KEY=... npx gate-mcp --modules=spot,futures
|
|
75
|
+
|
|
76
|
+
# Load futures tools in read-only mode (26 tools)
|
|
77
|
+
npx gate-mcp --modules=futures --readonly
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
**MCP config (env vars):**
|
|
81
|
+
```json
|
|
82
|
+
{
|
|
83
|
+
"mcpServers": {
|
|
84
|
+
"gate": {
|
|
85
|
+
"command": "npx",
|
|
86
|
+
"args": ["-y", "gate-mcp"],
|
|
87
|
+
"env": {
|
|
88
|
+
"GATE_MODULES": "spot,futures",
|
|
89
|
+
"GATE_READONLY": "true",
|
|
90
|
+
"GATE_API_KEY": "your-api-key",
|
|
91
|
+
"GATE_API_SECRET": "your-api-secret"
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
**Available modules:** `spot`, `futures`, `delivery`, `margin`, `wallet`, `account`, `options`, `earn`, `flash_swap`, `unified`, `sub_account`
|
|
99
|
+
|
|
100
|
+
| Module | Total | Read-only |
|
|
101
|
+
|---|---|---|
|
|
102
|
+
| spot | 28 | 18 |
|
|
103
|
+
| futures | 45 | 26 |
|
|
104
|
+
| delivery | 11 | 9 |
|
|
105
|
+
| margin | 5 | 4 |
|
|
106
|
+
| wallet | 12 | 9 |
|
|
107
|
+
| account | 10 | 6 |
|
|
108
|
+
| options | 13 | 11 |
|
|
109
|
+
| earn | 5 | 5 |
|
|
110
|
+
| flash_swap | 5 | 4 |
|
|
111
|
+
| unified | 16 | 12 |
|
|
112
|
+
| sub_account | 11 | 5 |
|
|
113
|
+
|
|
66
114
|
## Environment Variables
|
|
67
115
|
|
|
68
116
|
| Variable | Required | Default | Description |
|
|
@@ -70,41 +118,45 @@ A local (stdio) MCP server that exposes the full [Gate.com](https://www.gate.com
|
|
|
70
118
|
| `GATE_API_KEY` | No | — | API key for authenticated endpoints |
|
|
71
119
|
| `GATE_API_SECRET` | No | — | API secret for authenticated endpoints |
|
|
72
120
|
| `GATE_BASE_URL` | No | `https://api.gateio.ws` | Override base URL (e.g. for testnet) |
|
|
121
|
+
| `GATE_MODULES` | No | all modules | Comma-separated list of modules to load (e.g. `spot,futures`) |
|
|
122
|
+
| `GATE_READONLY` | No | `false` | Set to `true` to disable all write (order/transfer) tools |
|
|
73
123
|
|
|
74
124
|
## Available Tools
|
|
75
125
|
|
|
126
|
+
Tools marked `*` require authentication (`GATE_API_KEY` + `GATE_API_SECRET`).
|
|
127
|
+
|
|
76
128
|
### Spot (28 tools)
|
|
77
|
-
`
|
|
129
|
+
`cex_spot_list_currencies`, `cex_spot_get_currency`, `cex_spot_list_currency_pairs`, `cex_spot_get_currency_pair`, `cex_spot_get_spot_tickers`, `cex_spot_get_spot_order_book`, `cex_spot_get_spot_trades`, `cex_spot_get_spot_candlesticks`, `cex_spot_get_spot_fee`\*, `cex_spot_get_spot_accounts`\*, `cex_spot_list_spot_account_book`\*, `cex_spot_list_spot_orders`\*, `cex_spot_create_spot_order`\*, `cex_spot_get_spot_order`\*, `cex_spot_cancel_spot_order`\*, `cex_spot_amend_spot_order`\*, `cex_spot_cancel_all_spot_orders`\*, `cex_spot_create_spot_batch_orders`\*, `cex_spot_cancel_spot_batch_orders`\*, `cex_spot_get_spot_batch_fee`\*, `cex_spot_list_spot_my_trades`\*, `cex_spot_list_all_open_orders`\*, `cex_spot_list_spot_price_triggered_orders`\*, `cex_spot_create_spot_price_triggered_order`\*, `cex_spot_get_spot_price_triggered_order`\*, `cex_spot_cancel_spot_price_triggered_order`\*, `cex_spot_cancel_spot_price_triggered_order_list`\*, `cex_spot_countdown_cancel_all_spot`\*
|
|
78
130
|
|
|
79
|
-
### Futures (
|
|
80
|
-
`
|
|
131
|
+
### Futures (45 tools) — prefix abbreviated to `cex_fx_`
|
|
132
|
+
`cex_fx_list_fx_contracts`, `cex_fx_get_fx_contract`, `cex_fx_get_fx_order_book`, `cex_fx_get_fx_candlesticks`, `cex_fx_get_fx_tickers`, `cex_fx_get_fx_funding_rate`, `cex_fx_get_fx_trades`, `cex_fx_list_contract_stats`, `cex_fx_get_fx_premium_index`, `cex_fx_get_fx_accounts`\*, `cex_fx_list_fx_account_book`\*, `cex_fx_get_fx_fee`\*, `cex_fx_list_fx_positions`\*, `cex_fx_get_fx_position`\*, `cex_fx_get_leverage`\*, `cex_fx_update_fx_position_leverage`\*, `cex_fx_update_fx_position_margin`\*, `cex_fx_update_fx_position_risk_limit`\*, `cex_fx_list_fx_orders`\*, `cex_fx_create_fx_order`\*, `cex_fx_get_fx_order`\*, `cex_fx_cancel_fx_order`\*, `cex_fx_cancel_all_fx_orders`\*, `cex_fx_amend_fx_order`\*, `cex_fx_create_fx_batch_orders`\*, `cex_fx_cancel_fx_batch_orders`\*, `cex_fx_get_fx_orders_with_time_range`\*, `cex_fx_list_fx_my_trades`\*, `cex_fx_get_fx_my_trades_timerange`\*, `cex_fx_list_position_close`\*, `cex_fx_list_fx_liq_orders`\*, `cex_fx_list_price_triggered_orders`\*, `cex_fx_create_fx_price_triggered_order`\*, `cex_fx_get_fx_price_triggered_order`\*, `cex_fx_cancel_fx_price_triggered_order`\*, `cex_fx_cancel_fx_price_triggered_order_list`\*, `cex_fx_countdown_cancel_all_fx`\*, `cex_fx_list_fx_risk_limit_tiers`\*, `cex_fx_set_fx_dual`\*, `cex_fx_get_fx_dual_position`\*, `cex_fx_update_fx_dual_position_margin`\*, `cex_fx_update_fx_dual_position_leverage`\*, `cex_fx_update_fx_dual_position_risk_limit`\*, `cex_fx_update_fx_position_cross_mode`\*, `cex_fx_update_fx_dual_position_cross_mode`\*
|
|
81
133
|
|
|
82
134
|
### Delivery (11 tools)
|
|
83
|
-
`
|
|
135
|
+
`cex_delivery_list_delivery_contracts`, `cex_delivery_get_delivery_contract`, `cex_delivery_list_delivery_order_book`, `cex_delivery_list_delivery_candlesticks`, `cex_delivery_list_delivery_tickers`, `cex_delivery_list_delivery_accounts`\*, `cex_delivery_list_delivery_positions`\*, `cex_delivery_list_delivery_orders`\*, `cex_delivery_create_delivery_order`\*, `cex_delivery_cancel_delivery_order`\*, `cex_delivery_get_my_delivery_trades`\*
|
|
84
136
|
|
|
85
137
|
### Margin (5 tools)
|
|
86
|
-
`
|
|
138
|
+
`cex_margin_list_margin_accounts`\*, `cex_margin_list_margin_account_book`\*, `cex_margin_get_auto_repay_status`\*, `cex_margin_set_auto_repay`\*, `cex_margin_get_margin_transferable`\*
|
|
87
139
|
|
|
88
|
-
### Wallet (
|
|
89
|
-
`
|
|
140
|
+
### Wallet (12 tools)
|
|
141
|
+
`cex_wallet_list_currency_chains`, `cex_wallet_get_total_balance`\*, `cex_wallet_list_withdrawals`\*, `cex_wallet_list_deposits`\*, `cex_wallet_get_deposit_address`\*, `cex_wallet_create_transfer`\*, `cex_wallet_list_sa_balances`\*, `cex_wallet_get_wallet_fee`\*, `cex_wallet_create_sa_transfer`\*, `cex_wallet_create_sa_to_sa_transfer`\*, `cex_wallet_get_transfer_order_status`\*, `cex_wallet_list_withdraw_status`\*
|
|
90
142
|
|
|
91
143
|
### Account (10 tools)
|
|
92
|
-
`
|
|
144
|
+
`cex_account_get_account_detail`\*, `cex_account_get_account_rate_limit`\*, `cex_account_get_debit_fee`\*, `cex_account_set_debit_fee`\*, `cex_account_get_account_main_keys`\*, `cex_account_list_stp_groups`\*, `cex_account_create_stp_group`\*, `cex_account_list_stp_group_users`\*, `cex_account_add_stp_group_users`\*, `cex_account_delete_stp_group_user`\*
|
|
93
145
|
|
|
94
146
|
### Options (13 tools)
|
|
95
|
-
`
|
|
147
|
+
`cex_options_list_options_underlyings`, `cex_options_list_options_expirations`, `cex_options_list_options_contracts`, `cex_options_get_options_contract`, `cex_options_list_options_order_book`, `cex_options_list_options_tickers`, `cex_options_list_options_candlesticks`, `cex_options_list_options_account`\*, `cex_options_list_options_positions`\*, `cex_options_list_options_orders`\*, `cex_options_create_options_order`\*, `cex_options_cancel_options_order`\*, `cex_options_list_my_options_trades`\*
|
|
96
148
|
|
|
97
149
|
### Earn (5 tools)
|
|
98
|
-
`
|
|
150
|
+
`cex_earn_list_dual_investment_plans`, `cex_earn_list_structured_products`, `cex_earn_list_dual_orders`\*, `cex_earn_list_dual_balance`\*, `cex_earn_list_structured_orders`\*
|
|
99
151
|
|
|
100
|
-
### Flash Swap (5 tools)
|
|
101
|
-
`
|
|
152
|
+
### Flash Swap (5 tools) — prefix abbreviated to `cex_fc_`
|
|
153
|
+
`cex_fc_list_fc_currency_pairs`, `cex_fc_preview_fc_order`\*, `cex_fc_create_fc_order`\*, `cex_fc_list_fc_orders`\*, `cex_fc_get_fc_order`\*
|
|
102
154
|
|
|
103
155
|
### Unified Account (16 tools)
|
|
104
|
-
`
|
|
156
|
+
`cex_unified_list_currency_discount_tiers`, `cex_unified_get_unified_accounts`\*, `cex_unified_list_unified_currencies`\*, `cex_unified_get_unified_mode`\*, `cex_unified_set_unified_mode`\*, `cex_unified_get_unified_risk_units`\*, `cex_unified_get_unified_borrowable`\*, `cex_unified_get_unified_transferable`\*, `cex_unified_get_unified_estimate_rate`\*, `cex_unified_list_unified_loans`\*, `cex_unified_create_unified_loan`\*, `cex_unified_list_unified_loan_records`\*, `cex_unified_list_unified_loan_interest_records`\*, `cex_unified_get_user_leverage_currency_setting`\*, `cex_unified_set_user_leverage_currency_setting`\*, `cex_unified_set_unified_collateral`\*
|
|
105
157
|
|
|
106
|
-
### Sub-Account (
|
|
107
|
-
`
|
|
158
|
+
### Sub-Account (11 tools) — prefix abbreviated to `cex_sa_`
|
|
159
|
+
`cex_sa_list_sas`\*, `cex_sa_create_sa`\*, `cex_sa_get_sa`\*, `cex_sa_lock_sa`\*, `cex_sa_unlock_sa`\*, `cex_sa_list_sa_keys`\*, `cex_sa_get_sa_key`\*, `cex_sa_create_sa_key`\*, `cex_sa_update_sa_key`\*, `cex_sa_get_sa_unified_mode`\*, `cex_sa_delete_sa_key`\*
|
|
108
160
|
|
|
109
161
|
*\* Requires authentication (`GATE_API_KEY` + `GATE_API_SECRET`)*
|
|
110
162
|
|
|
@@ -133,7 +185,7 @@ echo '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":
|
|
|
133
185
|
|
|
134
186
|
# Get BTC_USDT ticker (public, no auth)
|
|
135
187
|
echo '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"test","version":"1.0"}}}
|
|
136
|
-
{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"
|
|
188
|
+
{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"cex_spot_get_spot_tickers","arguments":{"currency_pair":"BTC_USDT"}}}' | node dist/index.js
|
|
137
189
|
```
|
|
138
190
|
|
|
139
191
|
## License
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const VALID_MODULES: readonly ["spot", "futures", "delivery", "margin", "wallet", "account", "options", "earn", "flash_swap", "unified", "sub_account"];
|
|
2
|
+
export type ModuleName = typeof VALID_MODULES[number];
|
|
3
|
+
export interface ServerConfig {
|
|
4
|
+
/** null means all modules */
|
|
5
|
+
modules: Set<ModuleName> | null;
|
|
6
|
+
readonly: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare function parseConfig(): ServerConfig;
|
|
9
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,oIAGhB,CAAC;AAEX,MAAM,MAAM,UAAU,GAAG,OAAO,aAAa,CAAC,MAAM,CAAC,CAAC;AAEtD,MAAM,WAAW,YAAY;IAC3B,6BAA6B;IAC7B,OAAO,EAAE,GAAG,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC;IAChC,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,wBAAgB,WAAW,IAAI,YAAY,CAyC1C"}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export const VALID_MODULES = [
|
|
2
|
+
'spot', 'futures', 'delivery', 'margin', 'wallet',
|
|
3
|
+
'account', 'options', 'earn', 'flash_swap', 'unified', 'sub_account',
|
|
4
|
+
];
|
|
5
|
+
export function parseConfig() {
|
|
6
|
+
// --- readonly ---
|
|
7
|
+
let readonly = process.env.GATE_READONLY === 'true';
|
|
8
|
+
if (process.argv.includes('--readonly'))
|
|
9
|
+
readonly = true;
|
|
10
|
+
// --- modules ---
|
|
11
|
+
// CLI flag: --modules=spot,futures OR --modules spot,futures
|
|
12
|
+
let modulesRaw = process.env.GATE_MODULES;
|
|
13
|
+
const flagIndex = process.argv.findIndex(a => a.startsWith('--modules'));
|
|
14
|
+
if (flagIndex !== -1) {
|
|
15
|
+
const arg = process.argv[flagIndex];
|
|
16
|
+
if (arg.includes('=')) {
|
|
17
|
+
modulesRaw = arg.split('=')[1];
|
|
18
|
+
}
|
|
19
|
+
else if (process.argv[flagIndex + 1] && !process.argv[flagIndex + 1].startsWith('--')) {
|
|
20
|
+
modulesRaw = process.argv[flagIndex + 1];
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
console.error(`[gate-mcp] --modules flag requires a value (e.g. --modules=spot,futures). Loading all modules.`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (!modulesRaw || modulesRaw.trim() === '') {
|
|
27
|
+
return { modules: null, readonly };
|
|
28
|
+
}
|
|
29
|
+
const requested = modulesRaw.split(',').map(s => s.trim().toLowerCase());
|
|
30
|
+
const valid = new Set();
|
|
31
|
+
for (const name of requested) {
|
|
32
|
+
if (VALID_MODULES.includes(name)) {
|
|
33
|
+
valid.add(name);
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
console.error(`[gate-mcp] Unknown module "${name}" — ignored. Valid modules: ${VALID_MODULES.join(', ')}`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (valid.size === 0) {
|
|
40
|
+
console.error('[gate-mcp] No valid modules specified — loading all modules.');
|
|
41
|
+
return { modules: null, readonly };
|
|
42
|
+
}
|
|
43
|
+
return { modules: valid, readonly };
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,QAAQ;IACjD,SAAS,EAAE,SAAS,EAAE,MAAM,EAAE,YAAY,EAAE,SAAS,EAAE,aAAa;CAC5D,CAAC;AAUX,MAAM,UAAU,WAAW;IACzB,mBAAmB;IACnB,IAAI,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,aAAa,KAAK,MAAM,CAAC;IACpD,IAAI,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,Y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,MAAM,IAAI,IAAI,SAAS,EAAE,CAAC;QAC7B,IAAK,aAAmC,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;YACxD,KAAK,CAAC,GAAG,CAAC,IAAkB,CAAC,CAAC;QAChC,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,KAAK,CAAC,8BAA8B,IAAI,+BAA+B,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC7G,CAAC;IACH,CAAC;IAED,IAAI,KAAK,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC;QACrB,OAAO,CAAC,KAAK,CAAC,8DAA8D,CAAC,CAAC;QAC9E,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;IACrC,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC;AACtC,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
3
3
|
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
4
|
-
import { sanitizeToolName } from './utils.js';
|
|
4
|
+
import { sanitizeToolName, isWriteTool } from './utils.js';
|
|
5
|
+
import { parseConfig } from './config.js';
|
|
5
6
|
import { registerSpotTools } from './tools/spot.js';
|
|
6
7
|
import { registerFuturesTools } from './tools/futures.js';
|
|
7
8
|
import { registerDeliveryTools } from './tools/delivery.js';
|
|
@@ -13,24 +14,40 @@ import { registerEarnTools } from './tools/earn.js';
|
|
|
13
14
|
import { registerFlashSwapTools } from './tools/flash_swap.js';
|
|
14
15
|
import { registerUnifiedTools } from './tools/unified.js';
|
|
15
16
|
import { registerSubAccountTools } from './tools/sub_account.js';
|
|
17
|
+
const config = parseConfig();
|
|
16
18
|
const server = new McpServer({
|
|
17
19
|
name: 'gate',
|
|
18
20
|
version: '0.1.0',
|
|
19
21
|
});
|
|
20
|
-
//
|
|
22
|
+
// Monkey-patch server.tool: apply name sanitization + readonly filter
|
|
21
23
|
const _registerTool = server.tool.bind(server);
|
|
22
|
-
server.tool = (name, ...args) =>
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
24
|
+
server.tool = (name, ...args) => {
|
|
25
|
+
const sanitized = sanitizeToolName(name);
|
|
26
|
+
if (config.readonly && isWriteTool(sanitized))
|
|
27
|
+
return;
|
|
28
|
+
_registerTool(sanitized, ...args);
|
|
29
|
+
};
|
|
30
|
+
const MODULE_REGISTRY = {
|
|
31
|
+
spot: registerSpotTools,
|
|
32
|
+
futures: registerFuturesTools,
|
|
33
|
+
delivery: registerDeliveryTools,
|
|
34
|
+
margin: registerMarginTools,
|
|
35
|
+
wallet: registerWalletTools,
|
|
36
|
+
account: registerAccountTools,
|
|
37
|
+
options: registerOptionsTools,
|
|
38
|
+
earn: registerEarnTools,
|
|
39
|
+
flash_swap: registerFlashSwapTools,
|
|
40
|
+
unified: registerUnifiedTools,
|
|
41
|
+
sub_account: registerSubAccountTools,
|
|
42
|
+
};
|
|
43
|
+
const modulesToLoad = config.modules ?? new Set(Object.keys(MODULE_REGISTRY));
|
|
44
|
+
for (const name of modulesToLoad) {
|
|
45
|
+
MODULE_REGISTRY[name](server);
|
|
46
|
+
}
|
|
47
|
+
if (config.modules || config.readonly) {
|
|
48
|
+
const moduleList = config.modules ? [...config.modules].join(', ') : 'all';
|
|
49
|
+
console.error(`[gate-mcp] Modules: ${moduleList} | Readonly: ${config.readonly}`);
|
|
50
|
+
}
|
|
34
51
|
const transport = new StdioServerTransport();
|
|
35
52
|
await server.connect(transport);
|
|
36
53
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAc,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AAEjE,MAAM,MAAM,GAAG,WAAW,EAAE,CAAC;AAE7B,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC;IAC3B,IAAI,EAAE,MAAM;IACZ,OAAO,EAAE,OAAO;CACjB,CAAC,CAAC;AAEH,sE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,CAAC;AACpF,CAAC;AAED,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;AAC7C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC"}
|
package/dist/tools/account.js
CHANGED
|
@@ -3,7 +3,7 @@ import { AccountApi } from 'gate-api';
|
|
|
3
3
|
import { createClient, requireAuth } from '../client.js';
|
|
4
4
|
import { textContent, errorContent } from '../utils.js';
|
|
5
5
|
export function registerAccountTools(server) {
|
|
6
|
-
server.tool('
|
|
6
|
+
server.tool('cex_account_get_account_detail', 'Get account profile and configuration (requires authentication)', {}, async () => {
|
|
7
7
|
try {
|
|
8
8
|
requireAuth();
|
|
9
9
|
const { body } = await new AccountApi(createClient()).getAccountDetail();
|
|
@@ -13,7 +13,7 @@ export function registerAccountTools(server) {
|
|
|
13
13
|
return errorContent(e);
|
|
14
14
|
}
|
|
15
15
|
});
|
|
16
|
-
server.tool('
|
|
16
|
+
server.tool('cex_account_get_account_rate_limit', 'Get account API rate limit information (requires authentication)', {}, async () => {
|
|
17
17
|
try {
|
|
18
18
|
requireAuth();
|
|
19
19
|
const { body } = await new AccountApi(createClient()).getAccountRateLimit();
|
|
@@ -23,7 +23,7 @@ export function registerAccountTools(server) {
|
|
|
23
23
|
return errorContent(e);
|
|
24
24
|
}
|
|
25
25
|
});
|
|
26
|
-
server.tool('
|
|
26
|
+
server.tool('cex_account_get_debit_fee', 'Get debit fee configuration (requires authentication)', {}, async () => {
|
|
27
27
|
try {
|
|
28
28
|
requireAuth();
|
|
29
29
|
const { body } = await new AccountApi(createClient()).getDebitFee();
|
|
@@ -33,7 +33,7 @@ export function registerAccountTools(server) {
|
|
|
33
33
|
return errorContent(e);
|
|
34
34
|
}
|
|
35
35
|
});
|
|
36
|
-
server.tool('
|
|
36
|
+
server.tool('cex_account_set_debit_fee', 'Enable or disable GT debit fee (requires authentication)', { enabled: z.boolean().describe('true to pay fees with GT, false to disable') }, async ({ enabled }) => {
|
|
37
37
|
try {
|
|
38
38
|
requireAuth();
|
|
39
39
|
const { body } = await new AccountApi(createClient()).setDebitFee({ enabled });
|
|
@@ -43,7 +43,7 @@ export function registerAccountTools(server) {
|
|
|
43
43
|
return errorContent(e);
|
|
44
44
|
}
|
|
45
45
|
});
|
|
46
|
-
server.tool('
|
|
46
|
+
server.tool('cex_account_get_account_main_keys', 'Get main account API key info (requires authentication)', {}, async () => {
|
|
47
47
|
try {
|
|
48
48
|
requireAuth();
|
|
49
49
|
const { body } = await new AccountApi(createClient()).getAccountMainKeys();
|
|
@@ -53,7 +53,7 @@ export function registerAccountTools(server) {
|
|
|
53
53
|
return errorContent(e);
|
|
54
54
|
}
|
|
55
55
|
});
|
|
56
|
-
server.tool('
|
|
56
|
+
server.tool('cex_account_list_stp_groups', 'List Self-Trade Prevention (STP) groups (requires authentication)', { name: z.string().optional().describe('Filter by group name') }, async ({ name }) => {
|
|
57
57
|
try {
|
|
58
58
|
requireAuth();
|
|
59
59
|
const opts = {};
|
|
@@ -66,7 +66,7 @@ export function registerAccountTools(server) {
|
|
|
66
66
|
return errorContent(e);
|
|
67
67
|
}
|
|
68
68
|
});
|
|
69
|
-
server.tool('
|
|
69
|
+
server.tool('cex_account_create_stp_group', 'Create a Self-Trade Prevention (STP) group (requires authentication)', { name: z.string().describe('STP group name') }, async ({ name }) => {
|
|
70
70
|
try {
|
|
71
71
|
requireAuth();
|
|
72
72
|
const { body } = await new AccountApi(createClient()).createSTPGroup({ name });
|
|
@@ -76,7 +76,7 @@ export function registerAccountTools(server) {
|
|
|
76
76
|
return errorContent(e);
|
|
77
77
|
}
|
|
78
78
|
});
|
|
79
|
-
server.tool('
|
|
79
|
+
server.tool('cex_account_list_stp_group_users', 'List users in an STP group (requires authentication)', { stp_id: z.number().int().describe('STP group ID') }, async ({ stp_id }) => {
|
|
80
80
|
try {
|
|
81
81
|
requireAuth();
|
|
82
82
|
const { body } = await new AccountApi(createClient()).listSTPGroupsUsers(stp_id);
|
|
@@ -86,7 +86,7 @@ export function registerAccountTools(server) {
|
|
|
86
86
|
return errorContent(e);
|
|
87
87
|
}
|
|
88
88
|
});
|
|
89
|
-
server.tool('
|
|
89
|
+
server.tool('cex_account_add_stp_group_users', 'Add users to an STP group (requires authentication)', {
|
|
90
90
|
stp_id: z.number().int().describe('STP group ID'),
|
|
91
91
|
user_ids: z.array(z.number().int()).describe('List of user IDs to add'),
|
|
92
92
|
}, async ({ stp_id, user_ids }) => {
|
|
@@ -99,7 +99,7 @@ export function registerAccountTools(server) {
|
|
|
99
99
|
return errorContent(e);
|
|
100
100
|
}
|
|
101
101
|
});
|
|
102
|
-
server.tool('
|
|
102
|
+
server.tool('cex_account_delete_stp_group_user', 'Remove a user from an STP group (requires authentication)', {
|
|
103
103
|
stp_id: z.number().int().describe('STP group ID'),
|
|
104
104
|
user_id: z.number().int().describe('User ID to remove'),
|
|
105
105
|
}, async ({ stp_id, user_id }) => {
|
package/dist/tools/delivery.js
CHANGED
|
@@ -6,7 +6,7 @@ import { textContent, errorContent } from '../utils.js';
|
|
|
6
6
|
const settleSchema = z.literal('usdt').describe('Settlement currency (only usdt supported)');
|
|
7
7
|
export function registerDeliveryTools(server) {
|
|
8
8
|
// ── Public tools ──────────────────────────────────────────────────────────
|
|
9
|
-
server.tool('
|
|
9
|
+
server.tool('cex_delivery_list_delivery_contracts', 'List all delivery (expiring futures) contracts', { settle: settleSchema }, async ({ settle }) => {
|
|
10
10
|
try {
|
|
11
11
|
const { body } = await new DeliveryApi(createClient()).listDeliveryContracts(settle);
|
|
12
12
|
return textContent(body);
|
|
@@ -15,7 +15,7 @@ export function registerDeliveryTools(server) {
|
|
|
15
15
|
return errorContent(e);
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
|
-
server.tool('
|
|
18
|
+
server.tool('cex_delivery_get_delivery_contract', 'Get a single delivery contract', {
|
|
19
19
|
settle: settleSchema,
|
|
20
20
|
contract: z.string().describe('Contract name'),
|
|
21
21
|
}, async ({ settle, contract }) => {
|
|
@@ -27,7 +27,7 @@ export function registerDeliveryTools(server) {
|
|
|
27
27
|
return errorContent(e);
|
|
28
28
|
}
|
|
29
29
|
});
|
|
30
|
-
server.tool('
|
|
30
|
+
server.tool('cex_delivery_list_delivery_order_book', 'Get delivery contract order book', {
|
|
31
31
|
settle: settleSchema,
|
|
32
32
|
contract: z.string().describe('Contract name'),
|
|
33
33
|
limit: z.number().int().optional(),
|
|
@@ -43,7 +43,7 @@ export function registerDeliveryTools(server) {
|
|
|
43
43
|
return errorContent(e);
|
|
44
44
|
}
|
|
45
45
|
});
|
|
46
|
-
server.tool('
|
|
46
|
+
server.tool('cex_delivery_list_delivery_candlesticks', 'Get delivery contract candlestick data', {
|
|
47
47
|
settle: settleSchema,
|
|
48
48
|
contract: z.string().describe('Contract name'),
|
|
49
49
|
interval: z.enum(['1m', '5m', '15m', '30m', '1h', '4h', '8h', '1d']).optional(),
|
|
@@ -62,7 +62,7 @@ export function registerDeliveryTools(server) {
|
|
|
62
62
|
return errorContent(e);
|
|
63
63
|
}
|
|
64
64
|
});
|
|
65
|
-
server.tool('
|
|
65
|
+
server.tool('cex_delivery_list_delivery_tickers', 'Get delivery contract tickers', {
|
|
66
66
|
settle: settleSchema,
|
|
67
67
|
contract: z.string().optional().describe('Filter by contract'),
|
|
68
68
|
}, async ({ settle, contract }) => {
|
|
@@ -78,7 +78,7 @@ export function registerDeliveryTools(server) {
|
|
|
78
78
|
}
|
|
79
79
|
});
|
|
80
80
|
// ── Private tools ─────────────────────────────────────────────────────────
|
|
81
|
-
server.tool('
|
|
81
|
+
server.tool('cex_delivery_list_delivery_accounts', 'Get delivery account balance (requires authentication)', { settle: settleSchema }, async ({ settle }) => {
|
|
82
82
|
try {
|
|
83
83
|
requireAuth();
|
|
84
84
|
const { body } = await new DeliveryApi(createClient()).listDeliveryAccounts(settle);
|
|
@@ -88,7 +88,7 @@ export function registerDeliveryTools(server) {
|
|
|
88
88
|
return errorContent(e);
|
|
89
89
|
}
|
|
90
90
|
});
|
|
91
|
-
server.tool('
|
|
91
|
+
server.tool('cex_delivery_list_delivery_positions', 'List delivery positions (requires authentication)', { settle: settleSchema }, async ({ settle }) => {
|
|
92
92
|
try {
|
|
93
93
|
requireAuth();
|
|
94
94
|
const { body } = await new DeliveryApi(createClient()).listDeliveryPositions(settle);
|
|
@@ -98,7 +98,7 @@ export function registerDeliveryTools(server) {
|
|
|
98
98
|
return errorContent(e);
|
|
99
99
|
}
|
|
100
100
|
});
|
|
101
|
-
server.tool('
|
|
101
|
+
server.tool('cex_delivery_list_delivery_orders', 'List delivery orders (requires authentication)', {
|
|
102
102
|
settle: settleSchema,
|
|
103
103
|
status: z.enum(['open', 'finished']),
|
|
104
104
|
contract: z.string().optional(),
|
|
@@ -121,7 +121,7 @@ export function registerDeliveryTools(server) {
|
|
|
121
121
|
return errorContent(e);
|
|
122
122
|
}
|
|
123
123
|
});
|
|
124
|
-
server.tool('
|
|
124
|
+
server.tool('cex_delivery_create_delivery_order', 'Create a delivery order (requires authentication) — always confirm the details with the user before calling this tool', {
|
|
125
125
|
settle: settleSchema,
|
|
126
126
|
contract: z.string().describe('Contract name'),
|
|
127
127
|
size: z.number().int().describe('Order size (negative = short)'),
|
|
@@ -146,7 +146,7 @@ export function registerDeliveryTools(server) {
|
|
|
146
146
|
return errorContent(e);
|
|
147
147
|
}
|
|
148
148
|
});
|
|
149
|
-
server.tool('
|
|
149
|
+
server.tool('cex_delivery_cancel_delivery_order', 'Cancel a delivery order (requires authentication) — always confirm with the user before calling this tool', {
|
|
150
150
|
settle: settleSchema,
|
|
151
151
|
order_id: z.string().describe('Order ID'),
|
|
152
152
|
}, async ({ settle, order_id }) => {
|
|
@@ -159,7 +159,7 @@ export function registerDeliveryTools(server) {
|
|
|
159
159
|
return errorContent(e);
|
|
160
160
|
}
|
|
161
161
|
});
|
|
162
|
-
server.tool('
|
|
162
|
+
server.tool('cex_delivery_get_my_delivery_trades', 'Get personal delivery trading history (requires authentication)', {
|
|
163
163
|
settle: settleSchema,
|
|
164
164
|
contract: z.string().optional(),
|
|
165
165
|
limit: z.number().int().optional(),
|
package/dist/tools/earn.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"earn.d.ts","sourceRoot":"","sources":["../../src/tools/earn.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAMpE,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"earn.d.ts","sourceRoot":"","sources":["../../src/tools/earn.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAMpE,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,CAmezD"}
|