tokenwallet-mcp 1.0.3 → 1.0.4
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 +2 -2
- package/dist/server.js +36 -13
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -52,7 +52,7 @@ Add to your user or workspace `.vscode/mcp.json`:
|
|
|
52
52
|
## Quick Start
|
|
53
53
|
|
|
54
54
|
1. After installation, start a conversation in your AI client and say:
|
|
55
|
-
**"Connect to TokenWallet"
|
|
55
|
+
**"Connect to TokenWallet"**. The reply includes a scannable QR code, a clickable pairing page, and an 8-character pairing code. If your client cannot display images, open the pairing page to see the QR code beneath the code. Clients with MCP prompt support can also use `connect_tokenwallet`.
|
|
56
56
|
2. Open the **TokenWallet** app on your phone, tap **+** → select the platform → **Scan QR Code** (or enter the 8-character pairing code manually).
|
|
57
57
|
3. After pairing, view your quota in TokenWallet.
|
|
58
58
|
|
|
@@ -114,7 +114,7 @@ claude mcp add tokenwallet -- npx -y --prefer-online tokenwallet-mcp@latest --pr
|
|
|
114
114
|
### 快速开始
|
|
115
115
|
|
|
116
116
|
1. 安装完成后,在 AI 客户端对话中输入:
|
|
117
|
-
**「帮我连接 TokenWallet
|
|
117
|
+
**「帮我连接 TokenWallet」**。回复会显示二维码、可点击的配对链接和 8 位配对码。客户端如果无法显示图片,打开配对链接即可在配对码下方看到二维码。支持 MCP 提示词的客户端也可以使用 `connect_tokenwallet`。
|
|
118
118
|
2. 打开手机上的 **词元钱包(TokenWallet)** App,点击右上角 **+** → 选择对应平台 → **扫描二维码**(若无法扫码可手动输入 8 位配对码)。
|
|
119
119
|
3. 配对完成后,在词元钱包中查看额度。
|
|
120
120
|
|
package/dist/server.js
CHANGED
|
@@ -12,6 +12,11 @@ const sourceHelp = {
|
|
|
12
12
|
xai: '检查 XAI_MANAGEMENT_API_KEY 的账单权限和 XAI_TEAM_ID。',
|
|
13
13
|
other: '自定义卡片由客户端从额度来源读取余量,再调用 report_quota 上报。可在客户端配置定时任务或用量事件来触发。',
|
|
14
14
|
};
|
|
15
|
+
const pairingInstructions = [
|
|
16
|
+
'When the user asks to connect or pair TokenWallet, including “帮我连接TokenWallet” or “连接词元钱包”, call connect_tokenwallet immediately using the configured provider. Ask for the provider only if it cannot be resolved.',
|
|
17
|
+
'After a successful call, show all three in the same reply: a visible scannable QR image, the clickable HTTPS pairing page, and the 8-character pairing code. Display the returned PNG or use the provided Markdown image URL. If the client cannot render images, keep the pairing page link and code visible and tell the user that the page shows the QR code directly below the code.',
|
|
18
|
+
'Ask the user to scan the QR code in TokenWallet or enter the code manually. Use only the actual values returned by the tool. If the tool returns an error, show its recovery steps.',
|
|
19
|
+
].join(' ');
|
|
15
20
|
const meterSchema = z.object({
|
|
16
21
|
meterKey: z.string().min(1).describe('Unique meter key, e.g. "5h", "7d", "balance:USD"'),
|
|
17
22
|
product: z.string().optional().describe('Product identifier, e.g. "chatgpt", "codex", "claude-code"'),
|
|
@@ -96,7 +101,7 @@ export function createTokenWalletMcpServer(onProviderReady) {
|
|
|
96
101
|
const server = new McpServer({
|
|
97
102
|
name: 'tokenwallet-mcp',
|
|
98
103
|
version: packageVersion,
|
|
99
|
-
}, { capabilities: { logging: {} } });
|
|
104
|
+
}, { capabilities: { logging: {} }, instructions: pairingInstructions });
|
|
100
105
|
const providerInput = (configured ? z.literal(configured) : z.enum(providerIds)).optional()
|
|
101
106
|
.describe('Provider for this instance. Required only when the client cannot be identified automatically.');
|
|
102
107
|
const getProvider = (requested) => {
|
|
@@ -133,9 +138,22 @@ export function createTokenWalletMcpServer(onProviderReady) {
|
|
|
133
138
|
title: 'Update TokenWallet MCP',
|
|
134
139
|
description: 'Upgrade the existing TokenWallet MCP without pinning a version, preserving provider and connection settings.',
|
|
135
140
|
}, () => ({ messages: [{ role: 'user', content: { type: 'text', text: updatePrompt } }] }));
|
|
141
|
+
server.registerPrompt('connect_tokenwallet', {
|
|
142
|
+
title: 'Connect TokenWallet / 连接词元钱包',
|
|
143
|
+
description: 'Create a pairing session and show its QR code, clickable pairing page, and 8-character code.',
|
|
144
|
+
}, () => ({
|
|
145
|
+
messages: [{ role: 'user', content: { type: 'text', text: pairingInstructions } }],
|
|
146
|
+
}));
|
|
136
147
|
server.registerTool('connect_tokenwallet', {
|
|
137
148
|
title: 'Connect to TokenWallet App',
|
|
138
|
-
description:
|
|
149
|
+
description: pairingInstructions,
|
|
150
|
+
outputSchema: {
|
|
151
|
+
pairingCode: z.string(),
|
|
152
|
+
pairingUrl: z.string().url(),
|
|
153
|
+
qrImageUrl: z.string().url(),
|
|
154
|
+
deepLink: z.string().url(),
|
|
155
|
+
expiresAt: z.number(),
|
|
156
|
+
},
|
|
139
157
|
inputSchema: {
|
|
140
158
|
provider: providerInput,
|
|
141
159
|
displayName: z.string().optional().describe('Optional card display name'),
|
|
@@ -180,31 +198,36 @@ export function createTokenWalletMcpServer(onProviderReady) {
|
|
|
180
198
|
startBackgroundPoll(pending, provider);
|
|
181
199
|
const qrDataUrl = await QRCode.toDataURL(created.qrPayload, {
|
|
182
200
|
width: 320,
|
|
183
|
-
margin:
|
|
201
|
+
margin: 4,
|
|
184
202
|
});
|
|
185
203
|
const base64Png = qrDataUrl.replace(/^data:image\/png;base64,/, '');
|
|
186
|
-
const
|
|
204
|
+
const qrImage = new URL('/connect/qr', created.webLink);
|
|
205
|
+
qrImage.search = new URLSearchParams({ provider: created.provider, code: created.code }).toString();
|
|
206
|
+
const qrImageUrl = qrImage.href;
|
|
187
207
|
const expiresInMin = Math.max(1, Math.round((created.expiresAt - Date.now()) / 60_000));
|
|
188
208
|
const cardLabel = provider === 'other' ? '自定义卡片' : created.displayName;
|
|
189
209
|
const update = await updateCheck;
|
|
190
210
|
const summary = [
|
|
191
|
-
|
|
192
|
-
'',
|
|
193
|
-
`连接码:${created.code}`,
|
|
194
|
-
`手机直达链接:${created.deepLink}`,
|
|
195
|
-
`网页跳转链接:${created.webLink}`,
|
|
211
|
+
`请在 TokenWallet App 中打开「添加卡片 → ${cardLabel} → 扫描二维码」,或手动输入配对码。有效期约 ${expiresInMin} 分钟。`,
|
|
196
212
|
'',
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
213
|
+
``,
|
|
214
|
+
`[打开 TokenWallet 配对页面](${created.webLink})`,
|
|
215
|
+
`配对码:${created.code}`,
|
|
200
216
|
'',
|
|
201
217
|
provider === 'other' || (!localQuota && !args.meters?.length)
|
|
202
218
|
? sourceHelp[provider] ?? '等待首次额度上报。'
|
|
203
219
|
: '',
|
|
204
|
-
'
|
|
220
|
+
'配对页面在配对码下方也会显示二维码。扫码或输入配对码后,可调用 `check_connection_status` 确认连接。',
|
|
205
221
|
...(update.updateAvailable ? ['', describeUpdate(update)] : []),
|
|
206
222
|
].join('\n');
|
|
207
223
|
return {
|
|
224
|
+
structuredContent: {
|
|
225
|
+
pairingCode: created.code,
|
|
226
|
+
pairingUrl: created.webLink,
|
|
227
|
+
qrImageUrl,
|
|
228
|
+
deepLink: created.deepLink,
|
|
229
|
+
expiresAt: created.expiresAt,
|
|
230
|
+
},
|
|
208
231
|
content: [
|
|
209
232
|
{
|
|
210
233
|
type: 'image',
|