mcp-user-system 1.0.4 → 2.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 +173 -15
- package/dist/env.d.ts +1 -1
- package/dist/env.js +1 -1
- package/dist/env.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +50 -224
- package/dist/index.js.map +1 -1
- package/dist/tools/client.d.ts +19 -0
- package/dist/tools/client.js +118 -0
- package/dist/tools/client.js.map +1 -0
- package/dist/tools/dashboard.d.ts +149 -0
- package/dist/tools/dashboard.js +184 -0
- package/dist/tools/dashboard.js.map +1 -0
- package/dist/tools/invoice.d.ts +47 -0
- package/dist/tools/invoice.js +53 -0
- package/dist/tools/invoice.js.map +1 -0
- package/dist/tools/misc.d.ts +240 -0
- package/dist/tools/misc.js +189 -0
- package/dist/tools/misc.js.map +1 -0
- package/dist/tools/team.d.ts +157 -0
- package/dist/tools/team.js +198 -0
- package/dist/tools/team.js.map +1 -0
- package/dist/tools/tokens.d.ts +109 -0
- package/dist/tools/tokens.js +83 -0
- package/dist/tools/tokens.js.map +1 -0
- package/dist/tools/user.d.ts +25 -0
- package/dist/tools/user.js +60 -0
- package/dist/tools/user.js.map +1 -0
- package/dist/tools/wallet.d.ts +119 -94
- package/dist/tools/wallet.js +103 -86
- package/dist/tools/wallet.js.map +1 -1
- package/install.cjs +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
# mcp-user-system
|
|
2
2
|
|
|
3
|
-
[MCP](https://modelcontextprotocol.io) server for token-user-system —
|
|
3
|
+
[MCP](https://modelcontextprotocol.io) server for token-user-system — Console 前台全量查询接口 via Model Context Protocol.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Provides AI agents with authenticated access to the Console (前台) query APIs, covering user info, dashboard statistics, wallet, team management, token usage, invoices, and miscellaneous lookups.
|
|
6
|
+
|
|
7
|
+
Supports: user profiles, dashboard stats & trends, wallet overview, team & member management, token consumption, invoice queries, and more.
|
|
6
8
|
|
|
7
9
|
## Prerequisites
|
|
8
10
|
|
|
@@ -11,7 +13,13 @@ Supports: balance, consumption trend, transaction records, coupons, corporate tr
|
|
|
11
13
|
|
|
12
14
|
## Installation
|
|
13
15
|
|
|
14
|
-
### 1.
|
|
16
|
+
### 1. Install globally
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install -g mcp-user-system
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Or clone & build manually:
|
|
15
23
|
|
|
16
24
|
```bash
|
|
17
25
|
git clone https://github.com/shenda-ai/mcp-user-system.git
|
|
@@ -24,16 +32,18 @@ npm run build
|
|
|
24
32
|
|
|
25
33
|
```bash
|
|
26
34
|
export TUS_BASE_URL=https://api.example.com
|
|
27
|
-
export TUS_ACCESS_TOKEN=
|
|
35
|
+
export TUS_ACCESS_TOKEN=your-jwt-access-token
|
|
28
36
|
```
|
|
29
37
|
|
|
30
38
|
Or create a `.env` file (add to `.gitignore`):
|
|
31
39
|
|
|
32
40
|
```bash
|
|
33
41
|
TUS_BASE_URL=https://api.example.com
|
|
34
|
-
TUS_ACCESS_TOKEN=
|
|
42
|
+
TUS_ACCESS_TOKEN=your-jwt-access-token
|
|
35
43
|
```
|
|
36
44
|
|
|
45
|
+
> **Access Token** is a JWT Bearer Token obtained after user login. Include it as `Authorization: Bearer <token>` in upstream requests.
|
|
46
|
+
|
|
37
47
|
### 3. Test Run
|
|
38
48
|
|
|
39
49
|
```bash
|
|
@@ -54,7 +64,7 @@ Add to `~/Library/Application Support/Claude/claude_desktop_config.json`:
|
|
|
54
64
|
"args": ["/path/to/mcp-user-system/dist/index.js"],
|
|
55
65
|
"env": {
|
|
56
66
|
"TUS_BASE_URL": "https://api.example.com",
|
|
57
|
-
"TUS_ACCESS_TOKEN": "
|
|
67
|
+
"TUS_ACCESS_TOKEN": "your-jwt-access-token"
|
|
58
68
|
}
|
|
59
69
|
}
|
|
60
70
|
}
|
|
@@ -73,7 +83,7 @@ Add to settings (Cursor: `~/.cursor/mcp.json`, VS Code: settings.json):
|
|
|
73
83
|
"args": ["/path/to/mcp-user-system/dist/index.js"],
|
|
74
84
|
"env": {
|
|
75
85
|
"TUS_BASE_URL": "https://api.example.com",
|
|
76
|
-
"TUS_ACCESS_TOKEN": "
|
|
86
|
+
"TUS_ACCESS_TOKEN": "your-jwt-access-token"
|
|
77
87
|
}
|
|
78
88
|
}
|
|
79
89
|
}
|
|
@@ -92,7 +102,7 @@ Add to `~/.claude/mcp.json`:
|
|
|
92
102
|
"args": ["/path/to/mcp-user-system/dist/index.js"],
|
|
93
103
|
"env": {
|
|
94
104
|
"TUS_BASE_URL": "https://api.example.com",
|
|
95
|
-
"TUS_ACCESS_TOKEN": "
|
|
105
|
+
"TUS_ACCESS_TOKEN": "your-jwt-access-token"
|
|
96
106
|
}
|
|
97
107
|
}
|
|
98
108
|
}
|
|
@@ -101,13 +111,161 @@ Add to `~/.claude/mcp.json`:
|
|
|
101
111
|
|
|
102
112
|
## Available Tools
|
|
103
113
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
|
107
|
-
|
|
108
|
-
|
|
|
109
|
-
|
|
|
110
|
-
|
|
|
114
|
+
**62 tools** organized by domain:
|
|
115
|
+
|
|
116
|
+
| Domain | Count | Description |
|
|
117
|
+
|--------|-------|-------------|
|
|
118
|
+
| **user** | 6 | User profile, preferences, and account info |
|
|
119
|
+
| **dashboard** | 10 | Dashboard statistics, trends, rankings, model usage, member usage |
|
|
120
|
+
| **wallet** | 8 | Wallet overview, transactions, balance history, recharge records |
|
|
121
|
+
| **team** | 14 | Team/department management, member CRUD, role & permission queries |
|
|
122
|
+
| **tokens** | 6 | Token consumption details, usage aggregation, billing records |
|
|
123
|
+
| **invoice** | 4 | Invoice list, invoice detail, red-punch status queries |
|
|
124
|
+
| **misc** | 14 | Refund management, resource rules, alert settings, message center |
|
|
125
|
+
|
|
126
|
+
## Authentication
|
|
127
|
+
|
|
128
|
+
This MCP server uses **Access Token** (JWT Bearer Token) authentication. The token is obtained after user login and passed via the `TUS_ACCESS_TOKEN` environment variable. All upstream API requests include it as `Authorization: Bearer <token>`.
|
|
129
|
+
|
|
130
|
+
## Development
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
npm run dev # Watch mode
|
|
134
|
+
npm run build # Compile TypeScript
|
|
135
|
+
npm start # Run compiled server
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## License
|
|
139
|
+
|
|
140
|
+
MIT
|
|
141
|
+
# mcp-user-system
|
|
142
|
+
|
|
143
|
+
[MCP](https://modelcontextprotocol.io) server for token-user-system — Console 前台全量查询接口 via Model Context Protocol.
|
|
144
|
+
|
|
145
|
+
Provides AI agents with authenticated access to the Console (前台) query APIs, covering user info, dashboard statistics, wallet, team management, token usage, invoices, and miscellaneous lookups.
|
|
146
|
+
|
|
147
|
+
Supports: user profiles, dashboard stats & trends, wallet overview, team & member management, token consumption, invoice queries, and more.
|
|
148
|
+
|
|
149
|
+
## Prerequisites
|
|
150
|
+
|
|
151
|
+
- Node.js >= 18
|
|
152
|
+
- `TUS_BASE_URL` and `TUS_ACCESS_TOKEN` environment variables
|
|
153
|
+
|
|
154
|
+
## Installation
|
|
155
|
+
|
|
156
|
+
### 1. Install globally
|
|
157
|
+
|
|
158
|
+
```bash
|
|
159
|
+
npm install -g mcp-user-system
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
Or clone & build manually:
|
|
163
|
+
|
|
164
|
+
```bash
|
|
165
|
+
git clone https://github.com/shenda-ai/mcp-user-system.git
|
|
166
|
+
cd mcp-user-system
|
|
167
|
+
npm install
|
|
168
|
+
npm run build
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### 2. Configure Environment
|
|
172
|
+
|
|
173
|
+
```bash
|
|
174
|
+
export TUS_BASE_URL=https://api.example.com
|
|
175
|
+
export TUS_ACCESS_TOKEN=your-jwt-access-token
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
Or create a `.env` file (add to `.gitignore`):
|
|
179
|
+
|
|
180
|
+
```bash
|
|
181
|
+
TUS_BASE_URL=https://api.example.com
|
|
182
|
+
TUS_ACCESS_TOKEN=your-jwt-access-token
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
> **Access Token** is a JWT Bearer Token obtained after user login. Include it as `Authorization: Bearer <token>` in upstream requests.
|
|
186
|
+
|
|
187
|
+
### 3. Test Run
|
|
188
|
+
|
|
189
|
+
```bash
|
|
190
|
+
npm start
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
## MCP Client Configuration
|
|
194
|
+
|
|
195
|
+
### Claude Desktop (macOS)
|
|
196
|
+
|
|
197
|
+
Add to `~/Library/Application Support/Claude/claude_desktop_config.json`:
|
|
198
|
+
|
|
199
|
+
```json
|
|
200
|
+
{
|
|
201
|
+
"mcpServers": {
|
|
202
|
+
"user-system": {
|
|
203
|
+
"command": "node",
|
|
204
|
+
"args": ["/path/to/mcp-user-system/dist/index.js"],
|
|
205
|
+
"env": {
|
|
206
|
+
"TUS_BASE_URL": "https://api.example.com",
|
|
207
|
+
"TUS_ACCESS_TOKEN": "your-jwt-access-token"
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
### Cursor / VS Code
|
|
215
|
+
|
|
216
|
+
Add to settings (Cursor: `~/.cursor/mcp.json`, VS Code: settings.json):
|
|
217
|
+
|
|
218
|
+
```json
|
|
219
|
+
{
|
|
220
|
+
"mcpServers": {
|
|
221
|
+
"user-system": {
|
|
222
|
+
"command": "node",
|
|
223
|
+
"args": ["/path/to/mcp-user-system/dist/index.js"],
|
|
224
|
+
"env": {
|
|
225
|
+
"TUS_BASE_URL": "https://api.example.com",
|
|
226
|
+
"TUS_ACCESS_TOKEN": "your-jwt-access-token"
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
### Claude Code (CLI)
|
|
234
|
+
|
|
235
|
+
Add to `~/.claude/mcp.json`:
|
|
236
|
+
|
|
237
|
+
```json
|
|
238
|
+
{
|
|
239
|
+
"mcpServers": {
|
|
240
|
+
"user-system": {
|
|
241
|
+
"command": "node",
|
|
242
|
+
"args": ["/path/to/mcp-user-system/dist/index.js"],
|
|
243
|
+
"env": {
|
|
244
|
+
"TUS_BASE_URL": "https://api.example.com",
|
|
245
|
+
"TUS_ACCESS_TOKEN": "your-jwt-access-token"
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
## Available Tools
|
|
253
|
+
|
|
254
|
+
**62 tools** organized by domain:
|
|
255
|
+
|
|
256
|
+
| Domain | Count | Description |
|
|
257
|
+
|--------|-------|-------------|
|
|
258
|
+
| **user** | 6 | User profile, preferences, and account info |
|
|
259
|
+
| **dashboard** | 10 | Dashboard statistics, trends, rankings, model usage, member usage |
|
|
260
|
+
| **wallet** | 8 | Wallet overview, transactions, balance history, recharge records |
|
|
261
|
+
| **team** | 14 | Team/department management, member CRUD, role & permission queries |
|
|
262
|
+
| **tokens** | 6 | Token consumption details, usage aggregation, billing records |
|
|
263
|
+
| **invoice** | 4 | Invoice list, invoice detail, red-punch status queries |
|
|
264
|
+
| **misc** | 14 | Model list, announcements, notifications, system config, and other lookups |
|
|
265
|
+
|
|
266
|
+
## Authentication
|
|
267
|
+
|
|
268
|
+
This MCP server uses **Access Token** (JWT Bearer Token) authentication. The token is obtained after user login and passed via the `TUS_ACCESS_TOKEN` environment variable. All upstream API requests include it as `Authorization: Bearer <token>`.
|
|
111
269
|
|
|
112
270
|
## Development
|
|
113
271
|
|
package/dist/env.d.ts
CHANGED
package/dist/env.js
CHANGED
package/dist/env.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"env.js","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":"AAAA;;GAEG;AAOH,SAAS,UAAU,CAAC,IAAY;IAC9B,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAChC,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CAAC,0CAA0C,IAAI,EAAE,CAAC,CAAC;IACpE,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAM,UAAU,UAAU;IACxB,OAAO;QACL,OAAO,EAAE,UAAU,CAAC,cAAc,CAAC;QACnC,
|
|
1
|
+
{"version":3,"file":"env.js","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":"AAAA;;GAEG;AAOH,SAAS,UAAU,CAAC,IAAY;IAC9B,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAChC,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CAAC,0CAA0C,IAAI,EAAE,CAAC,CAAC;IACpE,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAM,UAAU,UAAU;IACxB,OAAO;QACL,OAAO,EAAE,UAAU,CAAC,cAAc,CAAC;QACnC,WAAW,EAAE,UAAU,CAAC,kBAAkB,CAAC;KAC5C,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* MCP Server for token-user-system
|
|
4
4
|
*
|
|
5
|
-
* Provides
|
|
6
|
-
*
|
|
5
|
+
* Provides tools via Model Context Protocol, organized by domain:
|
|
6
|
+
* user, dashboard, wallet, team, tokens, invoice, misc
|
|
7
7
|
*/
|
|
8
8
|
export {};
|
package/dist/index.js
CHANGED
|
@@ -2,252 +2,78 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* MCP Server for token-user-system
|
|
4
4
|
*
|
|
5
|
-
* Provides
|
|
6
|
-
*
|
|
5
|
+
* Provides tools via Model Context Protocol, organized by domain:
|
|
6
|
+
* user, dashboard, wallet, team, tokens, invoice, misc
|
|
7
7
|
*/
|
|
8
8
|
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
9
9
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
10
10
|
import { CallToolRequestSchema, ListToolsRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
|
|
11
|
-
import
|
|
11
|
+
import * as userTools from "./tools/user.js";
|
|
12
|
+
import * as dashboardTools from "./tools/dashboard.js";
|
|
13
|
+
import * as walletTools from "./tools/wallet.js";
|
|
14
|
+
import * as teamTools from "./tools/team.js";
|
|
15
|
+
import * as tokensTools from "./tools/tokens.js";
|
|
16
|
+
import * as invoiceTools from "./tools/invoice.js";
|
|
17
|
+
import * as miscTools from "./tools/misc.js";
|
|
18
|
+
// ── Merge all tool definitions ──
|
|
19
|
+
const allTools = [
|
|
20
|
+
...userTools.tools,
|
|
21
|
+
...dashboardTools.tools,
|
|
22
|
+
...walletTools.tools,
|
|
23
|
+
...teamTools.tools,
|
|
24
|
+
...tokensTools.tools,
|
|
25
|
+
...invoiceTools.tools,
|
|
26
|
+
...miscTools.tools,
|
|
27
|
+
];
|
|
12
28
|
// ── MCP Server Setup ──
|
|
13
29
|
const server = new Server({
|
|
14
30
|
name: "mcp-user-system",
|
|
15
|
-
version: "
|
|
31
|
+
version: "2.0.0",
|
|
16
32
|
}, {
|
|
17
33
|
capabilities: {
|
|
18
34
|
tools: {},
|
|
19
35
|
},
|
|
20
36
|
});
|
|
21
|
-
// ── Tool
|
|
22
|
-
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
name: "wallet_overview",
|
|
27
|
-
description: "Get account wallet overview (balance, usable balance, voucher, credit limit, pending amount)",
|
|
28
|
-
inputSchema: {
|
|
29
|
-
type: "object",
|
|
30
|
-
properties: {},
|
|
31
|
-
},
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
name: "dashboard_stats",
|
|
35
|
-
description: "Get dashboard statistics (used quota, consumption, request count, active users, etc.)",
|
|
36
|
-
inputSchema: {
|
|
37
|
-
type: "object",
|
|
38
|
-
properties: {
|
|
39
|
-
timeRange: {
|
|
40
|
-
type: "string",
|
|
41
|
-
description: "Time range: 0=custom, 1=last 3 days, 2=last week, 3=last month, 4=this month, 5=last year, 6=today, 7=this week, 8=this year (default: 1)",
|
|
42
|
-
},
|
|
43
|
-
startDate: {
|
|
44
|
-
type: "string",
|
|
45
|
-
description: "Custom start date (yyyy-MM-dd, required when timeRange=0)",
|
|
46
|
-
},
|
|
47
|
-
endDate: {
|
|
48
|
-
type: "string",
|
|
49
|
-
description: "Custom end date (yyyy-MM-dd, required when timeRange=0)",
|
|
50
|
-
},
|
|
51
|
-
},
|
|
52
|
-
},
|
|
53
|
-
},
|
|
54
|
-
{
|
|
55
|
-
name: "dashboard_orders",
|
|
56
|
-
description: "List API call detail records with optional filters",
|
|
57
|
-
inputSchema: {
|
|
58
|
-
type: "object",
|
|
59
|
-
properties: {
|
|
60
|
-
timeRange: {
|
|
61
|
-
type: "string",
|
|
62
|
-
description: "Time range: 0=custom, 1=last 3 days, 2=last week, 3=last month, 4=this month, 5=last year, 6=today, 7=this week, 8=this year (default: 1)",
|
|
63
|
-
},
|
|
64
|
-
startDate: {
|
|
65
|
-
type: "string",
|
|
66
|
-
description: "Custom start date (yyyy-MM-dd)",
|
|
67
|
-
},
|
|
68
|
-
endDate: {
|
|
69
|
-
type: "string",
|
|
70
|
-
description: "Custom end date (yyyy-MM-dd)",
|
|
71
|
-
},
|
|
72
|
-
type: {
|
|
73
|
-
type: "string",
|
|
74
|
-
description: "Bill type filter",
|
|
75
|
-
},
|
|
76
|
-
keyword: {
|
|
77
|
-
type: "string",
|
|
78
|
-
description: "Keyword filter (matches user name or team nickname)",
|
|
79
|
-
},
|
|
80
|
-
},
|
|
81
|
-
},
|
|
82
|
-
},
|
|
83
|
-
{
|
|
84
|
-
name: "dashboard_users",
|
|
85
|
-
description: "Get user dropdown options for dashboard filtering",
|
|
86
|
-
inputSchema: {
|
|
87
|
-
type: "object",
|
|
88
|
-
properties: {
|
|
89
|
-
deptId: {
|
|
90
|
-
type: "string",
|
|
91
|
-
description: "Department ID to filter users",
|
|
92
|
-
},
|
|
93
|
-
},
|
|
94
|
-
},
|
|
95
|
-
},
|
|
96
|
-
{
|
|
97
|
-
name: "dashboard_model_stats",
|
|
98
|
-
description: "Get model usage statistics (call count, token consumption, cost, etc.)",
|
|
99
|
-
inputSchema: {
|
|
100
|
-
type: "object",
|
|
101
|
-
properties: {
|
|
102
|
-
timeRange: {
|
|
103
|
-
type: "string",
|
|
104
|
-
description: "Time range: 0=custom, 1=last 3 days, 2=last week, 3=last month, 4=this month, 5=last year, 6=today, 7=this week, 8=this year (default: 1)",
|
|
105
|
-
},
|
|
106
|
-
startDate: {
|
|
107
|
-
type: "string",
|
|
108
|
-
description: "Custom start date (yyyy-MM-dd)",
|
|
109
|
-
},
|
|
110
|
-
endDate: {
|
|
111
|
-
type: "string",
|
|
112
|
-
description: "Custom end date (yyyy-MM-dd)",
|
|
113
|
-
},
|
|
114
|
-
sortBy: {
|
|
115
|
-
type: "string",
|
|
116
|
-
description: "Sort by: 'token' or 'amount' (default: amount)",
|
|
117
|
-
},
|
|
118
|
-
},
|
|
119
|
-
},
|
|
120
|
-
},
|
|
121
|
-
{
|
|
122
|
-
name: "dashboard_trend",
|
|
123
|
-
description: "Get consumption trend data over time",
|
|
124
|
-
inputSchema: {
|
|
125
|
-
type: "object",
|
|
126
|
-
properties: {
|
|
127
|
-
timeRange: {
|
|
128
|
-
type: "string",
|
|
129
|
-
description: "Time range: 0=custom, 1=last 3 days, 2=last week, 3=last month, 4=this month, 5=last year, 6=today, 7=this week, 8=this year (default: 1)",
|
|
130
|
-
},
|
|
131
|
-
startDate: {
|
|
132
|
-
type: "string",
|
|
133
|
-
description: "Custom start date (yyyy-MM-dd)",
|
|
134
|
-
},
|
|
135
|
-
endDate: {
|
|
136
|
-
type: "string",
|
|
137
|
-
description: "Custom end date (yyyy-MM-dd)",
|
|
138
|
-
},
|
|
139
|
-
},
|
|
140
|
-
},
|
|
141
|
-
},
|
|
142
|
-
],
|
|
143
|
-
};
|
|
144
|
-
});
|
|
145
|
-
// ── Tool Handlers ──
|
|
37
|
+
// ── Tool List Handler ──
|
|
38
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
39
|
+
tools: allTools,
|
|
40
|
+
}));
|
|
41
|
+
// ── Tool Call Router ──
|
|
146
42
|
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
147
43
|
const { name, arguments: args } = request.params;
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
startDate: args?.startDate || undefined,
|
|
165
|
-
endDate: args?.endDate || undefined,
|
|
166
|
-
});
|
|
167
|
-
return {
|
|
168
|
-
content: [
|
|
169
|
-
{
|
|
170
|
-
type: "text",
|
|
171
|
-
text: JSON.stringify(data, null, 2),
|
|
172
|
-
},
|
|
173
|
-
],
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
case "dashboard_orders": {
|
|
177
|
-
const data = await getDashboardOrders({
|
|
178
|
-
timeRange: args?.timeRange || undefined,
|
|
179
|
-
startDate: args?.startDate || undefined,
|
|
180
|
-
endDate: args?.endDate || undefined,
|
|
181
|
-
type: args?.type || undefined,
|
|
182
|
-
keyword: args?.keyword || undefined,
|
|
183
|
-
});
|
|
44
|
+
const parsedArgs = (args ?? {});
|
|
45
|
+
// 构建域路由映射
|
|
46
|
+
const domains = [
|
|
47
|
+
{ names: userTools.tools.map((t) => t.name), handler: userTools.handle },
|
|
48
|
+
{ names: dashboardTools.tools.map((t) => t.name), handler: dashboardTools.handle },
|
|
49
|
+
{ names: walletTools.tools.map((t) => t.name), handler: walletTools.handle },
|
|
50
|
+
{ names: teamTools.tools.map((t) => t.name), handler: teamTools.handle },
|
|
51
|
+
{ names: tokensTools.tools.map((t) => t.name), handler: tokensTools.handle },
|
|
52
|
+
{ names: invoiceTools.tools.map((t) => t.name), handler: invoiceTools.handle },
|
|
53
|
+
{ names: miscTools.tools.map((t) => t.name), handler: miscTools.handle },
|
|
54
|
+
];
|
|
55
|
+
// 找到匹配的域并执行
|
|
56
|
+
for (const domain of domains) {
|
|
57
|
+
if (domain.names.includes(name)) {
|
|
58
|
+
try {
|
|
59
|
+
const data = await domain.handler(name, parsedArgs);
|
|
184
60
|
return {
|
|
185
|
-
content: [
|
|
186
|
-
{
|
|
187
|
-
type: "text",
|
|
188
|
-
text: JSON.stringify(data, null, 2),
|
|
189
|
-
},
|
|
190
|
-
],
|
|
61
|
+
content: [{ type: "text", text: JSON.stringify(data, null, 2) }],
|
|
191
62
|
};
|
|
192
63
|
}
|
|
193
|
-
|
|
194
|
-
const
|
|
64
|
+
catch (err) {
|
|
65
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
195
66
|
return {
|
|
196
|
-
content: [
|
|
197
|
-
|
|
198
|
-
type: "text",
|
|
199
|
-
text: JSON.stringify(data, null, 2),
|
|
200
|
-
},
|
|
201
|
-
],
|
|
67
|
+
content: [{ type: "text", text: `Error: ${message}` }],
|
|
68
|
+
isError: true,
|
|
202
69
|
};
|
|
203
70
|
}
|
|
204
|
-
case "dashboard_model_stats": {
|
|
205
|
-
const data = await getDashboardModelStats({
|
|
206
|
-
timeRange: args?.timeRange || undefined,
|
|
207
|
-
startDate: args?.startDate || undefined,
|
|
208
|
-
endDate: args?.endDate || undefined,
|
|
209
|
-
sortBy: args?.sortBy || undefined,
|
|
210
|
-
});
|
|
211
|
-
return {
|
|
212
|
-
content: [
|
|
213
|
-
{
|
|
214
|
-
type: "text",
|
|
215
|
-
text: JSON.stringify(data, null, 2),
|
|
216
|
-
},
|
|
217
|
-
],
|
|
218
|
-
};
|
|
219
|
-
}
|
|
220
|
-
case "dashboard_trend": {
|
|
221
|
-
const data = await getDashboardTrend({
|
|
222
|
-
timeRange: args?.timeRange || undefined,
|
|
223
|
-
startDate: args?.startDate || undefined,
|
|
224
|
-
endDate: args?.endDate || undefined,
|
|
225
|
-
});
|
|
226
|
-
return {
|
|
227
|
-
content: [
|
|
228
|
-
{
|
|
229
|
-
type: "text",
|
|
230
|
-
text: JSON.stringify(data, null, 2),
|
|
231
|
-
},
|
|
232
|
-
],
|
|
233
|
-
};
|
|
234
|
-
}
|
|
235
|
-
default:
|
|
236
|
-
throw new Error(`Unknown tool: ${name}`);
|
|
237
71
|
}
|
|
238
72
|
}
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
{
|
|
244
|
-
type: "text",
|
|
245
|
-
text: `Error: ${message}`,
|
|
246
|
-
},
|
|
247
|
-
],
|
|
248
|
-
isError: true,
|
|
249
|
-
};
|
|
250
|
-
}
|
|
73
|
+
return {
|
|
74
|
+
content: [{ type: "text", text: `Unknown tool: ${name}` }],
|
|
75
|
+
isError: true,
|
|
76
|
+
};
|
|
251
77
|
});
|
|
252
78
|
// ── Start Server ──
|
|
253
79
|
async function main() {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA;;;;;GAKG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EACL,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,oCAAoC,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA;;;;;GAKG;AAEH,OAAO,EAAE,M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,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
interface TableDataInfo<T = unknown> {
|
|
2
|
+
code: number;
|
|
3
|
+
msg: string;
|
|
4
|
+
total: number;
|
|
5
|
+
rows: T[];
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* 发起 GET 请求
|
|
9
|
+
*/
|
|
10
|
+
export declare function apiGet<T = unknown>(path: string, params?: Record<string, string | undefined>): Promise<T>;
|
|
11
|
+
/**
|
|
12
|
+
* 发起 GET 请求,返回分页数据(TableDataInfo 格式)
|
|
13
|
+
*/
|
|
14
|
+
export declare function apiGetPage<T = unknown>(path: string, params?: Record<string, string | undefined>): Promise<TableDataInfo<T>>;
|
|
15
|
+
/**
|
|
16
|
+
* 发起 POST 请求
|
|
17
|
+
*/
|
|
18
|
+
export declare function apiPost<T = unknown>(path: string, body?: unknown): Promise<T>;
|
|
19
|
+
export {};
|