@crush-protocol/mcp-client 0.4.3 → 0.4.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/dist/cli.js CHANGED
@@ -3,6 +3,7 @@ import "dotenv/config";
3
3
  import { BacktestClient } from "./backtest/backtestClient.js";
4
4
  import { ClickHouseDirectClient } from "./clickhouse/directClient.js";
5
5
  import { DEFAULT_MCP_SERVER_URL } from "./config.js";
6
+ import { assertManualLoginNotRequired } from "./mcp/authPreflight.js";
6
7
  import { OAuthRemoteMcpClient } from "./mcp/oauthRemoteClient.js";
7
8
  import { getCachedAuthStatus, loadStoredTokens } from "./mcp/oauthStorage.js";
8
9
  import { runProxy } from "./mcp/proxy.js";
@@ -73,6 +74,11 @@ const createSmartClient = (flags) => {
73
74
  };
74
75
  };
75
76
  const connectClient = async (flags) => {
77
+ const explicitToken = getExplicitToken(flags);
78
+ if (!explicitToken) {
79
+ const serverUrl = getServerUrl(typeof flags.server === "string" ? flags.server : undefined);
80
+ await assertManualLoginNotRequired(serverUrl);
81
+ }
76
82
  const { client, needsOAuthConnect } = createSmartClient(flags);
77
83
  if (needsOAuthConnect) {
78
84
  await client.connect();
@@ -0,0 +1,9 @@
1
+ import { type CachedAuthStatus } from "./oauthStorage.js";
2
+ export type AuthPreflightResult = {
3
+ authStatus: CachedAuthStatus;
4
+ requiresManualLogin: boolean;
5
+ canAutoRefreshLogin: boolean;
6
+ };
7
+ export declare const getAuthPreflight: (serverUrl: string) => Promise<AuthPreflightResult>;
8
+ export declare const assertManualLoginNotRequired: (serverUrl: string) => Promise<AuthPreflightResult>;
9
+ export declare const getPreflightStatusMessage: (preflight: AuthPreflightResult) => string | null;
@@ -0,0 +1,26 @@
1
+ import { formatAutomaticRefreshMessage, formatLoginRequiredMessage } from "../onboarding/cliOutput.js";
2
+ import { getCachedAuthStatus } from "./oauthStorage.js";
3
+ export const getAuthPreflight = async (serverUrl) => {
4
+ const authStatus = await getCachedAuthStatus(serverUrl);
5
+ return {
6
+ authStatus,
7
+ requiresManualLogin: authStatus.status === "not_authenticated",
8
+ canAutoRefreshLogin: authStatus.status !== "not_authenticated",
9
+ };
10
+ };
11
+ export const assertManualLoginNotRequired = async (serverUrl) => {
12
+ const preflight = await getAuthPreflight(serverUrl);
13
+ if (preflight.requiresManualLogin) {
14
+ throw new Error(formatLoginRequiredMessage(serverUrl));
15
+ }
16
+ return preflight;
17
+ };
18
+ export const getPreflightStatusMessage = (preflight) => {
19
+ if (preflight.requiresManualLogin) {
20
+ return formatLoginRequiredMessage(preflight.authStatus.serverUrl);
21
+ }
22
+ if (preflight.authStatus.status === "registered") {
23
+ return formatAutomaticRefreshMessage(preflight.authStatus.serverUrl);
24
+ }
25
+ return null;
26
+ };
@@ -9,6 +9,7 @@ export type InteractiveOAuthProviderOptions = {
9
9
  redirectPath?: string;
10
10
  storageDir?: string;
11
11
  openBrowser?: boolean;
12
+ authorizationOutput?: "stdout" | "stderr" | "silent";
12
13
  onAuthorizationUrl?: (authorizationUrl: URL) => void | Promise<void>;
13
14
  };
14
15
  export declare class InteractiveOAuthProvider implements OAuthClientProvider {
@@ -17,6 +18,7 @@ export declare class InteractiveOAuthProvider implements OAuthClientProvider {
17
18
  private readonly storageFile;
18
19
  private readonly scope;
19
20
  private readonly openBrowserByDefault;
21
+ private readonly authorizationOutput;
20
22
  private readonly onAuthorizationUrl?;
21
23
  private callbackServer?;
22
24
  private pendingAuthorization?;
@@ -72,6 +72,7 @@ export class InteractiveOAuthProvider {
72
72
  storageFile;
73
73
  scope;
74
74
  openBrowserByDefault;
75
+ authorizationOutput;
75
76
  onAuthorizationUrl;
76
77
  callbackServer;
77
78
  pendingAuthorization;
@@ -82,6 +83,7 @@ export class InteractiveOAuthProvider {
82
83
  this.redirectUrl = new URL(`http://127.0.0.1:${redirectPort}${redirectPath}`);
83
84
  this.scope = options.scope ?? DEFAULT_OAUTH_SCOPE;
84
85
  this.openBrowserByDefault = options.openBrowser ?? true;
86
+ this.authorizationOutput = options.authorizationOutput ?? "stdout";
85
87
  const storageDir = options.storageDir ?? defaultStorageDir();
86
88
  this.storageFile = getStorageFileForServer(options.serverUrl, storageDir);
87
89
  this.onAuthorizationUrl = options.onAuthorizationUrl;
@@ -132,7 +134,12 @@ export class InteractiveOAuthProvider {
132
134
  // Fall back to printing the URL when no browser launcher is available.
133
135
  }
134
136
  }
135
- process.stdout.write(`\nOpen this URL to authorize Crush MCP:\n${authorizationUrl.toString()}\n\n`);
137
+ if (this.authorizationOutput === "stdout") {
138
+ process.stdout.write(`\nOpen this URL to authorize Crush MCP:\n${authorizationUrl.toString()}\n\n`);
139
+ }
140
+ else if (this.authorizationOutput === "stderr") {
141
+ process.stderr.write(`\nOpen this URL to authorize Crush MCP:\n${authorizationUrl.toString()}\n\n`);
142
+ }
136
143
  }
137
144
  async saveCodeVerifier(codeVerifier) {
138
145
  const data = await this.loadState();
@@ -16,6 +16,9 @@ export declare class OAuthRemoteMcpClient implements McpClientLike {
16
16
  private readonly transport;
17
17
  private readonly authProvider;
18
18
  constructor(options: OAuthRemoteMcpClientOptions);
19
+ private isAuthError;
20
+ private recoverAuthorization;
21
+ private withReauthorization;
19
22
  connect(): Promise<void>;
20
23
  ensureAuthorized(): Promise<void>;
21
24
  runAuthFlow(): Promise<AuthResult>;
@@ -35,25 +35,38 @@ export class OAuthRemoteMcpClient {
35
35
  fetch: options.fetch,
36
36
  });
37
37
  }
38
+ isAuthError(error) {
39
+ return (error instanceof UnauthorizedError || String(error).includes("Unauthorized") || String(error).includes("401"));
40
+ }
41
+ async recoverAuthorization(error) {
42
+ if (!this.isAuthError(error)) {
43
+ throw error;
44
+ }
45
+ const authResult = await auth(this.authProvider, {
46
+ serverUrl: this.options.serverUrl,
47
+ scope: this.options.scope,
48
+ fetchFn: this.options.fetch,
49
+ });
50
+ if (authResult === "REDIRECT") {
51
+ const authorizationCode = await this.authProvider.waitForAuthorizationCode();
52
+ await this.transport.finishAuth(authorizationCode);
53
+ }
54
+ }
55
+ async withReauthorization(operation) {
56
+ try {
57
+ return await operation();
58
+ }
59
+ catch (error) {
60
+ await this.recoverAuthorization(error);
61
+ return operation();
62
+ }
63
+ }
38
64
  async connect() {
39
65
  try {
40
66
  await this.client.connect(this.transport);
41
67
  }
42
68
  catch (error) {
43
- if (!(error instanceof UnauthorizedError)) {
44
- throw error;
45
- }
46
- const authResult = await auth(this.authProvider, {
47
- serverUrl: this.options.serverUrl,
48
- scope: this.options.scope,
49
- fetchFn: this.options.fetch,
50
- });
51
- if (authResult !== "REDIRECT") {
52
- await this.client.connect(this.transport);
53
- return;
54
- }
55
- const authorizationCode = await this.authProvider.waitForAuthorizationCode();
56
- await this.transport.finishAuth(authorizationCode);
69
+ await this.recoverAuthorization(error);
57
70
  await this.client.connect(this.transport);
58
71
  }
59
72
  }
@@ -82,15 +95,15 @@ export class OAuthRemoteMcpClient {
82
95
  await this.transport.terminateSession();
83
96
  }
84
97
  async ping() {
85
- return this.client.ping();
98
+ return this.withReauthorization(() => this.client.ping());
86
99
  }
87
100
  async listTools() {
88
- return this.client.listTools();
101
+ return this.withReauthorization(() => this.client.listTools());
89
102
  }
90
103
  async callTool(name, args = {}) {
91
- return this.client.callTool({
104
+ return this.withReauthorization(() => this.client.callTool({
92
105
  name,
93
106
  arguments: args,
94
- });
107
+ }));
95
108
  }
96
109
  }
package/dist/mcp/proxy.js CHANGED
@@ -3,159 +3,74 @@
3
3
  *
4
4
  * 原理:
5
5
  * AI 工具(Cursor/Claude/Antigravity)通过 stdio 连接本 proxy,
6
- * proxy 读取 ~/.crush-mcp/ 中缓存的 OAuth token,
7
- * 将请求转发到远程 MCP Server(Streamable HTTP)。
6
+ * proxy 将请求转发到远程 MCP Server(Streamable HTTP)。
8
7
  *
9
8
  * 使用:
10
9
  * npx @crush-protocol/mcp-client proxy [SERVER_URL]
11
10
  *
12
11
  * 用户只需执行一次 `login` 获取 token,所有 AI 工具共享同一份凭证。
13
12
  */
14
- import { mkdir, readFile, writeFile } from "node:fs/promises";
15
- import path from "node:path";
16
- import { Client } from "@modelcontextprotocol/sdk/client/index.js";
17
- import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
18
13
  import { Server } from "@modelcontextprotocol/sdk/server/index.js";
19
14
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
20
15
  import { CallToolRequestSchema, ListToolsRequestSchema, PingRequestSchema } from "@modelcontextprotocol/sdk/types.js";
21
- import { getLoginCommand } from "../onboarding/cliOutput.js";
22
- import { defaultStorageDir, getStorageFileForServer, loadStoredTokens, } from "./oauthStorage.js";
16
+ import { getPreflightStatusMessage } from "./authPreflight.js";
17
+ import { OAuthRemoteMcpClient } from "./oauthRemoteClient.js";
18
+ import { getCachedAuthStatus } from "./oauthStorage.js";
23
19
  import { CLIENT_NAME, CLIENT_VERSION } from "./version.js";
24
- const saveTokens = async (serverUrl, tokens) => {
25
- const storageFile = getStorageFileForServer(serverUrl, defaultStorageDir());
26
- let state = {};
27
- try {
28
- const raw = await readFile(storageFile, "utf8");
29
- state = JSON.parse(raw);
30
- }
31
- catch {
32
- // ignore
33
- }
34
- state.tokens = tokens;
35
- await mkdir(path.dirname(storageFile), { recursive: true });
36
- await writeFile(storageFile, JSON.stringify(state, null, 2), { encoding: "utf8", mode: 0o600 });
37
- };
38
- /**
39
- * 尝试用 refresh_token 刷新 access_token
40
- */
41
- const refreshAccessToken = async (serverUrl, tokens) => {
42
- if (!tokens.refresh_token)
43
- return null;
44
- try {
45
- // 先获取 token_endpoint
46
- const metadataUrl = new URL("/.well-known/oauth-authorization-server", serverUrl);
47
- const metaRes = await fetch(metadataUrl.toString());
48
- if (!metaRes.ok)
49
- return null;
50
- const meta = (await metaRes.json());
51
- // 获取 client_id
52
- const storageFile = getStorageFileForServer(serverUrl, defaultStorageDir());
53
- const raw = await readFile(storageFile, "utf8");
54
- const state = JSON.parse(raw);
55
- const clientInfo = state.clientInformation;
56
- if (!clientInfo?.client_id)
57
- return null;
58
- const body = new URLSearchParams({
59
- grant_type: "refresh_token",
60
- refresh_token: tokens.refresh_token,
61
- client_id: clientInfo.client_id,
62
- });
63
- const res = await fetch(meta.token_endpoint, {
64
- method: "POST",
65
- headers: { "Content-Type": "application/x-www-form-urlencoded" },
66
- body: body.toString(),
67
- });
68
- if (!res.ok)
69
- return null;
70
- const newTokens = (await res.json());
71
- await saveTokens(serverUrl, newTokens);
72
- return newTokens;
73
- }
74
- catch {
75
- return null;
76
- }
77
- };
78
20
  export async function runProxy(serverUrl) {
79
- // 1. 加载缓存的 token
80
- let tokens = await loadStoredTokens(serverUrl);
81
- if (!tokens?.access_token) {
82
- process.stderr.write("Crush is connected but not authenticated.\n\n" +
83
- "Run this once in your terminal:\n" +
84
- `${getLoginCommand(serverUrl)}\n\n` +
85
- "After login, retry the same request.\n");
21
+ const authStatus = await getCachedAuthStatus(serverUrl);
22
+ if (authStatus.status === "not_authenticated") {
23
+ const message = getPreflightStatusMessage({
24
+ authStatus,
25
+ requiresManualLogin: true,
26
+ canAutoRefreshLogin: false,
27
+ });
28
+ process.stderr.write(`${message ?? "Crush needs sign-in on this machine."}\n`);
86
29
  process.exit(1);
87
30
  }
88
- // 2. 创建到远程 MCP Server 的 HTTP 客户端
89
- const createTransport = (token) => new StreamableHTTPClientTransport(new URL(serverUrl), {
90
- requestInit: {
91
- headers: {
92
- Authorization: `Bearer ${token}`,
93
- },
94
- },
31
+ const preflightMessage = getPreflightStatusMessage({
32
+ authStatus,
33
+ requiresManualLogin: false,
34
+ canAutoRefreshLogin: true,
95
35
  });
96
- const remoteClient = new Client({ name: `${CLIENT_NAME}-proxy`, version: CLIENT_VERSION }, { capabilities: {} });
97
- // 尝试连接,如果 401 则刷新 token
98
- let transport = createTransport(tokens.access_token);
99
- try {
100
- await remoteClient.connect(transport);
36
+ if (preflightMessage) {
37
+ process.stderr.write(`${preflightMessage}\n\n`);
101
38
  }
102
- catch (error) {
103
- const msg = String(error);
104
- if (msg.includes("401") || msg.includes("Unauthorized")) {
105
- process.stderr.write("Crush authentication expired. Attempting refresh...\n");
106
- const refreshed = await refreshAccessToken(serverUrl, tokens);
107
- if (!refreshed) {
108
- process.stderr.write("Crush authentication needs to be renewed.\n\n" +
109
- "Run:\n" +
110
- `${getLoginCommand(serverUrl)}\n\n` +
111
- "Then retry the same request.\n");
112
- process.exit(1);
113
- }
114
- tokens = refreshed;
115
- transport = createTransport(tokens.access_token);
116
- await remoteClient.connect(transport);
117
- }
118
- else {
119
- throw error;
120
- }
121
- }
122
- // 3. 获取远程 server 的能力
123
- const serverInfo = remoteClient.getServerVersion();
39
+ const remoteClient = new OAuthRemoteMcpClient({
40
+ serverUrl,
41
+ oauth: {
42
+ authorizationOutput: "stderr",
43
+ },
44
+ });
45
+ await remoteClient.connect();
124
46
  const remoteTools = await remoteClient.listTools();
125
- // 4. 创建本地 stdio server,代理所有请求
126
47
  const localServer = new Server({
127
- name: serverInfo?.name ?? "crush-mcp-proxy",
128
- version: serverInfo?.version ?? "1.0.0",
48
+ name: `${CLIENT_NAME}-proxy`,
49
+ version: CLIENT_VERSION,
129
50
  }, {
130
51
  capabilities: {
131
52
  tools: { listChanged: false },
132
53
  },
133
54
  });
134
- // 代理 tools/list
135
55
  localServer.setRequestHandler(ListToolsRequestSchema, async () => {
136
56
  try {
137
- const result = await remoteClient.listTools();
138
- return result;
57
+ return await remoteClient.listTools();
139
58
  }
140
59
  catch {
141
60
  return { tools: remoteTools.tools };
142
61
  }
143
62
  });
144
- // 代理 tools/call
145
63
  localServer.setRequestHandler(CallToolRequestSchema, async (request) => {
146
64
  const { name, arguments: args } = request.params;
147
- return remoteClient.callTool({ name, arguments: args ?? {} });
65
+ return remoteClient.callTool(name, (args ?? {}));
148
66
  });
149
- // 代理 ping
150
67
  localServer.setRequestHandler(PingRequestSchema, async () => {
151
68
  await remoteClient.ping();
152
69
  return {};
153
70
  });
154
- // 5. 启动 stdio transport
155
71
  const stdioTransport = new StdioServerTransport();
156
72
  await localServer.connect(stdioTransport);
157
73
  process.stderr.write(`[crush-mcp-proxy] Connected to ${serverUrl} | stdio proxy ready\n`);
158
- // 优雅关闭
159
74
  const cleanup = async () => {
160
75
  await localServer.close();
161
76
  await remoteClient.close();
@@ -7,6 +7,8 @@ export type DoctorCheck = {
7
7
  };
8
8
  export declare const getTargetLabel: (target: SetupTarget) => string;
9
9
  export declare const getLoginCommand: (serverUrl: string) => string;
10
+ export declare const formatLoginRequiredMessage: (serverUrl: string) => string;
11
+ export declare const formatAutomaticRefreshMessage: (serverUrl: string) => string;
10
12
  export declare const formatSetupSummary: (results: SetupInstallResult[], scope: SetupScope) => string;
11
13
  export declare const formatAuthStatus: (status: CachedAuthStatus) => string;
12
14
  export declare const formatDoctorReport: (serverUrl: string, checks: DoctorCheck[]) => string;
@@ -14,6 +14,21 @@ export const getTargetLabel = (target) => TARGET_LABELS[target];
14
14
  export const getLoginCommand = (serverUrl) => serverUrl === DEFAULT_MCP_SERVER_URL
15
15
  ? `npx -y ${PACKAGE_NAME} login`
16
16
  : `CRUSH_MCP_SERVER_URL=\"${serverUrl}\" npx -y ${PACKAGE_NAME} login`;
17
+ export const formatLoginRequiredMessage = (serverUrl) => [
18
+ "Crush needs sign-in on this machine.",
19
+ "",
20
+ "Run this once in your terminal:",
21
+ getLoginCommand(serverUrl),
22
+ "",
23
+ "Then retry the same request.",
24
+ ].join("\n");
25
+ export const formatAutomaticRefreshMessage = (serverUrl) => [
26
+ "Crush found previous local authorization data.",
27
+ "Refreshing the sign-in flow automatically...",
28
+ "",
29
+ "If the browser does not open, run:",
30
+ getLoginCommand(serverUrl),
31
+ ].join("\n");
17
32
  export const formatSetupSummary = (results, scope) => {
18
33
  const targets = results.map((result) => getTargetLabel(result.target)).join(", ");
19
34
  const lines = [
package/package.json CHANGED
@@ -1,47 +1,69 @@
1
1
  {
2
- "name": "@crush-protocol/mcp-client",
3
- "version": "0.4.3",
4
- "description": "Crush MCP npm client package (remote Streamable HTTP + optional ClickHouse direct)",
5
- "type": "module",
6
- "license": "MIT",
7
- "main": "dist/index.js",
8
- "types": "dist/index.d.ts",
9
- "bin": {
10
- "crush-mcp-client": "dist/cli.js"
11
- },
12
- "files": [
13
- "dist",
14
- "INSTRUCTIONS.md"
15
- ],
16
- "publishConfig": {
17
- "access": "public"
18
- },
19
- "exports": {
20
- ".": {
21
- "types": "./dist/index.d.ts",
22
- "default": "./dist/index.js"
23
- }
24
- },
25
- "dependencies": {
26
- "@modelcontextprotocol/sdk": "^1.26.0",
27
- "dotenv": "^17.2.1",
28
- "zod": "^3.25.76",
29
- "@crush-protocol/mcp-contracts": "0.1.2"
30
- },
31
- "devDependencies": {
32
- "@types/node": "^24.3.0",
33
- "dotenv-cli": "^8.0.0",
34
- "tsx": "^4.20.4",
35
- "typescript": "^5.9.2",
36
- "vitest": "^3.2.4"
37
- },
38
- "engines": {
39
- "node": ">=20"
40
- },
41
- "scripts": {
42
- "build": "tsc -p tsconfig.json",
43
- "dev": "tsx src/cli.ts",
44
- "test": "vitest run",
45
- "test:e2e": "dotenv -e .env.e2e vitest run src/__tests__/e2e.test.ts"
46
- }
47
- }
2
+ "name": "@crush-protocol/mcp-client",
3
+ "version": "0.4.5",
4
+ "description": "Official Crush MCP client for hosted market data, backtests, and trading workflows",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "homepage": "https://github.com/crush-protocol/crush-mcp-server/tree/main/packages/crush-mcp-client#readme",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/crush-protocol/crush-mcp-server.git",
11
+ "directory": "packages/crush-mcp-client"
12
+ },
13
+ "bugs": {
14
+ "url": "https://github.com/crush-protocol/crush-mcp-server/issues"
15
+ },
16
+ "keywords": [
17
+ "crush",
18
+ "crush-protocol",
19
+ "mcp",
20
+ "model-context-protocol",
21
+ "trading",
22
+ "backtest",
23
+ "quant",
24
+ "cursor",
25
+ "claude-code",
26
+ "codex"
27
+ ],
28
+ "main": "dist/index.js",
29
+ "types": "dist/index.d.ts",
30
+ "bin": {
31
+ "crush-mcp-client": "dist/cli.js"
32
+ },
33
+ "files": [
34
+ "dist",
35
+ "INSTRUCTIONS.md"
36
+ ],
37
+ "publishConfig": {
38
+ "access": "public"
39
+ },
40
+ "exports": {
41
+ ".": {
42
+ "types": "./dist/index.d.ts",
43
+ "default": "./dist/index.js"
44
+ }
45
+ },
46
+ "scripts": {
47
+ "build": "rm -rf dist && tsc -p tsconfig.json",
48
+ "dev": "tsx src/cli.ts",
49
+ "test": "vitest run",
50
+ "test:e2e": "dotenv -e .env.e2e vitest run src/__tests__/e2e.test.ts",
51
+ "prepublishOnly": "pnpm run build"
52
+ },
53
+ "dependencies": {
54
+ "@crush-protocol/mcp-contracts": "workspace:*",
55
+ "@modelcontextprotocol/sdk": "^1.26.0",
56
+ "dotenv": "^17.2.1",
57
+ "zod": "^3.25.76"
58
+ },
59
+ "devDependencies": {
60
+ "@types/node": "^24.3.0",
61
+ "dotenv-cli": "^8.0.0",
62
+ "tsx": "^4.20.4",
63
+ "typescript": "^5.9.2",
64
+ "vitest": "^3.2.4"
65
+ },
66
+ "engines": {
67
+ "node": ">=20"
68
+ }
69
+ }
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.
@@ -1 +0,0 @@
1
- export {};
@@ -1,34 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { formatAuthStatus, formatSetupSummary, getLoginCommand } from "../onboarding/cliOutput.js";
3
- describe("cliOutput", () => {
4
- it("renders setup summary with next steps", () => {
5
- const results = [
6
- {
7
- target: "cursor",
8
- scope: "user",
9
- status: "created",
10
- location: "/tmp/.cursor/mcp.json",
11
- },
12
- ];
13
- const output = formatSetupSummary(results, "user");
14
- expect(output).toContain("Crush MCP configured for Cursor.");
15
- expect(output).toContain("Restart Cursor");
16
- expect(output).toContain("npx -y @crush-protocol/mcp-client login");
17
- });
18
- it("renders auth status with login guidance when missing", () => {
19
- const output = formatAuthStatus({
20
- serverUrl: "https://crush-mcp-ats.dev.xexlab.com/mcp",
21
- status: "not_authenticated",
22
- hasClientInformation: false,
23
- hasAccessToken: false,
24
- hasRefreshToken: false,
25
- hasCodeVerifier: false,
26
- });
27
- expect(output).toContain("Status: Not authenticated");
28
- expect(output).toContain("Run:");
29
- expect(output).toContain("npx -y @crush-protocol/mcp-client login");
30
- });
31
- it("renders custom login command for non-default server URLs", () => {
32
- expect(getLoginCommand("https://example.com/mcp")).toBe('CRUSH_MCP_SERVER_URL="https://example.com/mcp" npx -y @crush-protocol/mcp-client login');
33
- });
34
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,50 +0,0 @@
1
- import { afterAll, beforeAll, describe, expect, it } from "vitest";
2
- import { BacktestClient } from "../backtest/backtestClient.js";
3
- import { OAuthRemoteMcpClient } from "../mcp/oauthRemoteClient.js";
4
- /**
5
- * E2E 测试:验证 MCP client 能成功连接服务端并调用工具。
6
- *
7
- * 前置条件(通过环境变量或 .env.e2e 配置):
8
- * CRUSH_MCP_SERVER_URL — 指向运行中的 MCP server(默认 https://crush-mcp-ats.dev.xexlab.com/mcp)
9
- * CRUSH_OAUTH_ACCESS_TOKEN — 有效的 OAuth access token
10
- */
11
- const serverUrl = process.env.CRUSH_MCP_SERVER_URL ?? "https://crush-mcp-ats.dev.xexlab.com/mcp";
12
- const token = process.env.CRUSH_OAUTH_ACCESS_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 OAuthRemoteMcpClient({ serverUrl, token, oauth: { openBrowser: false } });
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
- });
@@ -1 +0,0 @@
1
- export {};