tokenwallet-mcp 1.0.1 → 1.0.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tokenwallet-mcp",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "TokenWallet MCP Server for QR pairing and automatic real-time AI token quota syncing",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -26,7 +26,7 @@
26
26
  ],
27
27
  "repository": {
28
28
  "type": "git",
29
- "url": "https://github.com/token-wallet-app/mcp.git"
29
+ "url": "git+https://github.com/token-wallet-app/mcp.git"
30
30
  },
31
31
  "homepage": "https://token-wallet.app",
32
32
  "scripts": {
@@ -36,6 +36,7 @@
36
36
  "prepublishOnly": "npm run build",
37
37
  "start": "node dist/index.js",
38
38
  "start:http": "node dist/index.js --http",
39
+ "test": "tsx --test test/providers.test.ts",
39
40
  "typecheck": "tsc --noEmit"
40
41
  },
41
42
  "dependencies": {
@@ -1,108 +0,0 @@
1
- import fs from 'node:fs';
2
- import os from 'node:os';
3
- import path from 'node:path';
4
- import { maskEmail, toEpochMs } from './types.js';
5
- function getCursorStateDbPath() {
6
- if (process.env.CURSOR_STATE_DB)
7
- return process.env.CURSOR_STATE_DB;
8
- if (process.platform === 'win32') {
9
- const appData = process.env.APPDATA || path.join(os.homedir(), 'AppData', 'Roaming');
10
- return path.join(appData, 'Cursor', 'User', 'globalStorage', 'state.vscdb');
11
- }
12
- if (process.platform === 'darwin') {
13
- return path.join(os.homedir(), 'Library', 'Application Support', 'Cursor', 'User', 'globalStorage', 'state.vscdb');
14
- }
15
- return path.join(os.homedir(), '.config', 'Cursor', 'User', 'globalStorage', 'state.vscdb');
16
- }
17
- async function readCursorLocalAuth() {
18
- const envToken = process.env.CURSOR_ACCESS_TOKEN?.trim();
19
- if (envToken)
20
- return { token: envToken };
21
- const dbPath = getCursorStateDbPath();
22
- if (!fs.existsSync(dbPath))
23
- return null;
24
- try {
25
- const sqlite = await import('node:sqlite');
26
- const db = new sqlite.DatabaseSync(dbPath, { readOnly: true });
27
- try {
28
- const tokenRow = db
29
- .prepare("SELECT value FROM ItemTable WHERE key = 'cursorAuth/accessToken'")
30
- .get();
31
- const emailRow = db
32
- .prepare("SELECT value FROM ItemTable WHERE key = 'cursorAuth/cachedEmail'")
33
- .get();
34
- const token = tokenRow?.value?.trim();
35
- if (!token)
36
- return null;
37
- return { token, email: emailRow?.value?.trim() };
38
- }
39
- finally {
40
- db.close();
41
- }
42
- }
43
- catch {
44
- return null;
45
- }
46
- }
47
- export async function collectCursorQuota() {
48
- const auth = await readCursorLocalAuth();
49
- if (!auth)
50
- return null;
51
- const endpoints = [
52
- 'https://api2.cursor.sh/auth/usage-summary',
53
- 'https://cursor.com/api/usage-summary',
54
- ];
55
- let data = null;
56
- for (const url of endpoints) {
57
- const res = await fetch(url, {
58
- method: 'GET',
59
- headers: {
60
- Authorization: `Bearer ${auth.token}`,
61
- Accept: 'application/json',
62
- 'User-Agent': 'tokenwallet-mcp/1.0',
63
- },
64
- signal: AbortSignal.timeout(8000),
65
- }).catch(() => null);
66
- if (res && res.ok) {
67
- data = (await res.json().catch(() => null));
68
- if (data?.individualUsage)
69
- break;
70
- }
71
- }
72
- if (!data?.individualUsage)
73
- return null;
74
- const now = Date.now();
75
- const resetsAt = toEpochMs(data.billingCycleEnd);
76
- const meters = [];
77
- const planUsage = data.individualUsage.plan;
78
- if (planUsage && typeof planUsage.limit === 'number' && planUsage.limit > 0) {
79
- const remainingRaw = typeof planUsage.remaining === 'number'
80
- ? planUsage.remaining
81
- : Math.max(0, planUsage.limit - Number(planUsage.used ?? 0));
82
- const pct = Math.max(0, Math.min(100, Math.round((remainingRaw / planUsage.limit) * 1000) / 10));
83
- meters.push({
84
- meterKey: 'month',
85
- product: 'cursor',
86
- label: '本月额度',
87
- kind: 'percent',
88
- window: 'month',
89
- remaining: pct,
90
- total: 100,
91
- unit: '%',
92
- resetsAt,
93
- observedAt: now,
94
- });
95
- }
96
- if (meters.length === 0)
97
- return null;
98
- const membership = data.membershipType?.trim();
99
- const plan = membership ? membership.charAt(0).toUpperCase() + membership.slice(1) : undefined;
100
- return {
101
- brand: 'cursor',
102
- plan,
103
- accountHint: maskEmail(auth.email),
104
- observedAt: now,
105
- source: 'cursor',
106
- meters,
107
- };
108
- }