@crush-protocol/mcp-client 0.1.3 → 0.1.5

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 CHANGED
@@ -1,159 +1,87 @@
1
- # @crush-protocol/mcp-client
1
+ # Crush Protocol MCP Server
2
2
 
3
3
  [![npm version](https://badge.fury.io/js/%40crush-protocol%2Fmcp-client.svg)](https://www.npmjs.com/package/@crush-protocol/mcp-client)
4
4
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
5
5
 
6
- Crush Protocol MCP client — SDK + CLI for interacting with the Crush MCP Server.
6
+ **AI-powered quantitative trading tools for Claude Code and other MCP clients.**
7
7
 
8
- ## Features
8
+ Run backtests, validate trading strategies, and query market data — directly from your AI coding assistant.
9
9
 
10
- - **Remote MCP SDK** Connect to the Crush MCP Server via Streamable HTTP, authenticated with `Bearer mcp_xxx` tokens.
11
- - **Backtest SDK** — Typed wrappers for all backtest tools (`getConfigSchema`, `createBacktest`, `getResult`, etc.).
12
- - **ClickHouse direct** _(optional)_ — Read-only direct ClickHouse access with a row cap safety limit.
13
- - **CLI** — Command-line tool for quick testing and scripting.
10
+ ## Without Crush Protocol MCP
14
11
 
15
- ## Requirements
12
+ - ❌ Manually switch between your IDE and trading dashboards
13
+ - ❌ Copy-paste backtest configs and wait for results separately
14
+ - ❌ No way for your AI agent to iterate on strategies automatically
16
15
 
17
- - Node.js >= 20
18
- - A valid `mcp_xxx` token (issued by the Crush MCP Server)
16
+ ## With Crush Protocol MCP
19
17
 
20
- ## Installation
18
+ Your AI agent can **create, run, and analyze backtests** in a single conversation:
21
19
 
22
- ```bash
23
- npm install @crush-protocol/mcp-client
20
+ ```txt
21
+ Run a backtest on ETHUSDT on Hyperliquid using a 4h timeframe,
22
+ entry when RSI < 30, exit when RSI > 70. Use crush protocol mcp.
24
23
  ```
25
24
 
26
- ## Quick Start
27
-
28
- ### Get a Token
29
-
30
- Tokens are issued by the Crush MCP Server's REST API. Use your Privy JWT to claim one:
31
-
32
- ```bash
33
- curl -X POST https://your-server/v1/mcp-tokens \
34
- -H "Authorization: Bearer <privy-jwt>" \
35
- -H "Content-Type: application/json" \
36
- -d '{"name": "my-token"}'
37
- # → {"data": {"token": "mcp_xxx", ...}}
25
+ ```txt
26
+ List my last 10 completed backtests and summarize the best performing strategy.
38
27
  ```
39
28
 
40
- Store the returned `mcp_xxx` tokenit is shown only once.
29
+ The AI agent calls the Crush Protocol MCP tools directly no tab-switching, no manual data entry.
41
30
 
42
31
  ---
43
32
 
44
- ## SDK Usage
45
-
46
- ```typescript
47
- import { RemoteMcpClient, BacktestClient } from '@crush-protocol/mcp-client'
48
-
49
- const mcp = new RemoteMcpClient({
50
- serverUrl: 'https://your-server/mcp',
51
- token: 'mcp_xxx',
52
- })
53
- await mcp.connect()
54
-
55
- const backtest = new BacktestClient(mcp)
56
-
57
- // Get supported configuration schema
58
- const schema = await backtest.getConfigSchema()
59
-
60
- // List available tokens for a platform
61
- const { tokens } = await backtest.getAvailableTokens({ platform: 'hyperliquid_perps' })
62
-
63
- // Validate an entry/exit expression
64
- const validation = await backtest.validateExpression({
65
- expression: { type: 'comparison', field: 'close', operator: '>', value: 100 },
66
- dataSource: 'kline',
67
- })
68
-
69
- // Create a backtest
70
- const bt = await backtest.createBacktest({
71
- config: {
72
- token: { symbol: 'ETHUSDT' },
73
- platform: 'hyperliquid_perps',
74
- timeframe: '240',
75
- entry: {
76
- /* AST expression */
77
- },
78
- },
79
- })
80
-
81
- // Poll for result
82
- const result = await backtest.getResult({ backtestId: bt.backtestId })
33
+ ## Getting a Token
83
34
 
84
- // List backtests
85
- const list = await backtest.list({ status: 'COMPLETED', limit: 10 })
86
-
87
- await mcp.close()
88
- ```
35
+ Tokens are issued from the Crush Protocol web app. After logging in, navigate to **Settings → API Tokens** to create an `mcp_xxx` token.
89
36
 
90
37
  ---
91
38
 
92
- ## CLI Usage
93
-
94
- ### General
95
-
96
- ```bash
97
- # Ping the MCP server
98
- crush-mcp-client ping --url https://your-server/mcp --token mcp_xxx
39
+ ## Installation
99
40
 
100
- # List available tools
101
- crush-mcp-client tools:list --url https://your-server/mcp --token mcp_xxx
41
+ ### Claude Code
102
42
 
103
- # Call any tool by name
104
- crush-mcp-client tool:call --name get_backtest_config_schema --args '{}' --token mcp_xxx
43
+ ```sh
44
+ claude mcp add --scope user crush-protocol -- npx -y @crush-protocol/mcp-client
105
45
  ```
106
46
 
107
- ### Backtest
47
+ Then set your credentials:
108
48
 
109
- ```bash
110
- crush-mcp-client backtest:schema --token mcp_xxx
111
- crush-mcp-client backtest:tokens --platform hyperliquid_perps --token mcp_xxx
112
- crush-mcp-client backtest:validate \
113
- --expression '{"type":"comparison","field":"close","operator":">","value":100}' \
114
- --token mcp_xxx
115
- crush-mcp-client backtest:create \
116
- --config '{"token":{"symbol":"ETHUSDT"},"platform":"hyperliquid_perps","timeframe":"240","entry":{}}' \
49
+ ```sh
50
+ claude mcp add --scope user crush-protocol \
51
+ -- npx -y @crush-protocol/mcp-client \
52
+ --url https://mcp.crush-protocol.com/mcp \
117
53
  --token mcp_xxx
118
- crush-mcp-client backtest:get --backtest-id <id> --token mcp_xxx
119
- crush-mcp-client backtest:list --status COMPLETED --limit 10 --token mcp_xxx
120
54
  ```
121
55
 
122
- ### ClickHouse Direct (read-only)
56
+ Or via environment variables in `~/.claude.json`:
123
57
 
124
- ```bash
125
- crush-mcp-client clickhouse:list-tables \
126
- --ch-host localhost --ch-port 8123 --ch-user default --ch-password "" --ch-database crush_ats
127
-
128
- crush-mcp-client clickhouse:query \
129
- --sql "SELECT * FROM system.tables LIMIT 10" --ch-database system
58
+ ```json
59
+ {
60
+ "mcpServers": {
61
+ "crush-protocol": {
62
+ "command": "npx",
63
+ "args": ["-y", "@crush-protocol/mcp-client"],
64
+ "env": {
65
+ "CRUSH_MCP_SERVER_URL": "https://mcp.crush-protocol.com/mcp",
66
+ "CRUSH_MCP_TOKEN": "mcp_xxx"
67
+ }
68
+ }
69
+ }
70
+ }
130
71
  ```
131
72
 
132
- ### Environment Variables
133
-
134
- Set these to avoid passing flags on every command:
135
-
136
- | Variable | Description |
137
- | ----------------------------------------------------------------- | ----------------------------------------------------- |
138
- | `CRUSH_MCP_SERVER_URL` | MCP server URL (default: `http://localhost:8080/mcp`) |
139
- | `CRUSH_MCP_TOKEN` | MCP auth token (`mcp_xxx`) |
140
- | `CH_HOST` / `CH_PORT` / `CH_USER` / `CH_PASSWORD` / `CH_DATABASE` | ClickHouse connection |
141
- | `CH_ROW_CAP` | Max rows returned (default: `5000`) |
142
-
143
- ---
144
-
145
- ## Configure Claude Code (MCP Integration)
73
+ ### Cursor
146
74
 
147
- Add to your Claude Code config (`~/.claude.json`):
75
+ Add to `~/.cursor/mcp.json`:
148
76
 
149
77
  ```json
150
78
  {
151
79
  "mcpServers": {
152
- "crush": {
80
+ "crush-protocol": {
153
81
  "command": "npx",
154
- "args": ["-y", "@crush-protocol/mcp-client", "tools:list"],
82
+ "args": ["-y", "@crush-protocol/mcp-client"],
155
83
  "env": {
156
- "CRUSH_MCP_SERVER_URL": "https://your-server/mcp",
84
+ "CRUSH_MCP_SERVER_URL": "https://mcp.crush-protocol.com/mcp",
157
85
  "CRUSH_MCP_TOKEN": "mcp_xxx"
158
86
  }
159
87
  }
@@ -163,11 +91,53 @@ Add to your Claude Code config (`~/.claude.json`):
163
91
 
164
92
  ---
165
93
 
166
- ## Security
94
+ ## Available Tools
95
+
96
+ | Tool | Description |
97
+ | ---------------------------- | --------------------------------------------------------------- |
98
+ | `get_backtest_config_schema` | Get supported platforms, timeframes, and strategy config schema |
99
+ | `get_available_tokens` | List tradable tokens, optionally filtered by platform |
100
+ | `validate_expression` | Validate and compile an entry/exit AST expression |
101
+ | `create_backtest` | Create or update a backtest with a strategy config |
102
+ | `get_backtest_result` | Fetch result, summary, portfolio history and trades |
103
+ | `list_backtests` | List your backtests with optional status filter and pagination |
104
+
105
+ ---
106
+
107
+ ## Environment Variables
108
+
109
+ | Variable | Description |
110
+ | ---------------------- | -------------------------------------------------------------------- |
111
+ | `CRUSH_MCP_SERVER_URL` | MCP server URL (default: `https://crush-mcp-ats.dev.xexlab.com/mcp`) |
112
+ | `CRUSH_MCP_TOKEN` | MCP auth token (`mcp_xxx`) |
113
+
114
+ ---
115
+
116
+ ## SDK Usage (Advanced)
117
+
118
+ For programmatic access:
167
119
 
168
- - Tokens must be in the format `mcp_xxx`. Invalid formats are rejected immediately.
169
- - Tokens are transmitted via `Authorization: Bearer` header over HTTPS.
170
- - ClickHouse direct mode enforces `readonly=1` and a row cap to prevent abuse.
120
+ ```typescript
121
+ import { RemoteMcpClient, BacktestClient } from '@crush-protocol/mcp-client'
122
+
123
+ const mcp = new RemoteMcpClient({
124
+ serverUrl: 'https://mcp.crush-protocol.com/mcp',
125
+ token: 'mcp_xxx',
126
+ })
127
+ await mcp.connect()
128
+
129
+ const backtest = new BacktestClient(mcp)
130
+ const bt = await backtest.createBacktest({
131
+ config: {
132
+ /* ... */
133
+ },
134
+ })
135
+ const result = await backtest.getResult({ backtestId: bt.backtestId })
136
+
137
+ await mcp.close()
138
+ ```
139
+
140
+ ---
171
141
 
172
142
  ## License
173
143
 
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,50 @@
1
+ import { describe, it, expect, beforeAll, afterAll } from "vitest";
2
+ import { RemoteMcpClient } from "../mcp/remoteClient.js";
3
+ import { BacktestClient } from "../backtest/backtestClient.js";
4
+ /**
5
+ * E2E 测试:验证 MCP client 能成功连接服务端并调用工具。
6
+ *
7
+ * 前置条件(通过环境变量或 .env.e2e 配置):
8
+ * CRUSH_MCP_SERVER_URL — 指向运行中的 MCP server(默认 http://localhost:3333/mcp)
9
+ * CRUSH_MCP_TOKEN — 有效的 mcp_xxx token
10
+ */
11
+ const serverUrl = process.env.CRUSH_MCP_SERVER_URL ?? "http://localhost:3333/mcp";
12
+ const token = process.env.CRUSH_MCP_TOKEN ?? "";
13
+ // 没有 token 时跳过所有 e2e 测试
14
+ const describeE2E = token ? describe : describe.skip;
15
+ describeE2E("MCP Client E2E", () => {
16
+ let mcp;
17
+ let backtest;
18
+ beforeAll(async () => {
19
+ mcp = new RemoteMcpClient({ serverUrl, token });
20
+ await mcp.connect();
21
+ backtest = new BacktestClient(mcp);
22
+ });
23
+ afterAll(async () => {
24
+ await mcp.close();
25
+ });
26
+ it("ping — 服务端可达", async () => {
27
+ const result = await mcp.ping();
28
+ expect(result).toBeDefined();
29
+ });
30
+ it("listTools — 返回至少一个工具", async () => {
31
+ const { tools } = await mcp.listTools();
32
+ expect(tools.length).toBeGreaterThan(0);
33
+ });
34
+ it("backtest:schema — 返回支持的配置 schema", async () => {
35
+ const schema = await backtest.getConfigSchema();
36
+ expect(schema).toHaveProperty("platforms");
37
+ expect(schema).toHaveProperty("timeframes");
38
+ expect(Array.isArray(schema.platforms)).toBe(true);
39
+ });
40
+ it("backtest:tokens — 返回可用交易对列表", async () => {
41
+ const result = await backtest.getAvailableTokens();
42
+ expect(result).toHaveProperty("tokens");
43
+ expect(Array.isArray(result.tokens)).toBe(true);
44
+ });
45
+ it("backtest:list — 返回当前用户的回测列表", async () => {
46
+ const result = await backtest.list({ limit: 5 });
47
+ expect(result).toHaveProperty("backtests");
48
+ expect(typeof result.total).toBe("number");
49
+ });
50
+ });
package/dist/cli.js CHANGED
@@ -32,7 +32,7 @@ const requireString = (value, message) => {
32
32
  const createRemoteClient = (flags) => {
33
33
  const serverUrl = typeof flags.url === "string"
34
34
  ? flags.url
35
- : (process.env.CRUSH_MCP_SERVER_URL ?? "http://localhost:8080/mcp");
35
+ : (process.env.CRUSH_MCP_SERVER_URL ?? "https://crush-mcp-ats.dev.xexlab.com/mcp");
36
36
  const token = typeof flags.token === "string"
37
37
  ? flags.token
38
38
  : requireString(process.env.CRUSH_MCP_TOKEN, "Missing token. Use --token or CRUSH_MCP_TOKEN");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crush-protocol/mcp-client",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "Crush MCP npm client package (remote Streamable HTTP + optional ClickHouse direct)",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -18,22 +18,26 @@
18
18
  "default": "./dist/index.js"
19
19
  }
20
20
  },
21
+ "scripts": {
22
+ "build": "tsc -p tsconfig.json",
23
+ "dev": "tsx src/cli.ts",
24
+ "test:e2e": "dotenv -e .env.e2e vitest run src/__tests__/e2e.test.ts",
25
+ "prepublishOnly": "pnpm run build"
26
+ },
21
27
  "dependencies": {
28
+ "@crush-protocol/mcp-contracts": "workspace:*",
22
29
  "@modelcontextprotocol/sdk": "^1.26.0",
23
30
  "dotenv": "^17.2.1",
24
- "zod": "^3.25.76",
25
- "@crush-protocol/mcp-contracts": "0.1.0"
31
+ "zod": "^3.25.76"
26
32
  },
27
33
  "devDependencies": {
28
34
  "@types/node": "^24.3.0",
35
+ "dotenv-cli": "^8.0.0",
29
36
  "tsx": "^4.20.4",
30
- "typescript": "^5.9.2"
37
+ "typescript": "^5.9.2",
38
+ "vitest": "^3.2.4"
31
39
  },
32
40
  "engines": {
33
41
  "node": ">=20"
34
- },
35
- "scripts": {
36
- "build": "tsc -p tsconfig.json",
37
- "dev": "tsx src/cli.ts"
38
42
  }
39
- }
43
+ }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2025 Edwin Hernandez
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.