@the-staq/tradestaq-mcp 0.1.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/CHANGELOG.md +14 -0
- package/README.md +228 -0
- package/VERSION +1 -0
- package/dist/api.d.ts +12 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +86 -0
- package/dist/api.js.map +1 -0
- package/dist/config.d.ts +10 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +54 -0
- package/dist/config.js.map +1 -0
- package/dist/helpers.d.ts +8 -0
- package/dist/helpers.d.ts.map +1 -0
- package/dist/helpers.js +31 -0
- package/dist/helpers.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +107 -0
- package/dist/index.js.map +1 -0
- package/dist/prompts/index.d.ts +3 -0
- package/dist/prompts/index.d.ts.map +1 -0
- package/dist/prompts/index.js +62 -0
- package/dist/prompts/index.js.map +1 -0
- package/dist/resources/index.d.ts +3 -0
- package/dist/resources/index.d.ts.map +1 -0
- package/dist/resources/index.js +75 -0
- package/dist/resources/index.js.map +1 -0
- package/dist/tools/advisor.d.ts +3 -0
- package/dist/tools/advisor.d.ts.map +1 -0
- package/dist/tools/advisor.js +31 -0
- package/dist/tools/advisor.js.map +1 -0
- package/dist/tools/auth.d.ts +3 -0
- package/dist/tools/auth.d.ts.map +1 -0
- package/dist/tools/auth.js +190 -0
- package/dist/tools/auth.js.map +1 -0
- package/dist/tools/backtest.d.ts +3 -0
- package/dist/tools/backtest.d.ts.map +1 -0
- package/dist/tools/backtest.js +66 -0
- package/dist/tools/backtest.js.map +1 -0
- package/dist/tools/bot.d.ts +3 -0
- package/dist/tools/bot.d.ts.map +1 -0
- package/dist/tools/bot.js +75 -0
- package/dist/tools/bot.js.map +1 -0
- package/dist/tools/copy-trading.d.ts +3 -0
- package/dist/tools/copy-trading.d.ts.map +1 -0
- package/dist/tools/copy-trading.js +44 -0
- package/dist/tools/copy-trading.js.map +1 -0
- package/dist/tools/market.d.ts +3 -0
- package/dist/tools/market.d.ts.map +1 -0
- package/dist/tools/market.js +66 -0
- package/dist/tools/market.js.map +1 -0
- package/dist/tools/portfolio.d.ts +3 -0
- package/dist/tools/portfolio.d.ts.map +1 -0
- package/dist/tools/portfolio.js +32 -0
- package/dist/tools/portfolio.js.map +1 -0
- package/dist/tools/strategy.d.ts +3 -0
- package/dist/tools/strategy.d.ts.map +1 -0
- package/dist/tools/strategy.js +148 -0
- package/dist/tools/strategy.js.map +1 -0
- package/dist/tools/trades.d.ts +3 -0
- package/dist/tools/trades.d.ts.map +1 -0
- package/dist/tools/trades.js +46 -0
- package/dist/tools/trades.js.map +1 -0
- package/package.json +57 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [0.1.0] - 2026-04-05
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
- MCP server scaffold with stdio transport
|
|
7
|
+
- OAuth PKCE authentication flow (browser-based, credentials never in chat)
|
|
8
|
+
- 27 tools across 9 categories: auth, market data, portfolio, strategies, backtesting, bot management, trade history, copy trading, advisor
|
|
9
|
+
- 3 prompt templates: trading-assistant, strategy-builder, portfolio-reviewer
|
|
10
|
+
- Structured error handling with retryable/non-retryable error contract
|
|
11
|
+
- In-memory config caching for performance during polling
|
|
12
|
+
- 33 tests (config, API client, helpers, tool registration, prompts)
|
|
13
|
+
- GitHub Actions CI (type check + test + build)
|
|
14
|
+
- README with setup instructions for Claude Desktop, Cursor, and Claude Code
|
package/README.md
ADDED
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
# TradeStaq MCP Server
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@the-staq/tradestaq-mcp)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
|
|
6
|
+
**31 AI-powered trading tools for Claude, Cursor, and any MCP client.**
|
|
7
|
+
|
|
8
|
+
Create strategies, backtest them, deploy trading bots, copy top traders, monitor positions, and manage your crypto portfolio, all from conversation. Supports Binance, Bybit, OKX, Bitget, Hyperliquid, dYdX, and more.
|
|
9
|
+
|
|
10
|
+
```
|
|
11
|
+
"Show me my portfolio" → get_portfolio
|
|
12
|
+
"Backtest GhostRider on BTC/USDT for 3 months" → what_if_backtest
|
|
13
|
+
"Deploy it on my Binance account" → deploy_bot
|
|
14
|
+
"Who are the top traders this month?" → list_top_traders
|
|
15
|
+
"Generate a momentum strategy for ETH" → generate_strategy
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Quick Start
|
|
19
|
+
|
|
20
|
+
### Option A: Remote server (no install needed)
|
|
21
|
+
|
|
22
|
+
For MCP clients that support HTTP transport:
|
|
23
|
+
|
|
24
|
+
```json
|
|
25
|
+
{
|
|
26
|
+
"mcpServers": {
|
|
27
|
+
"tradestaq": {
|
|
28
|
+
"url": "https://mcp.tradestaq.com/mcp"
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Option B: npx (recommended for local)
|
|
35
|
+
|
|
36
|
+
No clone, no build. Just add to your MCP config:
|
|
37
|
+
|
|
38
|
+
**Claude Desktop** (`~/Library/Application Support/Claude/claude_desktop_config.json`):
|
|
39
|
+
|
|
40
|
+
```json
|
|
41
|
+
{
|
|
42
|
+
"mcpServers": {
|
|
43
|
+
"tradestaq": {
|
|
44
|
+
"command": "npx",
|
|
45
|
+
"args": ["-y", "@the-staq/tradestaq-mcp"]
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
**Cursor** (`.cursor/mcp.json`):
|
|
52
|
+
|
|
53
|
+
```json
|
|
54
|
+
{
|
|
55
|
+
"mcpServers": {
|
|
56
|
+
"tradestaq": {
|
|
57
|
+
"command": "npx",
|
|
58
|
+
"args": ["-y", "@the-staq/tradestaq-mcp"]
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
**Claude Code:**
|
|
65
|
+
|
|
66
|
+
```sh
|
|
67
|
+
claude mcp add tradestaq -- npx -y @the-staq/tradestaq-mcp
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Option C: Clone and build
|
|
71
|
+
|
|
72
|
+
```sh
|
|
73
|
+
git clone https://github.com/the-staq/tradestaq-mcp.git
|
|
74
|
+
cd tradestaq-mcp
|
|
75
|
+
npm install
|
|
76
|
+
npm run build
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Then point your MCP client to `dist/index.js`.
|
|
80
|
+
|
|
81
|
+
## Authenticate
|
|
82
|
+
|
|
83
|
+
After adding the server, ask your AI assistant to log in:
|
|
84
|
+
|
|
85
|
+
- **"Log me in to TradeStaq"** — uses email/password directly
|
|
86
|
+
- **"Authenticate with TradeStaq"** — opens a browser window for secure OAuth login
|
|
87
|
+
|
|
88
|
+
Credentials never enter the chat when using the browser flow. Token is stored locally at `~/.tradestaq/mcp-config.json` with restricted permissions (0600).
|
|
89
|
+
|
|
90
|
+
## Tools
|
|
91
|
+
|
|
92
|
+
### Auth
|
|
93
|
+
|
|
94
|
+
| Tool | Description |
|
|
95
|
+
|------|-------------|
|
|
96
|
+
| `login` | Log in with email and password |
|
|
97
|
+
| `authenticate` | Log in via browser (OAuth + PKCE) |
|
|
98
|
+
| `check_auth` | Check authentication status |
|
|
99
|
+
| `set_token` | Manually set a JWT token |
|
|
100
|
+
| `connect_exchange` | Connect an exchange account via browser |
|
|
101
|
+
| `logout` | Remove stored credentials |
|
|
102
|
+
|
|
103
|
+
### Market Data
|
|
104
|
+
|
|
105
|
+
| Tool | Description |
|
|
106
|
+
|------|-------------|
|
|
107
|
+
| `get_price` | Current price, 24h change, volume |
|
|
108
|
+
| `get_candles` | OHLCV candlestick data (1m to 1d) |
|
|
109
|
+
| `list_exchanges` | List connected exchange accounts |
|
|
110
|
+
| `search_markets` | Find trading pairs on a specific exchange |
|
|
111
|
+
|
|
112
|
+
### Portfolio
|
|
113
|
+
|
|
114
|
+
| Tool | Description |
|
|
115
|
+
|------|-------------|
|
|
116
|
+
| `get_portfolio` | Total balance, exchanges, active bots |
|
|
117
|
+
| `get_positions` | Open positions with live PnL |
|
|
118
|
+
|
|
119
|
+
### Strategies
|
|
120
|
+
|
|
121
|
+
| Tool | Description |
|
|
122
|
+
|------|-------------|
|
|
123
|
+
| `list_strategies` | Browse marketplace or your own strategies |
|
|
124
|
+
| `get_strategy` | Full strategy details and performance |
|
|
125
|
+
| `explain_strategy` | Plain-English explanation with risk profile |
|
|
126
|
+
| `compare_strategies` | Side-by-side metrics comparison |
|
|
127
|
+
| `create_strategy` | Create a strategy from TradeDroid code |
|
|
128
|
+
| `generate_strategy` | Generate a strategy from natural language using AI |
|
|
129
|
+
|
|
130
|
+
### Backtesting
|
|
131
|
+
|
|
132
|
+
| Tool | Description |
|
|
133
|
+
|------|-------------|
|
|
134
|
+
| `what_if_backtest` | Run a historical backtest (async, 30-120s) |
|
|
135
|
+
| `get_backtest_results` | Check status of a running backtest |
|
|
136
|
+
|
|
137
|
+
### Bot Management
|
|
138
|
+
|
|
139
|
+
| Tool | Description |
|
|
140
|
+
|------|-------------|
|
|
141
|
+
| `list_bots` | All bots with status and performance |
|
|
142
|
+
| `get_bot_status` | Detailed bot metrics and config |
|
|
143
|
+
| `deploy_bot` | Deploy a strategy as a trading bot |
|
|
144
|
+
| `stop_bot` | Stop a running bot |
|
|
145
|
+
| `close_position` | Close an open position (full or partial) |
|
|
146
|
+
|
|
147
|
+
`deploy_bot` defaults to paper trading. Pass `live: true` for real money.
|
|
148
|
+
|
|
149
|
+
### Trade History
|
|
150
|
+
|
|
151
|
+
| Tool | Description |
|
|
152
|
+
|------|-------------|
|
|
153
|
+
| `get_trade_history` | Closed trades with PnL, entry/exit prices |
|
|
154
|
+
| `get_performance_metrics` | ROI, win rate, Sortino ratio, PnL breakdown |
|
|
155
|
+
|
|
156
|
+
### Copy Trading
|
|
157
|
+
|
|
158
|
+
| Tool | Description |
|
|
159
|
+
|------|-------------|
|
|
160
|
+
| `list_top_traders` | Browse the leaderboard of top traders |
|
|
161
|
+
| `follow_trader` | Subscribe to copy a trader's trades |
|
|
162
|
+
|
|
163
|
+
### Advisor
|
|
164
|
+
|
|
165
|
+
| Tool | Description |
|
|
166
|
+
|------|-------------|
|
|
167
|
+
| `suggest_strategies` | Match strategies to your risk profile |
|
|
168
|
+
| `get_market_context` | Trend, volatility, support/resistance for a symbol |
|
|
169
|
+
|
|
170
|
+
## Prompt Templates
|
|
171
|
+
|
|
172
|
+
**Trading Assistant** — Start a conversation about your portfolio and positions. The AI calls `get_portfolio` and `get_positions` to ground its responses in your actual data.
|
|
173
|
+
|
|
174
|
+
**Strategy Builder** — Walk through creating, backtesting, and deploying a strategy. Pass an optional `goal` like "momentum strategy for ETH" to get focused suggestions.
|
|
175
|
+
|
|
176
|
+
**Portfolio Reviewer** — Deep analysis of your portfolio, positions, trade history, and performance. Identifies what's working, what isn't, and suggests improvements.
|
|
177
|
+
|
|
178
|
+
## Architecture
|
|
179
|
+
|
|
180
|
+
```
|
|
181
|
+
┌─────────────────┐ stdio ┌──────────────────┐ HTTPS ┌──────────────┐
|
|
182
|
+
│ Claude Desktop │◄──────────────►│ tradestaq-mcp │◄────────────►│ TradeStaq │
|
|
183
|
+
│ Cursor / CLI │ │ (this server) │ Bearer JWT │ API │
|
|
184
|
+
└─────────────────┘ └──────────────────┘ └──────────────┘
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
- Standalone process, communicates with TradeStaq API over HTTPS
|
|
188
|
+
- stdio transport for local integrations
|
|
189
|
+
- JWT auth via OAuth PKCE flow (browser-based, no credentials in chat)
|
|
190
|
+
- All tools return structured JSON for agent consumption
|
|
191
|
+
|
|
192
|
+
## Development
|
|
193
|
+
|
|
194
|
+
```sh
|
|
195
|
+
npm run dev # watch mode with tsx
|
|
196
|
+
npm run build # compile TypeScript
|
|
197
|
+
npm run lint # type check without emitting
|
|
198
|
+
npm test # run tests
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
## Error Handling
|
|
202
|
+
|
|
203
|
+
All tool errors return structured responses:
|
|
204
|
+
|
|
205
|
+
```json
|
|
206
|
+
{
|
|
207
|
+
"error": {
|
|
208
|
+
"code": "INSUFFICIENT_BALANCE",
|
|
209
|
+
"message": "Human-readable description",
|
|
210
|
+
"retryable": true,
|
|
211
|
+
"retryAfterMs": 5000
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
Error codes: `AUTH_EXPIRED`, `TIMEOUT`, `RATE_LIMITED`, `NETWORK_ERROR`, `HTTP_4xx`, `HTTP_5xx`.
|
|
217
|
+
|
|
218
|
+
## Security
|
|
219
|
+
|
|
220
|
+
- Credentials never enter AI conversation history
|
|
221
|
+
- OAuth PKCE flow with browser-based authentication
|
|
222
|
+
- Token stored with 0600 file permissions
|
|
223
|
+
- Localhost-only OAuth callbacks
|
|
224
|
+
- `deploy_bot`, `stop_bot`, `close_position`, and `follow_trader` are destructive operations (AI confirms with user)
|
|
225
|
+
|
|
226
|
+
## License
|
|
227
|
+
|
|
228
|
+
MIT
|
package/VERSION
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
0.1.0
|
package/dist/api.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare class ApiError extends Error {
|
|
2
|
+
status: number;
|
|
3
|
+
code: string;
|
|
4
|
+
retryable: boolean;
|
|
5
|
+
constructor(status: number, code: string, message: string, retryable?: boolean);
|
|
6
|
+
}
|
|
7
|
+
export declare function api<T = unknown>(path: string, options?: {
|
|
8
|
+
method?: string;
|
|
9
|
+
body?: unknown;
|
|
10
|
+
timeout?: number;
|
|
11
|
+
}): Promise<T>;
|
|
12
|
+
//# sourceMappingURL=api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAEA,qBAAa,QAAS,SAAQ,KAAK;IAExB,MAAM,EAAE,MAAM;IACd,IAAI,EAAE,MAAM;IAEZ,SAAS,EAAE,OAAO;gBAHlB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM,EACR,SAAS,GAAE,OAAe;CAKpC;AAqCD,wBAAsB,GAAG,CAAC,CAAC,GAAG,OAAO,EACnC,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,OAAO,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAO,GAClE,OAAO,CAAC,CAAC,CAAC,CA6CZ"}
|
package/dist/api.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { loadConfig, saveConfig } from './config.js';
|
|
2
|
+
export class ApiError extends Error {
|
|
3
|
+
status;
|
|
4
|
+
code;
|
|
5
|
+
retryable;
|
|
6
|
+
constructor(status, code, message, retryable = false) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.status = status;
|
|
9
|
+
this.code = code;
|
|
10
|
+
this.retryable = retryable;
|
|
11
|
+
this.name = 'ApiError';
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
async function refreshTokenIfNeeded() {
|
|
15
|
+
const config = loadConfig();
|
|
16
|
+
if (!config.token || !config.tokenExpiresAt)
|
|
17
|
+
return;
|
|
18
|
+
// Only refresh if expiring within 1 hour
|
|
19
|
+
const oneHour = 60 * 60 * 1000;
|
|
20
|
+
if (config.tokenExpiresAt - Date.now() > oneHour)
|
|
21
|
+
return;
|
|
22
|
+
try {
|
|
23
|
+
// Use Payload's built-in refresh endpoint
|
|
24
|
+
const res = await fetch(`${config.baseUrl}/api/users/refresh-token`, {
|
|
25
|
+
method: 'POST',
|
|
26
|
+
headers: {
|
|
27
|
+
Authorization: `Bearer ${config.token}`,
|
|
28
|
+
'Content-Type': 'application/json',
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
if (res.ok) {
|
|
32
|
+
const data = (await res.json());
|
|
33
|
+
const newToken = data.refreshedToken || data.token || data.access_token;
|
|
34
|
+
if (newToken) {
|
|
35
|
+
saveConfig({
|
|
36
|
+
...config,
|
|
37
|
+
token: newToken,
|
|
38
|
+
tokenExpiresAt: Date.now() + 7 * 24 * 3600 * 1000,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
// If refresh fails, continue with existing token — it might still work
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
// Silently continue — token refresh is best-effort
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
export async function api(path, options = {}) {
|
|
49
|
+
const config = loadConfig();
|
|
50
|
+
if (!config.token) {
|
|
51
|
+
throw new ApiError(401, 'AUTH_EXPIRED', 'Not authenticated. Run the authenticate tool first.');
|
|
52
|
+
}
|
|
53
|
+
await refreshTokenIfNeeded();
|
|
54
|
+
const url = `${config.baseUrl}${path}`;
|
|
55
|
+
const controller = new AbortController();
|
|
56
|
+
const timer = setTimeout(() => controller.abort(), options.timeout ?? 30_000);
|
|
57
|
+
try {
|
|
58
|
+
const res = await fetch(url, {
|
|
59
|
+
method: options.method ?? 'GET',
|
|
60
|
+
headers: {
|
|
61
|
+
Authorization: `Bearer ${config.token}`,
|
|
62
|
+
'Content-Type': 'application/json',
|
|
63
|
+
'X-MCP-Source': 'tradestaq-mcp',
|
|
64
|
+
},
|
|
65
|
+
body: options.body ? JSON.stringify(options.body) : undefined,
|
|
66
|
+
signal: controller.signal,
|
|
67
|
+
});
|
|
68
|
+
const data = (await res.json());
|
|
69
|
+
if (!res.ok) {
|
|
70
|
+
throw new ApiError(res.status, data?.error?.code ?? `HTTP_${res.status}`, data?.error?.message ?? data?.error ?? data?.message ?? `API returned ${res.status}`, res.status === 429 || res.status >= 500);
|
|
71
|
+
}
|
|
72
|
+
return data;
|
|
73
|
+
}
|
|
74
|
+
catch (err) {
|
|
75
|
+
if (err instanceof ApiError)
|
|
76
|
+
throw err;
|
|
77
|
+
if (err.name === 'AbortError') {
|
|
78
|
+
throw new ApiError(408, 'TIMEOUT', 'Request timed out', true);
|
|
79
|
+
}
|
|
80
|
+
throw new ApiError(0, 'NETWORK_ERROR', `Failed to reach TradeStaq API: ${err.message}`, true);
|
|
81
|
+
}
|
|
82
|
+
finally {
|
|
83
|
+
clearTimeout(timer);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=api.js.map
|
package/dist/api.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAEpD,MAAM,OAAO,QAAS,SAAQ,KAAK;IAExB;IACA;IAEA;IAJT,YACS,MAAc,EACd,IAAY,EACnB,OAAe,EACR,YAAqB,KAAK;QAEjC,KAAK,CAAC,OAAO,CAAC,CAAA;QALP,WAAM,GAAN,MAAM,CAAQ;QACd,SAAI,GAAJ,IAAI,CAAQ;QAEZ,cAAS,GAAT,SAAS,CAAiB;QAGjC,IAAI,CAAC,IAAI,GAAG,UAAU,CAAA;IACxB,CAAC;CACF;AAED,KAAK,UAAU,oBAAoB;IACjC,MAAM,MAAM,GAAG,UAAU,EAAE,CAAA;IAC3B,IAAI,CAAC,MAAM,CAAC,KAAK,IAAI,CAAC,MAAM,CAAC,cAAc;QAAE,OAAM;IAEnD,yCAAyC;IACzC,MAAM,OAAO,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAA;IAC9B,IAAI,MAAM,CAAC,cAAc,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,OAAO;QAAE,OAAM;IAExD,IAAI,CAAC;QACH,0CAA0C;QAC1C,MAAM,GAAG,GAAG,MAAM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Aa,CAAC,OAAO,EAAE,EAAE,IAAI,CAAC,CAAA;IAC1G,CAAC;YAAS,CAAC;QACT,YAAY,CAAC,KAAK,CAAC,CAAA;IACrB,CAAC;AACH,CAAC"}
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface McpConfig {
|
|
2
|
+
token?: string;
|
|
3
|
+
baseUrl: string;
|
|
4
|
+
tokenExpiresAt?: number;
|
|
5
|
+
}
|
|
6
|
+
export declare function loadConfig(): McpConfig;
|
|
7
|
+
export declare function saveConfig(config: McpConfig): void;
|
|
8
|
+
export declare function clearToken(): void;
|
|
9
|
+
export declare function isAuthenticated(): boolean;
|
|
10
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,SAAS;IACxB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,MAAM,CAAA;IACf,cAAc,CAAC,EAAE,MAAM,CAAA;CACxB;AAOD,wBAAgB,UAAU,IAAI,SAAS,CAsBtC;AAED,wBAAgB,UAAU,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,CAIlD;AAED,wBAAgB,UAAU,IAAI,IAAI,CAMjC;AAED,wBAAgB,eAAe,IAAI,OAAO,CAKzC"}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
const CONFIG_DIR = path.join(os.homedir(), '.tradestaq');
|
|
5
|
+
const CONFIG_FILE = path.join(CONFIG_DIR, 'mcp-config.json');
|
|
6
|
+
let _cache = null;
|
|
7
|
+
export function loadConfig() {
|
|
8
|
+
if (_cache)
|
|
9
|
+
return _cache;
|
|
10
|
+
const defaults = { baseUrl: 'https://tradestaq.com' };
|
|
11
|
+
// Environment variables override file config (useful for CI, Claude Code, etc.)
|
|
12
|
+
const envToken = process.env.TRADESTAQ_TOKEN;
|
|
13
|
+
const envBaseUrl = process.env.TRADESTAQ_BASE_URL;
|
|
14
|
+
try {
|
|
15
|
+
const raw = fs.readFileSync(CONFIG_FILE, 'utf-8');
|
|
16
|
+
const config = { ...defaults, ...JSON.parse(raw) };
|
|
17
|
+
if (envToken)
|
|
18
|
+
config.token = envToken;
|
|
19
|
+
if (envBaseUrl)
|
|
20
|
+
config.baseUrl = envBaseUrl;
|
|
21
|
+
_cache = config;
|
|
22
|
+
return config;
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
const config = { ...defaults };
|
|
26
|
+
if (envToken)
|
|
27
|
+
config.token = envToken;
|
|
28
|
+
if (envBaseUrl)
|
|
29
|
+
config.baseUrl = envBaseUrl;
|
|
30
|
+
_cache = config;
|
|
31
|
+
return config;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export function saveConfig(config) {
|
|
35
|
+
fs.mkdirSync(CONFIG_DIR, { recursive: true, mode: 0o700 });
|
|
36
|
+
fs.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2), { mode: 0o600 });
|
|
37
|
+
_cache = config;
|
|
38
|
+
}
|
|
39
|
+
export function clearToken() {
|
|
40
|
+
_cache = null;
|
|
41
|
+
const config = loadConfig();
|
|
42
|
+
delete config.token;
|
|
43
|
+
delete config.tokenExpiresAt;
|
|
44
|
+
saveConfig(config);
|
|
45
|
+
}
|
|
46
|
+
export function isAuthenticated() {
|
|
47
|
+
const config = loadConfig();
|
|
48
|
+
if (!config.token || typeof config.token !== 'string' || config.token.length < 10)
|
|
49
|
+
return false;
|
|
50
|
+
if (config.tokenExpiresAt && Date.now() > config.tokenExpiresAt)
|
|
51
|
+
return false;
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","source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AAC,GAAG,CAAC,EAAE,OAAO,EAAE,CAAC,GAAG,CAAC,CAsB3F"}
|
package/dist/helpers.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { ApiError } from './api.js';
|
|
2
|
+
export function jsonResult(data) {
|
|
3
|
+
return {
|
|
4
|
+
content: [{ type: 'text', text: JSON.stringify(data, null, 2) }],
|
|
5
|
+
};
|
|
6
|
+
}
|
|
7
|
+
export function withErrorHandling(handler) {
|
|
8
|
+
return (async (...args) => {
|
|
9
|
+
try {
|
|
10
|
+
return await handler(...args);
|
|
11
|
+
}
|
|
12
|
+
catch (err) {
|
|
13
|
+
if (err instanceof ApiError) {
|
|
14
|
+
return {
|
|
15
|
+
isError: true,
|
|
16
|
+
content: [{ type: 'text', text: JSON.stringify({
|
|
17
|
+
error: { code: err.code, message: err.message, retryable: err.retryable,
|
|
18
|
+
...(err.retryable ? { retryAfterMs: 5000 } : {}) }
|
|
19
|
+
}, null, 2) }],
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
isError: true,
|
|
24
|
+
content: [{ type: 'text', text: JSON.stringify({
|
|
25
|
+
error: { code: 'INTERNAL_ERROR', message: err.message, retryable: false }
|
|
26
|
+
}) }],
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AAEnC,MAAM,UAAU,UAAU,CAAC,IAAa;IACtC,OAAO;QACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC;KAC1E,CAAA;AACH,CAAC;AAED,MAAM,UAAU,iBAAiB,CAA6C,OAAU;IACtF,OAAO,CAAC,KAAK,EAAE,GAAG,IAAW,EAAE,EAAE;QAC/B,IAAI,CAAC;YACH,OAAO,MAAM,OAAO,CAAC,GAAG,IAAI,CAAC,CAAA;QAC/B,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,IAAI,GAAG,YAAY,QAAQ,EAAE,CAAC;gBAC5B,OAAO;oBACL,OAAO,EAAE,IAAI;oBACb,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;gCACtD,KAAK,EAAE,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,EAAE,SAAS,EAAE,GAAG,CAAC,SAAS;oCACrE,GAAG,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE;6BACrD,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC;iBACf,CAAA;YACH,CAAC;YACD,OAAO;gBACL,OAAO,EAAE,IAAI;gBACb,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;4BACtD,KAAK,EAAE,EAAE,IAAI,EAAE,gBAAgB,EAAE,OAAO,EAAG,GAAa,CAAC,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE;yBACrF,CAAC,EAAE,CAAC;aACN,CAAA;QACH,CAAC;IACH,CAAC,CAAM,CAAA;AACT,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import http from 'node:http';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import { randomUUID } from 'node:crypto';
|
|
7
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
8
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
9
|
+
import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
|
|
10
|
+
import { registerAuthTools } from './tools/auth.js';
|
|
11
|
+
import { registerMarketTools } from './tools/market.js';
|
|
12
|
+
import { registerPortfolioTools } from './tools/portfolio.js';
|
|
13
|
+
import { registerStrategyTools } from './tools/strategy.js';
|
|
14
|
+
import { registerBacktestTools } from './tools/backtest.js';
|
|
15
|
+
import { registerBotTools } from './tools/bot.js';
|
|
16
|
+
import { registerTradeTools } from './tools/trades.js';
|
|
17
|
+
import { registerCopyTradingTools } from './tools/copy-trading.js';
|
|
18
|
+
import { registerAdvisorTools } from './tools/advisor.js';
|
|
19
|
+
import { registerPrompts } from './prompts/index.js';
|
|
20
|
+
import { registerResources } from './resources/index.js';
|
|
21
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
22
|
+
const version = fs.readFileSync(path.join(__dirname, '..', 'VERSION'), 'utf-8').trim();
|
|
23
|
+
const mode = process.argv.includes('--http') ? 'http' : 'stdio';
|
|
24
|
+
const port = parseInt(process.env.MCP_PORT || '3100', 10);
|
|
25
|
+
function createServer() {
|
|
26
|
+
const server = new McpServer({ name: 'tradestaq', version }, { capabilities: { logging: {} } });
|
|
27
|
+
registerAuthTools(server);
|
|
28
|
+
registerMarketTools(server);
|
|
29
|
+
registerPortfolioTools(server);
|
|
30
|
+
registerStrategyTools(server);
|
|
31
|
+
registerBacktestTools(server);
|
|
32
|
+
registerBotTools(server);
|
|
33
|
+
registerTradeTools(server);
|
|
34
|
+
registerCopyTradingTools(server);
|
|
35
|
+
registerAdvisorTools(server);
|
|
36
|
+
registerPrompts(server);
|
|
37
|
+
registerResources(server);
|
|
38
|
+
return server;
|
|
39
|
+
}
|
|
40
|
+
if (mode === 'http') {
|
|
41
|
+
// HTTP+SSE transport — multiple clients, stateful sessions
|
|
42
|
+
const sessions = new Map();
|
|
43
|
+
const httpServer = http.createServer(async (req, res) => {
|
|
44
|
+
// CORS headers for browser-based MCP clients
|
|
45
|
+
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
46
|
+
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, DELETE, OPTIONS');
|
|
47
|
+
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, mcp-session-id');
|
|
48
|
+
res.setHeader('Access-Control-Expose-Headers', 'mcp-session-id');
|
|
49
|
+
if (req.method === 'OPTIONS') {
|
|
50
|
+
res.writeHead(204);
|
|
51
|
+
res.end();
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
// Health check
|
|
55
|
+
if (req.url === '/health') {
|
|
56
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
57
|
+
res.end(JSON.stringify({ status: 'ok', version, sessions: sessions.size }));
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
// MCP endpoint
|
|
61
|
+
if (req.url === '/mcp') {
|
|
62
|
+
const sessionId = req.headers['mcp-session-id'];
|
|
63
|
+
if (req.method === 'POST' && !sessionId) {
|
|
64
|
+
// New session — create server + transport
|
|
65
|
+
const transport = new StreamableHTTPServerTransport({
|
|
66
|
+
sessionIdGenerator: () => randomUUID(),
|
|
67
|
+
});
|
|
68
|
+
const server = createServer();
|
|
69
|
+
await server.connect(transport);
|
|
70
|
+
transport.onclose = () => {
|
|
71
|
+
const sid = transport.sessionId;
|
|
72
|
+
if (sid)
|
|
73
|
+
sessions.delete(sid);
|
|
74
|
+
};
|
|
75
|
+
await transport.handleRequest(req, res);
|
|
76
|
+
if (transport.sessionId) {
|
|
77
|
+
sessions.set(transport.sessionId, { server, transport });
|
|
78
|
+
}
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
if (sessionId && sessions.has(sessionId)) {
|
|
82
|
+
// Existing session
|
|
83
|
+
const session = sessions.get(sessionId);
|
|
84
|
+
await session.transport.handleRequest(req, res);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
// Unknown session or missing session ID on non-init request
|
|
88
|
+
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
89
|
+
res.end(JSON.stringify({ error: 'Invalid or missing session' }));
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
res.writeHead(404);
|
|
93
|
+
res.end('Not found');
|
|
94
|
+
});
|
|
95
|
+
httpServer.listen(port, '0.0.0.0', () => {
|
|
96
|
+
console.log(`TradeStaq MCP server v${version} (HTTP+SSE) listening on port ${port}`);
|
|
97
|
+
console.log(`Endpoint: http://localhost:${port}/mcp`);
|
|
98
|
+
console.log(`Health: http://localhost:${port}/health`);
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
// stdio transport — local process (Claude Desktop, Cursor, Claude Code)
|
|
103
|
+
const server = createServer();
|
|
104
|
+
const transport = new StdioServerTransport();
|
|
105
|
+
await server.connect(transport);
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AACxC,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAA;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAA;AAChF,OAAO,EAAE,6BAA6B,EAAE,MAAM,oDAAoD,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