tokenwallet-mcp 0.0.0-stage → 1.0.1
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 +118 -2
- package/dist/api.js +49 -0
- package/dist/codex-reader.js +146 -0
- package/dist/collectors/claude.js +107 -0
- package/dist/collectors/cursor.js +108 -0
- package/dist/collectors/gemini.js +112 -0
- package/dist/collectors/grok.js +42 -0
- package/dist/collectors/index.js +41 -0
- package/dist/collectors/types.js +25 -0
- package/dist/config.js +66 -0
- package/dist/index.js +127 -0
- package/dist/server.js +334 -0
- package/package.json +50 -4
package/README.md
CHANGED
|
@@ -1,3 +1,119 @@
|
|
|
1
|
-
#
|
|
1
|
+
# TokenWallet MCP
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Official MCP server for [TokenWallet](https://token-wallet.app) — connect your AI clients to the TokenWallet app and keep your token quotas in sync automatically.
|
|
4
|
+
|
|
5
|
+
[简体中文](#简体中文)
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
### CLI (Codex CLI / Claude Code / Gemini CLI)
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
# Codex CLI
|
|
15
|
+
codex mcp add tokenwallet -- npx -y tokenwallet-mcp
|
|
16
|
+
|
|
17
|
+
# Claude Code
|
|
18
|
+
claude mcp add tokenwallet -- npx -y tokenwallet-mcp
|
|
19
|
+
|
|
20
|
+
# Gemini CLI
|
|
21
|
+
gemini mcp add tokenwallet npx -y tokenwallet-mcp
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### Desktop & IDE (Cursor / Antigravity / Claude Desktop / Windsurf / Cline & more)
|
|
25
|
+
|
|
26
|
+
Add the following to your client's MCP configuration file (works with any MCP-compatible IDE or AI client):
|
|
27
|
+
|
|
28
|
+
```json
|
|
29
|
+
{
|
|
30
|
+
"mcpServers": {
|
|
31
|
+
"tokenwallet": {
|
|
32
|
+
"command": "npx",
|
|
33
|
+
"args": ["-y", "tokenwallet-mcp"]
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### VS Code
|
|
40
|
+
|
|
41
|
+
Add to your user or workspace `.vscode/mcp.json`:
|
|
42
|
+
|
|
43
|
+
```json
|
|
44
|
+
{
|
|
45
|
+
"servers": {
|
|
46
|
+
"tokenwallet": {
|
|
47
|
+
"type": "stdio",
|
|
48
|
+
"command": "npx",
|
|
49
|
+
"args": ["-y", "tokenwallet-mcp"]
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Quick Start
|
|
56
|
+
|
|
57
|
+
1. After installation, start a conversation in your AI client and say:
|
|
58
|
+
**"Connect to TokenWallet"**
|
|
59
|
+
2. Open the **TokenWallet** app on your phone, tap **+** → select the platform → **Scan QR Code** (or enter the 8-character pairing code manually).
|
|
60
|
+
3. Once connected, your quota updates will sync to the TokenWallet app automatically.
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## 简体中文
|
|
65
|
+
|
|
66
|
+
[TokenWallet(词元钱包)](https://token-wallet.app) 官方 MCP 服务,将你的 AI 客户端连接到词元钱包 App,自动同步额度状态。
|
|
67
|
+
|
|
68
|
+
### 安装方式
|
|
69
|
+
|
|
70
|
+
#### 命令行客户端(Codex CLI / Claude Code / Gemini CLI)
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
# Codex CLI
|
|
74
|
+
codex mcp add tokenwallet -- npx -y tokenwallet-mcp
|
|
75
|
+
|
|
76
|
+
# Claude Code
|
|
77
|
+
claude mcp add tokenwallet -- npx -y tokenwallet-mcp
|
|
78
|
+
|
|
79
|
+
# Gemini CLI
|
|
80
|
+
gemini mcp add tokenwallet npx -y tokenwallet-mcp
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
#### 桌面端与 IDE(Cursor / Antigravity / Claude Desktop / Windsurf / Cline 等)
|
|
84
|
+
|
|
85
|
+
在对应客户端的 MCP 配置文件中加入(其他任何支持 MCP 协议的 IDE 或 AI 客户端均可按相同方式配置使用):
|
|
86
|
+
|
|
87
|
+
```json
|
|
88
|
+
{
|
|
89
|
+
"mcpServers": {
|
|
90
|
+
"tokenwallet": {
|
|
91
|
+
"command": "npx",
|
|
92
|
+
"args": ["-y", "tokenwallet-mcp"]
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
#### VS Code
|
|
99
|
+
|
|
100
|
+
在用户或项目 `.vscode/mcp.json` 中加入:
|
|
101
|
+
|
|
102
|
+
```json
|
|
103
|
+
{
|
|
104
|
+
"servers": {
|
|
105
|
+
"tokenwallet": {
|
|
106
|
+
"type": "stdio",
|
|
107
|
+
"command": "npx",
|
|
108
|
+
"args": ["-y", "tokenwallet-mcp"]
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### 快速开始
|
|
115
|
+
|
|
116
|
+
1. 安装完成后,在 AI 客户端对话中输入:
|
|
117
|
+
**「帮我连接 TokenWallet」**
|
|
118
|
+
2. 打开手机上的 **词元钱包(TokenWallet)** App,点击右上角 **+** → 选择对应平台 → **扫描二维码**(若无法扫码可手动输入 8 位配对码)。
|
|
119
|
+
3. 绑定完成后,额度将自动同步至你的词元钱包 App。
|
package/dist/api.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
async function requestJson(baseUrl, pathname, options = {}) {
|
|
2
|
+
const url = `${baseUrl.replace(/\/+$/, '')}${pathname}`;
|
|
3
|
+
const headers = {
|
|
4
|
+
Accept: 'application/json',
|
|
5
|
+
'Content-Type': 'application/json; charset=utf-8',
|
|
6
|
+
};
|
|
7
|
+
if (options.token) {
|
|
8
|
+
headers.Authorization = `Bearer ${options.token}`;
|
|
9
|
+
}
|
|
10
|
+
const res = await fetch(url, {
|
|
11
|
+
method: options.method ?? 'GET',
|
|
12
|
+
headers,
|
|
13
|
+
body: options.body !== undefined ? JSON.stringify(options.body) : undefined,
|
|
14
|
+
});
|
|
15
|
+
const data = (await res.json().catch(() => null));
|
|
16
|
+
if (!res.ok) {
|
|
17
|
+
const msg = data?.error?.message || `TokenWallet API error (${res.status})`;
|
|
18
|
+
const err = new Error(msg);
|
|
19
|
+
err.code = data?.error?.code;
|
|
20
|
+
err.status = res.status;
|
|
21
|
+
throw err;
|
|
22
|
+
}
|
|
23
|
+
return data;
|
|
24
|
+
}
|
|
25
|
+
export function apiCreateMcpSession(baseUrl, params) {
|
|
26
|
+
return requestJson(baseUrl, '/mcp/sessions', {
|
|
27
|
+
method: 'POST',
|
|
28
|
+
body: params,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
export function apiPollMcpSession(baseUrl, sessionId, pollToken) {
|
|
32
|
+
return requestJson(baseUrl, `/mcp/sessions/${encodeURIComponent(sessionId)}/poll`, { method: 'GET', token: pollToken });
|
|
33
|
+
}
|
|
34
|
+
export function apiSubmitReport(baseUrl, writeToken, params) {
|
|
35
|
+
return requestJson(baseUrl, '/reports', {
|
|
36
|
+
method: 'POST',
|
|
37
|
+
token: writeToken,
|
|
38
|
+
body: {
|
|
39
|
+
...params,
|
|
40
|
+
observedAt: params.observedAt ?? Date.now(),
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
export function apiPingNode(baseUrl, writeToken) {
|
|
45
|
+
return requestJson(baseUrl, '/reports/ping', {
|
|
46
|
+
method: 'GET',
|
|
47
|
+
token: writeToken,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
function normalizePlan(planType) {
|
|
5
|
+
if (!planType)
|
|
6
|
+
return undefined;
|
|
7
|
+
switch (planType.toLowerCase()) {
|
|
8
|
+
case 'plus':
|
|
9
|
+
return 'Plus';
|
|
10
|
+
case 'pro':
|
|
11
|
+
return 'Pro';
|
|
12
|
+
case 'team':
|
|
13
|
+
return 'Team';
|
|
14
|
+
case 'enterprise':
|
|
15
|
+
return 'Enterprise';
|
|
16
|
+
default:
|
|
17
|
+
return planType.charAt(0).toUpperCase() + planType.slice(1);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function collectJsonlFiles(rootDir) {
|
|
21
|
+
const results = [];
|
|
22
|
+
function walk(dir) {
|
|
23
|
+
let entries;
|
|
24
|
+
try {
|
|
25
|
+
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
for (const entry of entries) {
|
|
31
|
+
const fullPath = path.join(dir, entry.name);
|
|
32
|
+
if (entry.isDirectory()) {
|
|
33
|
+
walk(fullPath);
|
|
34
|
+
}
|
|
35
|
+
else if (entry.isFile() && entry.name.endsWith('.jsonl')) {
|
|
36
|
+
try {
|
|
37
|
+
const stat = fs.statSync(fullPath);
|
|
38
|
+
results.push({ filePath: fullPath, mtimeMs: stat.mtimeMs });
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
// Ignore unreadable file
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
walk(rootDir);
|
|
47
|
+
results.sort((a, b) => b.mtimeMs - a.mtimeMs);
|
|
48
|
+
return results;
|
|
49
|
+
}
|
|
50
|
+
function toEpochMs(raw) {
|
|
51
|
+
if (typeof raw !== 'number' || !Number.isFinite(raw) || raw <= 0)
|
|
52
|
+
return undefined;
|
|
53
|
+
// Codex stores resets_at in Unix seconds (~1.79e9); convert to ms if < 1e12
|
|
54
|
+
return raw < 1_000_000_000_000 ? Math.round(raw * 1000) : Math.round(raw);
|
|
55
|
+
}
|
|
56
|
+
function toRemainingPercent(usedPercent) {
|
|
57
|
+
if (typeof usedPercent !== 'number' || !Number.isFinite(usedPercent))
|
|
58
|
+
return undefined;
|
|
59
|
+
const remaining = Math.max(0, Math.min(100, 100 - usedPercent));
|
|
60
|
+
return Math.round(remaining * 10) / 10;
|
|
61
|
+
}
|
|
62
|
+
function parseLatestRateLimitsFromFile(filePath) {
|
|
63
|
+
let content;
|
|
64
|
+
try {
|
|
65
|
+
content = fs.readFileSync(filePath, 'utf8');
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
const lines = content.split(/\r?\n/);
|
|
71
|
+
for (let i = lines.length - 1; i >= 0; i--) {
|
|
72
|
+
const line = lines[i];
|
|
73
|
+
if (!line || !line.includes('"rate_limits"'))
|
|
74
|
+
continue;
|
|
75
|
+
let parsed;
|
|
76
|
+
try {
|
|
77
|
+
parsed = JSON.parse(line);
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
const rl = parsed.payload?.rate_limits;
|
|
83
|
+
if (!rl || (!rl.primary && !rl.secondary))
|
|
84
|
+
continue;
|
|
85
|
+
const observedAt = (parsed.timestamp ? Date.parse(parsed.timestamp) : NaN) || Date.now();
|
|
86
|
+
const meters = [];
|
|
87
|
+
if (rl.primary) {
|
|
88
|
+
const remaining = toRemainingPercent(rl.primary.used_percent);
|
|
89
|
+
if (remaining !== undefined) {
|
|
90
|
+
const is5h = !rl.primary.window_minutes || rl.primary.window_minutes <= 360;
|
|
91
|
+
meters.push({
|
|
92
|
+
meterKey: is5h ? '5h' : `w${rl.primary.window_minutes}m`,
|
|
93
|
+
product: rl.limit_id || 'codex',
|
|
94
|
+
label: is5h ? '5 小时' : `${Math.round((rl.primary.window_minutes ?? 300) / 60)} 小时`,
|
|
95
|
+
kind: 'percent',
|
|
96
|
+
window: is5h ? '5h' : 'rolling',
|
|
97
|
+
remaining,
|
|
98
|
+
total: 100,
|
|
99
|
+
unit: '%',
|
|
100
|
+
resetsAt: toEpochMs(rl.primary.resets_at),
|
|
101
|
+
observedAt,
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
if (rl.secondary) {
|
|
106
|
+
const remaining = toRemainingPercent(rl.secondary.used_percent);
|
|
107
|
+
if (remaining !== undefined) {
|
|
108
|
+
const isWeek = !rl.secondary.window_minutes || rl.secondary.window_minutes >= 7200;
|
|
109
|
+
meters.push({
|
|
110
|
+
meterKey: isWeek ? '7d' : `w${rl.secondary.window_minutes}m`,
|
|
111
|
+
product: rl.limit_id || 'codex',
|
|
112
|
+
label: isWeek ? '每周额度' : `${Math.round((rl.secondary.window_minutes ?? 10080) / 1440)} 天额度`,
|
|
113
|
+
kind: 'percent',
|
|
114
|
+
window: isWeek ? 'week' : 'rolling',
|
|
115
|
+
remaining,
|
|
116
|
+
total: 100,
|
|
117
|
+
unit: '%',
|
|
118
|
+
resetsAt: toEpochMs(rl.secondary.resets_at),
|
|
119
|
+
observedAt,
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
if (meters.length > 0) {
|
|
124
|
+
return {
|
|
125
|
+
plan: normalizePlan(rl.plan_type),
|
|
126
|
+
observedAt,
|
|
127
|
+
sourceFile: filePath,
|
|
128
|
+
meters,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
export function readLatestCodexQuota() {
|
|
135
|
+
const codexHome = process.env.CODEX_HOME || path.join(os.homedir(), '.codex');
|
|
136
|
+
const sessionsDir = path.join(codexHome, 'sessions');
|
|
137
|
+
if (!fs.existsSync(sessionsDir))
|
|
138
|
+
return null;
|
|
139
|
+
const files = collectJsonlFiles(sessionsDir).slice(0, 8);
|
|
140
|
+
for (const { filePath } of files) {
|
|
141
|
+
const snap = parseLatestRateLimitsFromFile(filePath);
|
|
142
|
+
if (snap)
|
|
143
|
+
return snap;
|
|
144
|
+
}
|
|
145
|
+
return null;
|
|
146
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { toEpochMs, toRemainingPercent } from './types.js';
|
|
5
|
+
function readClaudeCredentials() {
|
|
6
|
+
const envToken = process.env.CLAUDE_CODE_OAUTH_TOKEN?.trim();
|
|
7
|
+
if (envToken)
|
|
8
|
+
return { token: envToken };
|
|
9
|
+
const configDir = process.env.CLAUDE_CONFIG_DIR || path.join(os.homedir(), '.claude');
|
|
10
|
+
const credFile = path.join(configDir, '.credentials.json');
|
|
11
|
+
if (!fs.existsSync(credFile))
|
|
12
|
+
return null;
|
|
13
|
+
try {
|
|
14
|
+
const parsed = JSON.parse(fs.readFileSync(credFile, 'utf8'));
|
|
15
|
+
const token = parsed.claudeAiOauth?.accessToken?.trim();
|
|
16
|
+
if (!token)
|
|
17
|
+
return null;
|
|
18
|
+
const sub = parsed.claudeAiOauth?.subscriptionType;
|
|
19
|
+
const plan = sub ? sub.charAt(0).toUpperCase() + sub.slice(1) : undefined;
|
|
20
|
+
return { token, plan };
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
export async function collectClaudeQuota() {
|
|
27
|
+
const creds = readClaudeCredentials();
|
|
28
|
+
if (!creds)
|
|
29
|
+
return null;
|
|
30
|
+
const res = await fetch('https://api.anthropic.com/api/oauth/usage', {
|
|
31
|
+
method: 'GET',
|
|
32
|
+
headers: {
|
|
33
|
+
Authorization: `Bearer ${creds.token}`,
|
|
34
|
+
'anthropic-beta': 'oauth-2025-04-20',
|
|
35
|
+
Accept: 'application/json',
|
|
36
|
+
'User-Agent': 'tokenwallet-mcp/1.0',
|
|
37
|
+
},
|
|
38
|
+
signal: AbortSignal.timeout(8000),
|
|
39
|
+
}).catch(() => null);
|
|
40
|
+
if (!res || !res.ok)
|
|
41
|
+
return null;
|
|
42
|
+
const data = (await res.json().catch(() => null));
|
|
43
|
+
if (!data)
|
|
44
|
+
return null;
|
|
45
|
+
const now = Date.now();
|
|
46
|
+
const meters = [];
|
|
47
|
+
if (data.five_hour && typeof data.five_hour.utilization === 'number') {
|
|
48
|
+
const remaining = toRemainingPercent(data.five_hour.utilization);
|
|
49
|
+
if (remaining !== undefined) {
|
|
50
|
+
meters.push({
|
|
51
|
+
meterKey: '5h',
|
|
52
|
+
product: 'claude-code',
|
|
53
|
+
label: '5 小时',
|
|
54
|
+
kind: 'percent',
|
|
55
|
+
window: '5h',
|
|
56
|
+
remaining,
|
|
57
|
+
total: 100,
|
|
58
|
+
unit: '%',
|
|
59
|
+
resetsAt: toEpochMs(data.five_hour.resets_at),
|
|
60
|
+
observedAt: now,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (data.seven_day && typeof data.seven_day.utilization === 'number') {
|
|
65
|
+
const remaining = toRemainingPercent(data.seven_day.utilization);
|
|
66
|
+
if (remaining !== undefined) {
|
|
67
|
+
meters.push({
|
|
68
|
+
meterKey: '7d',
|
|
69
|
+
product: 'claude-code',
|
|
70
|
+
label: '每周额度',
|
|
71
|
+
kind: 'percent',
|
|
72
|
+
window: 'week',
|
|
73
|
+
remaining,
|
|
74
|
+
total: 100,
|
|
75
|
+
unit: '%',
|
|
76
|
+
resetsAt: toEpochMs(data.seven_day.resets_at),
|
|
77
|
+
observedAt: now,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (data.extra_usage?.is_enabled &&
|
|
82
|
+
typeof data.extra_usage.monthly_limit === 'number' &&
|
|
83
|
+
data.extra_usage.monthly_limit > 0) {
|
|
84
|
+
const used = Number(data.extra_usage.used_credits ?? 0);
|
|
85
|
+
const remaining = Math.max(0, Math.round((data.extra_usage.monthly_limit - used) * 100) / 100);
|
|
86
|
+
meters.push({
|
|
87
|
+
meterKey: 'extra',
|
|
88
|
+
product: 'claude-code',
|
|
89
|
+
label: '额外额度',
|
|
90
|
+
kind: 'balance',
|
|
91
|
+
window: 'month',
|
|
92
|
+
remaining,
|
|
93
|
+
total: data.extra_usage.monthly_limit,
|
|
94
|
+
unit: 'USD',
|
|
95
|
+
observedAt: now,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
if (meters.length === 0)
|
|
99
|
+
return null;
|
|
100
|
+
return {
|
|
101
|
+
brand: 'claude',
|
|
102
|
+
plan: creds.plan,
|
|
103
|
+
observedAt: now,
|
|
104
|
+
source: 'claude-code',
|
|
105
|
+
meters,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { toEpochMs } from './types.js';
|
|
5
|
+
function readGeminiAccessToken() {
|
|
6
|
+
const envToken = process.env.GEMINI_OAUTH_TOKEN?.trim();
|
|
7
|
+
if (envToken)
|
|
8
|
+
return envToken;
|
|
9
|
+
const geminiHome = process.env.GEMINI_CLI_HOME || path.join(os.homedir(), '.gemini');
|
|
10
|
+
const credCandidates = [
|
|
11
|
+
path.join(geminiHome, 'oauth_creds.json'),
|
|
12
|
+
path.join(geminiHome, 'antigravity', 'oauth_creds.json'),
|
|
13
|
+
];
|
|
14
|
+
for (const file of credCandidates) {
|
|
15
|
+
if (!fs.existsSync(file))
|
|
16
|
+
continue;
|
|
17
|
+
try {
|
|
18
|
+
const parsed = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
19
|
+
if (parsed.access_token?.trim()) {
|
|
20
|
+
return parsed.access_token.trim();
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
// Try next candidate
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
export async function collectGeminiQuota() {
|
|
30
|
+
const token = readGeminiAccessToken();
|
|
31
|
+
if (!token)
|
|
32
|
+
return null;
|
|
33
|
+
const res = await fetch('https://cloudcode-pa.googleapis.com/v1internal:retrieveUserQuota', {
|
|
34
|
+
method: 'POST',
|
|
35
|
+
headers: {
|
|
36
|
+
Authorization: `Bearer ${token}`,
|
|
37
|
+
'Content-Type': 'application/json',
|
|
38
|
+
Accept: 'application/json',
|
|
39
|
+
},
|
|
40
|
+
body: JSON.stringify({}),
|
|
41
|
+
signal: AbortSignal.timeout(8000),
|
|
42
|
+
}).catch(() => null);
|
|
43
|
+
if (!res || !res.ok)
|
|
44
|
+
return null;
|
|
45
|
+
const data = (await res.json().catch(() => null));
|
|
46
|
+
if (!data?.buckets || data.buckets.length === 0)
|
|
47
|
+
return null;
|
|
48
|
+
const now = Date.now();
|
|
49
|
+
const proBuckets = data.buckets.filter((b) => b.modelId?.toLowerCase().includes('pro'));
|
|
50
|
+
const flashBuckets = data.buckets.filter((b) => b.modelId?.toLowerCase().includes('flash'));
|
|
51
|
+
const meters = [];
|
|
52
|
+
const pickLowest = (list) => list
|
|
53
|
+
.filter((b) => typeof b.remainingFraction === 'number')
|
|
54
|
+
.sort((a, b) => (a.remainingFraction ?? 1) - (b.remainingFraction ?? 1))[0];
|
|
55
|
+
const pro = pickLowest(proBuckets);
|
|
56
|
+
if (pro && typeof pro.remainingFraction === 'number') {
|
|
57
|
+
meters.push({
|
|
58
|
+
meterKey: 'pro',
|
|
59
|
+
product: 'gemini',
|
|
60
|
+
label: 'Gemini Pro',
|
|
61
|
+
kind: 'percent',
|
|
62
|
+
window: 'day',
|
|
63
|
+
modelGroup: pro.modelId,
|
|
64
|
+
remaining: Math.max(0, Math.min(100, Math.round(pro.remainingFraction * 1000) / 10)),
|
|
65
|
+
total: 100,
|
|
66
|
+
unit: '%',
|
|
67
|
+
resetsAt: toEpochMs(pro.resetTime),
|
|
68
|
+
observedAt: now,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
const flash = pickLowest(flashBuckets);
|
|
72
|
+
if (flash && typeof flash.remainingFraction === 'number') {
|
|
73
|
+
meters.push({
|
|
74
|
+
meterKey: 'flash',
|
|
75
|
+
product: 'gemini',
|
|
76
|
+
label: 'Gemini Flash',
|
|
77
|
+
kind: 'percent',
|
|
78
|
+
window: 'day',
|
|
79
|
+
modelGroup: flash.modelId,
|
|
80
|
+
remaining: Math.max(0, Math.min(100, Math.round(flash.remainingFraction * 1000) / 10)),
|
|
81
|
+
total: 100,
|
|
82
|
+
unit: '%',
|
|
83
|
+
resetsAt: toEpochMs(flash.resetTime),
|
|
84
|
+
observedAt: now,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
if (meters.length === 0) {
|
|
88
|
+
const first = pickLowest(data.buckets);
|
|
89
|
+
if (first && typeof first.remainingFraction === 'number') {
|
|
90
|
+
meters.push({
|
|
91
|
+
meterKey: 'default',
|
|
92
|
+
product: 'gemini',
|
|
93
|
+
label: first.modelId || 'Google AI',
|
|
94
|
+
kind: 'percent',
|
|
95
|
+
window: 'day',
|
|
96
|
+
remaining: Math.max(0, Math.min(100, Math.round(first.remainingFraction * 1000) / 10)),
|
|
97
|
+
total: 100,
|
|
98
|
+
unit: '%',
|
|
99
|
+
resetsAt: toEpochMs(first.resetTime),
|
|
100
|
+
observedAt: now,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
if (meters.length === 0)
|
|
105
|
+
return null;
|
|
106
|
+
return {
|
|
107
|
+
brand: 'gemini',
|
|
108
|
+
observedAt: now,
|
|
109
|
+
source: 'gemini-cli',
|
|
110
|
+
meters,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export async function collectGrokQuota() {
|
|
2
|
+
const mgmtKey = process.env.XAI_MANAGEMENT_API_KEY?.trim();
|
|
3
|
+
const teamId = process.env.XAI_TEAM_ID?.trim();
|
|
4
|
+
if (!mgmtKey || !teamId)
|
|
5
|
+
return null;
|
|
6
|
+
const res = await fetch(`https://management-api.x.ai/v1/billing/teams/${encodeURIComponent(teamId)}/prepaid/balance`, {
|
|
7
|
+
method: 'GET',
|
|
8
|
+
headers: {
|
|
9
|
+
Authorization: `Bearer ${mgmtKey}`,
|
|
10
|
+
Accept: 'application/json',
|
|
11
|
+
},
|
|
12
|
+
signal: AbortSignal.timeout(8000),
|
|
13
|
+
}).catch(() => null);
|
|
14
|
+
if (!res || !res.ok)
|
|
15
|
+
return null;
|
|
16
|
+
const data = (await res.json().catch(() => null));
|
|
17
|
+
if (!data)
|
|
18
|
+
return null;
|
|
19
|
+
const rawRemaining = data.remaining?.val ?? data.remaining_balance ?? data.balance ?? data.total?.val;
|
|
20
|
+
const remainingNum = typeof rawRemaining === 'string' ? Number(rawRemaining) : rawRemaining;
|
|
21
|
+
if (typeof remainingNum !== 'number' || !Number.isFinite(remainingNum))
|
|
22
|
+
return null;
|
|
23
|
+
// xAI billing API may return cents or dollars depending on field; normalize cleanly
|
|
24
|
+
const now = Date.now();
|
|
25
|
+
const meters = [
|
|
26
|
+
{
|
|
27
|
+
meterKey: 'balance:USD',
|
|
28
|
+
product: 'xai',
|
|
29
|
+
label: '可用余额',
|
|
30
|
+
kind: 'balance',
|
|
31
|
+
remaining: Math.round(remainingNum * 100) / 100,
|
|
32
|
+
unit: 'USD',
|
|
33
|
+
observedAt: now,
|
|
34
|
+
},
|
|
35
|
+
];
|
|
36
|
+
return {
|
|
37
|
+
brand: 'grok',
|
|
38
|
+
observedAt: now,
|
|
39
|
+
source: 'xai-billing',
|
|
40
|
+
meters,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { readLatestCodexQuota } from '../codex-reader.js';
|
|
2
|
+
import { collectClaudeQuota } from './claude.js';
|
|
3
|
+
import { collectCursorQuota } from './cursor.js';
|
|
4
|
+
import { collectGeminiQuota } from './gemini.js';
|
|
5
|
+
import { collectGrokQuota } from './grok.js';
|
|
6
|
+
export async function collectQuotaForBrand(brand) {
|
|
7
|
+
switch (brand) {
|
|
8
|
+
case 'openai': {
|
|
9
|
+
const codex = readLatestCodexQuota();
|
|
10
|
+
if (!codex)
|
|
11
|
+
return null;
|
|
12
|
+
return {
|
|
13
|
+
brand: 'openai',
|
|
14
|
+
plan: codex.plan,
|
|
15
|
+
observedAt: codex.observedAt,
|
|
16
|
+
source: 'codex',
|
|
17
|
+
meters: codex.meters,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
case 'claude':
|
|
21
|
+
return collectClaudeQuota();
|
|
22
|
+
case 'cursor':
|
|
23
|
+
return collectCursorQuota();
|
|
24
|
+
case 'gemini':
|
|
25
|
+
return collectGeminiQuota();
|
|
26
|
+
case 'grok':
|
|
27
|
+
return collectGrokQuota();
|
|
28
|
+
default:
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export async function collectAllLocalQuotas() {
|
|
33
|
+
const results = await Promise.all([
|
|
34
|
+
collectQuotaForBrand('openai'),
|
|
35
|
+
collectQuotaForBrand('claude'),
|
|
36
|
+
collectQuotaForBrand('cursor'),
|
|
37
|
+
collectQuotaForBrand('gemini'),
|
|
38
|
+
collectQuotaForBrand('grok'),
|
|
39
|
+
]);
|
|
40
|
+
return results.filter((snap) => snap !== null);
|
|
41
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export function maskEmail(email) {
|
|
2
|
+
if (!email || !email.includes('@'))
|
|
3
|
+
return undefined;
|
|
4
|
+
const [user, domain] = email.trim().split('@');
|
|
5
|
+
if (!user || !domain)
|
|
6
|
+
return undefined;
|
|
7
|
+
const prefix = user.length <= 2 ? user[0] : user.slice(0, 2);
|
|
8
|
+
return `${prefix}***@${domain}`;
|
|
9
|
+
}
|
|
10
|
+
export function toRemainingPercent(usedPercent) {
|
|
11
|
+
if (typeof usedPercent !== 'number' || !Number.isFinite(usedPercent))
|
|
12
|
+
return undefined;
|
|
13
|
+
const remaining = Math.max(0, Math.min(100, 100 - usedPercent));
|
|
14
|
+
return Math.round(remaining * 10) / 10;
|
|
15
|
+
}
|
|
16
|
+
export function toEpochMs(raw) {
|
|
17
|
+
if (typeof raw === 'string' && raw.trim()) {
|
|
18
|
+
const parsed = Date.parse(raw);
|
|
19
|
+
return Number.isFinite(parsed) ? parsed : undefined;
|
|
20
|
+
}
|
|
21
|
+
if (typeof raw === 'number' && Number.isFinite(raw) && raw > 0) {
|
|
22
|
+
return raw < 1_000_000_000_000 ? Math.round(raw * 1000) : Math.round(raw);
|
|
23
|
+
}
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
const DEFAULT_API_URL = process.env.TOKENWALLET_API_URL || 'https://api.token-wallet.app/v1';
|
|
5
|
+
const CONFIG_DIR = process.env.TOKENWALLET_MCP_HOME || path.join(os.homedir(), '.tokenwallet-mcp');
|
|
6
|
+
const CONFIG_FILE = path.join(CONFIG_DIR, 'config.json');
|
|
7
|
+
export function getApiBaseUrl() {
|
|
8
|
+
const cfg = loadConfig();
|
|
9
|
+
return (process.env.TOKENWALLET_API_URL || cfg.apiBaseUrl || DEFAULT_API_URL).replace(/\/+$/, '');
|
|
10
|
+
}
|
|
11
|
+
export function loadConfig() {
|
|
12
|
+
try {
|
|
13
|
+
if (fs.existsSync(CONFIG_FILE)) {
|
|
14
|
+
const parsed = JSON.parse(fs.readFileSync(CONFIG_FILE, 'utf8'));
|
|
15
|
+
return {
|
|
16
|
+
apiBaseUrl: parsed.apiBaseUrl || DEFAULT_API_URL,
|
|
17
|
+
connections: Array.isArray(parsed.connections) ? parsed.connections : [],
|
|
18
|
+
pendingSessions: Array.isArray(parsed.pendingSessions) ? parsed.pendingSessions : [],
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
// Fall through to default config
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
apiBaseUrl: DEFAULT_API_URL,
|
|
27
|
+
connections: [],
|
|
28
|
+
pendingSessions: [],
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export function saveConfig(config) {
|
|
32
|
+
fs.mkdirSync(CONFIG_DIR, { recursive: true });
|
|
33
|
+
fs.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2), { encoding: 'utf8', mode: 0o600 });
|
|
34
|
+
}
|
|
35
|
+
export function savePendingSession(session) {
|
|
36
|
+
const cfg = loadConfig();
|
|
37
|
+
const now = Date.now();
|
|
38
|
+
const active = cfg.pendingSessions.filter((s) => s.sessionId !== session.sessionId && s.expiresAt > now);
|
|
39
|
+
active.unshift(session);
|
|
40
|
+
cfg.pendingSessions = active.slice(0, 10);
|
|
41
|
+
saveConfig(cfg);
|
|
42
|
+
}
|
|
43
|
+
export function removePendingSession(sessionId) {
|
|
44
|
+
const cfg = loadConfig();
|
|
45
|
+
cfg.pendingSessions = cfg.pendingSessions.filter((s) => s.sessionId !== sessionId);
|
|
46
|
+
saveConfig(cfg);
|
|
47
|
+
}
|
|
48
|
+
export function upsertBoundConnection(conn) {
|
|
49
|
+
const cfg = loadConfig();
|
|
50
|
+
const existingIdx = cfg.connections.findIndex((c) => c.cardId === conn.cardId);
|
|
51
|
+
if (existingIdx >= 0) {
|
|
52
|
+
cfg.connections[existingIdx] = conn;
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
cfg.connections.unshift(conn);
|
|
56
|
+
}
|
|
57
|
+
saveConfig(cfg);
|
|
58
|
+
}
|
|
59
|
+
export function markConnectionReported(cardId, reportedAt = Date.now()) {
|
|
60
|
+
const cfg = loadConfig();
|
|
61
|
+
const target = cfg.connections.find((c) => c.cardId === cardId);
|
|
62
|
+
if (target) {
|
|
63
|
+
target.lastReportedAt = reportedAt;
|
|
64
|
+
saveConfig(cfg);
|
|
65
|
+
}
|
|
66
|
+
}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import http from 'node:http';
|
|
3
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
4
|
+
import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
|
|
5
|
+
import { apiSubmitReport } from './api.js';
|
|
6
|
+
import { collectQuotaForBrand } from './collectors/index.js';
|
|
7
|
+
import { getApiBaseUrl, loadConfig, markConnectionReported } from './config.js';
|
|
8
|
+
import { createTokenWalletMcpServer } from './server.js';
|
|
9
|
+
function parseArgs() {
|
|
10
|
+
const argv = process.argv.slice(2);
|
|
11
|
+
const useHttp = argv.includes('--http') || process.env.MCP_TRANSPORT === 'http';
|
|
12
|
+
const portIdx = argv.indexOf('--port');
|
|
13
|
+
const port = (portIdx >= 0 && Number(argv[portIdx + 1])) ||
|
|
14
|
+
Number(process.env.PORT) ||
|
|
15
|
+
8788;
|
|
16
|
+
return { useHttp, port };
|
|
17
|
+
}
|
|
18
|
+
function startLocalAutoReporter() {
|
|
19
|
+
const lastFingerprintByCard = new Map();
|
|
20
|
+
const tick = async () => {
|
|
21
|
+
try {
|
|
22
|
+
const cfg = loadConfig();
|
|
23
|
+
if (cfg.connections.length === 0)
|
|
24
|
+
return;
|
|
25
|
+
const baseUrl = getApiBaseUrl();
|
|
26
|
+
const uniqueBrands = Array.from(new Set(cfg.connections.map((c) => c.brand)));
|
|
27
|
+
for (const brand of uniqueBrands) {
|
|
28
|
+
const snap = await collectQuotaForBrand(brand);
|
|
29
|
+
if (!snap || snap.meters.length === 0)
|
|
30
|
+
continue;
|
|
31
|
+
const sig = JSON.stringify(snap.meters.map((m) => [m.meterKey, m.remaining, m.resetsAt ?? null]));
|
|
32
|
+
const matchingConns = cfg.connections.filter((c) => c.brand === brand);
|
|
33
|
+
for (const conn of matchingConns) {
|
|
34
|
+
if (lastFingerprintByCard.get(conn.cardId) === sig)
|
|
35
|
+
continue;
|
|
36
|
+
await apiSubmitReport(baseUrl, conn.writeToken, {
|
|
37
|
+
plan: snap.plan,
|
|
38
|
+
accountHint: snap.accountHint,
|
|
39
|
+
observedAt: snap.observedAt,
|
|
40
|
+
meters: snap.meters,
|
|
41
|
+
});
|
|
42
|
+
markConnectionReported(conn.cardId, Date.now());
|
|
43
|
+
lastFingerprintByCard.set(conn.cardId, sig);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
// Ignore transient network errors during background sync
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
void tick();
|
|
52
|
+
const timer = setInterval(() => {
|
|
53
|
+
void tick();
|
|
54
|
+
}, 60_000);
|
|
55
|
+
timer.unref();
|
|
56
|
+
}
|
|
57
|
+
async function startStdio() {
|
|
58
|
+
const server = createTokenWalletMcpServer();
|
|
59
|
+
const transport = new StdioServerTransport();
|
|
60
|
+
await server.connect(transport);
|
|
61
|
+
startLocalAutoReporter();
|
|
62
|
+
console.error(`[tokenwallet-mcp] stdio ready (API: ${getApiBaseUrl()})`);
|
|
63
|
+
}
|
|
64
|
+
async function startHttp(port) {
|
|
65
|
+
const httpServer = http.createServer(async (req, res) => {
|
|
66
|
+
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
67
|
+
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, DELETE, OPTIONS');
|
|
68
|
+
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Accept, Mcp-Session-Id');
|
|
69
|
+
if (req.method === 'OPTIONS') {
|
|
70
|
+
res.writeHead(204);
|
|
71
|
+
res.end();
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const url = new URL(req.url || '/', `http://${req.headers.host || 'localhost'}`);
|
|
75
|
+
const pathname = url.pathname.replace(/\/+$/, '') || '/';
|
|
76
|
+
const acceptHeader = String(req.headers.accept || '');
|
|
77
|
+
const isBrowserHealthCheck = req.method === 'GET' &&
|
|
78
|
+
(pathname === '/health' || (pathname === '/' && !acceptHeader.includes('text/event-stream')));
|
|
79
|
+
if (isBrowserHealthCheck) {
|
|
80
|
+
res.writeHead(200, { 'Content-Type': 'application/json; charset=utf-8' });
|
|
81
|
+
res.end(JSON.stringify({
|
|
82
|
+
ok: true,
|
|
83
|
+
service: 'tokenwallet-mcp',
|
|
84
|
+
transport: 'streamable-http',
|
|
85
|
+
mcpEndpoint: '/',
|
|
86
|
+
apiBaseUrl: getApiBaseUrl(),
|
|
87
|
+
}));
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
if (pathname === '/' || pathname === '/mcp') {
|
|
91
|
+
try {
|
|
92
|
+
const server = createTokenWalletMcpServer();
|
|
93
|
+
const transport = new StreamableHTTPServerTransport({
|
|
94
|
+
sessionIdGenerator: undefined,
|
|
95
|
+
});
|
|
96
|
+
res.on('close', () => {
|
|
97
|
+
void transport.close();
|
|
98
|
+
void server.close();
|
|
99
|
+
});
|
|
100
|
+
await server.connect(transport);
|
|
101
|
+
await transport.handleRequest(req, res);
|
|
102
|
+
}
|
|
103
|
+
catch (err) {
|
|
104
|
+
console.error('[tokenwallet-mcp] HTTP error:', err);
|
|
105
|
+
if (!res.headersSent) {
|
|
106
|
+
res.writeHead(500, { 'Content-Type': 'application/json; charset=utf-8' });
|
|
107
|
+
res.end(JSON.stringify({ error: err instanceof Error ? err.message : 'Internal server error' }));
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
res.writeHead(404, { 'Content-Type': 'application/json; charset=utf-8' });
|
|
113
|
+
res.end(JSON.stringify({ error: 'Not Found. Use / or /mcp for Streamable HTTP MCP.' }));
|
|
114
|
+
});
|
|
115
|
+
const host = process.env.HOST || '0.0.0.0';
|
|
116
|
+
httpServer.listen(port, host, () => {
|
|
117
|
+
console.log(`[tokenwallet-mcp] Streamable HTTP listening on http://${host}:${port}/mcp`);
|
|
118
|
+
console.log(`[tokenwallet-mcp] TokenWallet API: ${getApiBaseUrl()}`);
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
const { useHttp, port } = parseArgs();
|
|
122
|
+
if (useHttp) {
|
|
123
|
+
await startHttp(port);
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
await startStdio();
|
|
127
|
+
}
|
package/dist/server.js
ADDED
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
+
import QRCode from 'qrcode';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { apiCreateMcpSession, apiPingNode, apiPollMcpSession, apiSubmitReport, } from './api.js';
|
|
5
|
+
import { collectQuotaForBrand } from './collectors/index.js';
|
|
6
|
+
import { getApiBaseUrl, loadConfig, markConnectionReported, removePendingSession, savePendingSession, upsertBoundConnection, } from './config.js';
|
|
7
|
+
const meterSchema = z.object({
|
|
8
|
+
meterKey: z.string().min(1).describe('Unique meter key, e.g. "5h", "7d", "balance:USD"'),
|
|
9
|
+
product: z.string().optional().describe('Product identifier, e.g. "chatgpt", "codex", "claude-code"'),
|
|
10
|
+
label: z.string().min(1).describe('Human-readable label, e.g. "5 小时", "每周额度", "可用余额"'),
|
|
11
|
+
kind: z.enum(['percent', 'balance']).describe('"percent" for 0-100% quotas, "balance" for currency/credits'),
|
|
12
|
+
window: z.enum(['5h', 'day', 'week', 'month', 'rolling']).optional(),
|
|
13
|
+
modelGroup: z.string().optional(),
|
|
14
|
+
remaining: z.number().describe('Remaining amount or percentage (0-100)'),
|
|
15
|
+
total: z.number().optional().describe('Total quota if applicable (e.g. 100 for percent)'),
|
|
16
|
+
unit: z.string().optional().describe('Unit such as "%", "USD", "CNY", "credits"'),
|
|
17
|
+
resetsAt: z.number().optional().describe('Reset timestamp in epoch milliseconds'),
|
|
18
|
+
});
|
|
19
|
+
const activePollTimers = new Map();
|
|
20
|
+
async function tryPollPendingSession(session) {
|
|
21
|
+
const baseUrl = getApiBaseUrl();
|
|
22
|
+
try {
|
|
23
|
+
const res = await apiPollMcpSession(baseUrl, session.sessionId, session.pollToken);
|
|
24
|
+
if (res.status === 'authorized' && res.writeToken && res.cardId && res.nodeId) {
|
|
25
|
+
const bound = {
|
|
26
|
+
cardId: res.cardId,
|
|
27
|
+
nodeId: res.nodeId,
|
|
28
|
+
brand: session.brand,
|
|
29
|
+
provider: session.provider,
|
|
30
|
+
writeToken: res.writeToken,
|
|
31
|
+
fingerprintSalt: res.fingerprintSalt,
|
|
32
|
+
connectedAt: Date.now(),
|
|
33
|
+
};
|
|
34
|
+
upsertBoundConnection(bound);
|
|
35
|
+
removePendingSession(session.sessionId);
|
|
36
|
+
stopBackgroundPoll(session.sessionId);
|
|
37
|
+
return bound;
|
|
38
|
+
}
|
|
39
|
+
if (res.status === 'expired') {
|
|
40
|
+
removePendingSession(session.sessionId);
|
|
41
|
+
stopBackgroundPoll(session.sessionId);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
// Ignore transient network errors during background polling
|
|
46
|
+
}
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
function stopBackgroundPoll(sessionId) {
|
|
50
|
+
const timer = activePollTimers.get(sessionId);
|
|
51
|
+
if (timer) {
|
|
52
|
+
clearInterval(timer);
|
|
53
|
+
activePollTimers.delete(sessionId);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function startBackgroundPoll(session) {
|
|
57
|
+
stopBackgroundPoll(session.sessionId);
|
|
58
|
+
const timer = setInterval(() => {
|
|
59
|
+
if (Date.now() > session.expiresAt) {
|
|
60
|
+
removePendingSession(session.sessionId);
|
|
61
|
+
stopBackgroundPoll(session.sessionId);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
void tryPollPendingSession(session);
|
|
65
|
+
}, 3000);
|
|
66
|
+
timer.unref();
|
|
67
|
+
activePollTimers.set(session.sessionId, timer);
|
|
68
|
+
}
|
|
69
|
+
async function syncAllPendingSessions() {
|
|
70
|
+
const cfg = loadConfig();
|
|
71
|
+
const newlyBound = [];
|
|
72
|
+
for (const session of cfg.pendingSessions) {
|
|
73
|
+
const bound = await tryPollPendingSession(session);
|
|
74
|
+
if (bound)
|
|
75
|
+
newlyBound.push(bound);
|
|
76
|
+
}
|
|
77
|
+
return newlyBound;
|
|
78
|
+
}
|
|
79
|
+
export function createTokenWalletMcpServer() {
|
|
80
|
+
const server = new McpServer({
|
|
81
|
+
name: 'tokenwallet-mcp',
|
|
82
|
+
version: '1.0.0',
|
|
83
|
+
});
|
|
84
|
+
server.registerTool('connect_tokenwallet', {
|
|
85
|
+
title: 'Connect to TokenWallet App',
|
|
86
|
+
description: 'Generate a QR code and pairing link so the user can scan with the TokenWallet mobile app to bind this AI client and sync token quotas.',
|
|
87
|
+
inputSchema: {
|
|
88
|
+
brand: z
|
|
89
|
+
.enum(['openai', 'claude', 'gemini', 'cursor', 'grok', 'openrouter', 'deepseek', 'other'])
|
|
90
|
+
.default('openai')
|
|
91
|
+
.describe('Provider brand (openai, claude, gemini, cursor, grok, openrouter, deepseek, other)'),
|
|
92
|
+
provider: z.string().optional().describe('Custom display name for the provider'),
|
|
93
|
+
nodeLabel: z.string().optional().describe('Friendly name for this client/machine, e.g. "MacBook ChatGPT"'),
|
|
94
|
+
source: z.string().optional().describe('Client source identifier, e.g. "chatgpt", "codex", "claude-code", "cursor", "gemini-cli"'),
|
|
95
|
+
plan: z.string().optional().describe('Subscription plan name, e.g. "Plus", "Pro", "AI Pro"'),
|
|
96
|
+
accountHint: z.string().optional().describe('Optional masked account hint, e.g. "u***@gmail.com"'),
|
|
97
|
+
meters: z.array(meterSchema).optional().describe('Optional initial quota meters to populate immediately upon scan'),
|
|
98
|
+
},
|
|
99
|
+
}, async (args) => {
|
|
100
|
+
const baseUrl = getApiBaseUrl();
|
|
101
|
+
const localQuota = !args.meters || args.meters.length === 0
|
|
102
|
+
? await collectQuotaForBrand(args.brand)
|
|
103
|
+
: null;
|
|
104
|
+
const created = await apiCreateMcpSession(baseUrl, {
|
|
105
|
+
brand: args.brand,
|
|
106
|
+
provider: args.provider,
|
|
107
|
+
nodeLabel: args.nodeLabel,
|
|
108
|
+
source: args.source ?? localQuota?.source ?? 'mcp',
|
|
109
|
+
plan: args.plan ?? localQuota?.plan,
|
|
110
|
+
accountHint: args.accountHint ?? localQuota?.accountHint,
|
|
111
|
+
meters: args.meters ?? localQuota?.meters,
|
|
112
|
+
});
|
|
113
|
+
const pending = {
|
|
114
|
+
sessionId: created.sessionId,
|
|
115
|
+
mcpCode: created.mcpCode,
|
|
116
|
+
pollToken: created.pollToken,
|
|
117
|
+
brand: created.brand,
|
|
118
|
+
provider: created.provider,
|
|
119
|
+
deepLink: created.deepLink,
|
|
120
|
+
webLink: created.webLink,
|
|
121
|
+
expiresAt: created.expiresAt,
|
|
122
|
+
createdAt: Date.now(),
|
|
123
|
+
};
|
|
124
|
+
savePendingSession(pending);
|
|
125
|
+
startBackgroundPoll(pending);
|
|
126
|
+
const qrDataUrl = await QRCode.toDataURL(created.qrPayload, {
|
|
127
|
+
width: 320,
|
|
128
|
+
margin: 2,
|
|
129
|
+
});
|
|
130
|
+
const base64Png = qrDataUrl.replace(/^data:image\/png;base64,/, '');
|
|
131
|
+
const asciiQr = await QRCode.toString(created.qrPayload, { type: 'utf8' });
|
|
132
|
+
const expiresInMin = Math.max(1, Math.round((created.expiresAt - Date.now()) / 60_000));
|
|
133
|
+
const summary = [
|
|
134
|
+
`请打开 TokenWallet App,进入「添加卡片 → ${created.provider}」,点击「扫描二维码」扫描下方二维码即可完成连接(有效期约 ${expiresInMin} 分钟):`,
|
|
135
|
+
'',
|
|
136
|
+
`连接码:${created.mcpCode}`,
|
|
137
|
+
`手机直达链接:${created.deepLink}`,
|
|
138
|
+
`网页跳转链接:${created.webLink}`,
|
|
139
|
+
'',
|
|
140
|
+
'```',
|
|
141
|
+
asciiQr.trimEnd(),
|
|
142
|
+
'```',
|
|
143
|
+
'',
|
|
144
|
+
'扫码后本 MCP 会自动完成配对并保存只写上报凭证;也可以调用 `check_connection_status` 立即确认绑定状态。',
|
|
145
|
+
].join('\n');
|
|
146
|
+
return {
|
|
147
|
+
content: [
|
|
148
|
+
{
|
|
149
|
+
type: 'image',
|
|
150
|
+
data: base64Png,
|
|
151
|
+
mimeType: 'image/png',
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
type: 'text',
|
|
155
|
+
text: summary,
|
|
156
|
+
},
|
|
157
|
+
],
|
|
158
|
+
};
|
|
159
|
+
});
|
|
160
|
+
server.registerTool('check_connection_status', {
|
|
161
|
+
title: 'Check TokenWallet Connection Status',
|
|
162
|
+
description: 'Poll pending QR pairing sessions and report currently connected TokenWallet cards.',
|
|
163
|
+
inputSchema: {
|
|
164
|
+
sessionId: z.string().optional().describe('Optional specific pending sessionId to poll'),
|
|
165
|
+
},
|
|
166
|
+
}, async ({ sessionId }) => {
|
|
167
|
+
const cfg = loadConfig();
|
|
168
|
+
const targets = sessionId
|
|
169
|
+
? cfg.pendingSessions.filter((s) => s.sessionId === sessionId)
|
|
170
|
+
: cfg.pendingSessions;
|
|
171
|
+
const newlyBound = [];
|
|
172
|
+
for (const s of targets) {
|
|
173
|
+
const bound = await tryPollPendingSession(s);
|
|
174
|
+
if (bound)
|
|
175
|
+
newlyBound.push(bound);
|
|
176
|
+
}
|
|
177
|
+
const updated = loadConfig();
|
|
178
|
+
const lines = [];
|
|
179
|
+
if (newlyBound.length > 0) {
|
|
180
|
+
lines.push(`新完成绑定 ${newlyBound.length} 张卡片:`);
|
|
181
|
+
for (const c of newlyBound) {
|
|
182
|
+
lines.push(`- ${c.provider} (${c.brand}) · cardId=${c.cardId}`);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
else if (updated.pendingSessions.length > 0) {
|
|
186
|
+
lines.push(`仍有 ${updated.pendingSessions.length} 个等待扫码的会话(最新连接码:${updated.pendingSessions[0].mcpCode})。`);
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
lines.push('当前没有等待中的扫码会话。');
|
|
190
|
+
}
|
|
191
|
+
lines.push('');
|
|
192
|
+
lines.push(`已绑定卡片总数:${updated.connections.length}`);
|
|
193
|
+
for (const c of updated.connections) {
|
|
194
|
+
lines.push(`- ${c.provider} (${c.brand}) · cardId=${c.cardId}`);
|
|
195
|
+
}
|
|
196
|
+
return {
|
|
197
|
+
content: [{ type: 'text', text: lines.join('\n') }],
|
|
198
|
+
};
|
|
199
|
+
});
|
|
200
|
+
server.registerTool('report_quota', {
|
|
201
|
+
title: 'Report Quota to TokenWallet',
|
|
202
|
+
description: 'Push real-time remaining token quota or balance meters to a bound TokenWallet card.',
|
|
203
|
+
inputSchema: {
|
|
204
|
+
cardId: z.string().optional().describe('Target cardId (optional; defaults to matching brand or latest bound card)'),
|
|
205
|
+
brand: z.string().optional().describe('Brand filter when cardId is omitted, e.g. "openai", "claude"'),
|
|
206
|
+
plan: z.string().optional().describe('Optional updated plan name, e.g. "Plus", "Pro"'),
|
|
207
|
+
accountHint: z.string().optional().describe('Optional masked account hint'),
|
|
208
|
+
meters: z.array(meterSchema).min(1).describe('One or more quota meters to report'),
|
|
209
|
+
},
|
|
210
|
+
}, async (args) => {
|
|
211
|
+
await syncAllPendingSessions();
|
|
212
|
+
const cfg = loadConfig();
|
|
213
|
+
const conn = (args.cardId && cfg.connections.find((c) => c.cardId === args.cardId)) ||
|
|
214
|
+
(args.brand && cfg.connections.find((c) => c.brand === args.brand)) ||
|
|
215
|
+
cfg.connections[0];
|
|
216
|
+
if (!conn) {
|
|
217
|
+
return {
|
|
218
|
+
isError: true,
|
|
219
|
+
content: [
|
|
220
|
+
{
|
|
221
|
+
type: 'text',
|
|
222
|
+
text: '尚未绑定任何 TokenWallet 卡片。请先调用 `connect_tokenwallet` 生成二维码并在手机 App 中扫码绑定。',
|
|
223
|
+
},
|
|
224
|
+
],
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
const baseUrl = getApiBaseUrl();
|
|
228
|
+
const now = Date.now();
|
|
229
|
+
const res = await apiSubmitReport(baseUrl, conn.writeToken, {
|
|
230
|
+
plan: args.plan,
|
|
231
|
+
accountHint: args.accountHint,
|
|
232
|
+
observedAt: now,
|
|
233
|
+
meters: args.meters.map((m) => ({
|
|
234
|
+
...m,
|
|
235
|
+
observedAt: now,
|
|
236
|
+
})),
|
|
237
|
+
});
|
|
238
|
+
markConnectionReported(conn.cardId, now);
|
|
239
|
+
return {
|
|
240
|
+
content: [
|
|
241
|
+
{
|
|
242
|
+
type: 'text',
|
|
243
|
+
text: `已上报 ${conn.provider}(cardId=${res.cardId})最新额度,更新字段:${res.updatedMeters.join(', ') || '无'},服务端版本 rev=${res.revision}。`,
|
|
244
|
+
},
|
|
245
|
+
],
|
|
246
|
+
};
|
|
247
|
+
});
|
|
248
|
+
server.registerTool('sync_local_quotas', {
|
|
249
|
+
title: 'Sync Real Local AI Client Quotas',
|
|
250
|
+
description: 'Collect real-time remaining quotas from locally installed AI clients (Codex CLI, Claude Code, Cursor, Gemini CLI, Grok/xAI) and push updates to bound TokenWallet cards.',
|
|
251
|
+
inputSchema: {
|
|
252
|
+
brand: z
|
|
253
|
+
.enum(['openai', 'claude', 'cursor', 'gemini', 'grok'])
|
|
254
|
+
.optional()
|
|
255
|
+
.describe('Optional specific brand to sync; omit to sync all bound local providers'),
|
|
256
|
+
cardId: z.string().optional().describe('Optional specific bound cardId'),
|
|
257
|
+
},
|
|
258
|
+
}, async ({ brand, cardId }) => {
|
|
259
|
+
await syncAllPendingSessions();
|
|
260
|
+
const cfg = loadConfig();
|
|
261
|
+
const baseUrl = getApiBaseUrl();
|
|
262
|
+
const targetBrands = brand
|
|
263
|
+
? [brand]
|
|
264
|
+
: Array.from(new Set(cfg.connections.map((c) => c.brand)));
|
|
265
|
+
if (targetBrands.length === 0) {
|
|
266
|
+
return {
|
|
267
|
+
isError: true,
|
|
268
|
+
content: [
|
|
269
|
+
{
|
|
270
|
+
type: 'text',
|
|
271
|
+
text: '尚未绑定任何 TokenWallet 卡片。请先调用 connect_tokenwallet 生成二维码并在手机 App 中扫码绑定。',
|
|
272
|
+
},
|
|
273
|
+
],
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
const lines = [];
|
|
277
|
+
for (const b of targetBrands) {
|
|
278
|
+
const snapshot = await collectQuotaForBrand(b);
|
|
279
|
+
if (!snapshot) {
|
|
280
|
+
lines.push(`- ${b}: 未检测到本机可用额度数据源`);
|
|
281
|
+
continue;
|
|
282
|
+
}
|
|
283
|
+
const conn = (cardId && cfg.connections.find((c) => c.cardId === cardId)) ||
|
|
284
|
+
cfg.connections.find((c) => c.brand === b);
|
|
285
|
+
if (!conn) {
|
|
286
|
+
lines.push(`- ${b}: 已采集到真实额度(${snapshot.meters.map((m) => `${m.label} ${m.remaining}${m.unit ?? ''}`).join(',')}),但尚未绑定卡片`);
|
|
287
|
+
continue;
|
|
288
|
+
}
|
|
289
|
+
const res = await apiSubmitReport(baseUrl, conn.writeToken, {
|
|
290
|
+
plan: snapshot.plan,
|
|
291
|
+
accountHint: snapshot.accountHint,
|
|
292
|
+
observedAt: snapshot.observedAt,
|
|
293
|
+
meters: snapshot.meters,
|
|
294
|
+
});
|
|
295
|
+
markConnectionReported(conn.cardId, Date.now());
|
|
296
|
+
const summary = snapshot.meters
|
|
297
|
+
.map((m) => `${m.label} ${m.remaining}${m.unit ?? ''}`)
|
|
298
|
+
.join(',');
|
|
299
|
+
lines.push(`- ${conn.provider} (cardId=${res.cardId}): 已同步 ${summary}`);
|
|
300
|
+
}
|
|
301
|
+
return {
|
|
302
|
+
content: [{ type: 'text', text: lines.join('\n') }],
|
|
303
|
+
};
|
|
304
|
+
});
|
|
305
|
+
server.registerTool('list_connections', {
|
|
306
|
+
title: 'List Connected TokenWallet Cards',
|
|
307
|
+
description: 'List all locally bound TokenWallet cards and verify their node connectivity.',
|
|
308
|
+
inputSchema: {},
|
|
309
|
+
}, async () => {
|
|
310
|
+
await syncAllPendingSessions();
|
|
311
|
+
const cfg = loadConfig();
|
|
312
|
+
if (cfg.connections.length === 0) {
|
|
313
|
+
return {
|
|
314
|
+
content: [{ type: 'text', text: '当前没有已绑定的 TokenWallet 卡片。可调用 `connect_tokenwallet` 开始绑定。' }],
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
const baseUrl = getApiBaseUrl();
|
|
318
|
+
const lines = [`API 地址:${baseUrl}`, `已绑定卡片 (${cfg.connections.length}):`];
|
|
319
|
+
for (const conn of cfg.connections) {
|
|
320
|
+
let status = 'online';
|
|
321
|
+
try {
|
|
322
|
+
await apiPingNode(baseUrl, conn.writeToken);
|
|
323
|
+
}
|
|
324
|
+
catch (err) {
|
|
325
|
+
status = `error: ${err instanceof Error ? err.message : 'unreachable'}`;
|
|
326
|
+
}
|
|
327
|
+
lines.push(`- ${conn.provider} (${conn.brand}) · cardId=${conn.cardId} · 状态=${status}`);
|
|
328
|
+
}
|
|
329
|
+
return {
|
|
330
|
+
content: [{ type: 'text', text: lines.join('\n') }],
|
|
331
|
+
};
|
|
332
|
+
});
|
|
333
|
+
return server;
|
|
334
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,52 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tokenwallet-mcp",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "TokenWallet MCP Server for QR pairing and automatic real-time AI token quota syncing",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "dist/index.js",
|
|
8
|
+
"bin": {
|
|
9
|
+
"tokenwallet-mcp": "dist/index.js"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"dist",
|
|
13
|
+
"README.md"
|
|
14
|
+
],
|
|
15
|
+
"engines": {
|
|
16
|
+
"node": ">=18.0.0"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"mcp",
|
|
20
|
+
"model-context-protocol",
|
|
21
|
+
"tokenwallet",
|
|
22
|
+
"codex",
|
|
23
|
+
"chatgpt",
|
|
24
|
+
"claude",
|
|
25
|
+
"ai-quota"
|
|
26
|
+
],
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "https://github.com/token-wallet-app/mcp.git"
|
|
30
|
+
},
|
|
31
|
+
"homepage": "https://token-wallet.app",
|
|
32
|
+
"scripts": {
|
|
33
|
+
"dev": "tsx src/index.ts",
|
|
34
|
+
"dev:http": "tsx src/index.ts --http",
|
|
35
|
+
"build": "tsc",
|
|
36
|
+
"prepublishOnly": "npm run build",
|
|
37
|
+
"start": "node dist/index.js",
|
|
38
|
+
"start:http": "node dist/index.js --http",
|
|
39
|
+
"typecheck": "tsc --noEmit"
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"@modelcontextprotocol/sdk": "^1.25.2",
|
|
43
|
+
"qrcode": "^1.5.4",
|
|
44
|
+
"zod": "^3.25.76"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@types/node": "^22.15.0",
|
|
48
|
+
"@types/qrcode": "^1.5.5",
|
|
49
|
+
"tsx": "^4.19.4",
|
|
50
|
+
"typescript": "^5.8.3"
|
|
51
|
+
}
|
|
52
|
+
}
|