@scorehub/mcp-server 0.1.3 → 0.1.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/dist/index.js +11 -27
- package/package.json +10 -3
package/dist/index.js
CHANGED
|
@@ -21,17 +21,7 @@ const AUTHORIZE_URL = `${REMOTE_MCP_URL}/authorize`;
|
|
|
21
21
|
const auth_js_1 = require("./auth.js");
|
|
22
22
|
const node_child_process_1 = require("node:child_process");
|
|
23
23
|
const HOST = new URL(REMOTE_MCP_URL).host;
|
|
24
|
-
|
|
25
|
-
function getStoredToken() {
|
|
26
|
-
if (cachedToken)
|
|
27
|
-
return cachedToken;
|
|
28
|
-
const t = (0, auth_js_1.loadTokens)(HOST);
|
|
29
|
-
if (t?.access_token && t.expires_at > Date.now() + 60_000) {
|
|
30
|
-
cachedToken = t.access_token;
|
|
31
|
-
return cachedToken;
|
|
32
|
-
}
|
|
33
|
-
return null;
|
|
34
|
-
}
|
|
24
|
+
const CLIENT_ID = "scorehub-mcp";
|
|
35
25
|
// ── Remote Tool Proxy ───────────────────────────────────────
|
|
36
26
|
async function fetchRemoteTools() {
|
|
37
27
|
try {
|
|
@@ -46,7 +36,7 @@ async function fetchRemoteTools() {
|
|
|
46
36
|
return [];
|
|
47
37
|
}
|
|
48
38
|
}
|
|
49
|
-
async function callRemoteTool(name, args) {
|
|
39
|
+
async function callRemoteTool(name, args, token) {
|
|
50
40
|
// Map tool names to remote endpoints
|
|
51
41
|
const toolEndpoints = {
|
|
52
42
|
search_creators: "/mcp/tools/search-creators",
|
|
@@ -63,7 +53,7 @@ async function callRemoteTool(name, args) {
|
|
|
63
53
|
method: "POST",
|
|
64
54
|
headers: {
|
|
65
55
|
"Content-Type": "application/json",
|
|
66
|
-
...(
|
|
56
|
+
...(token ? { Authorization: `Bearer ${token}` } : {}),
|
|
67
57
|
},
|
|
68
58
|
body: JSON.stringify(args),
|
|
69
59
|
});
|
|
@@ -117,12 +107,8 @@ server.setRequestHandler(types_js_1.CallToolRequestSchema, async (request) => {
|
|
|
117
107
|
const { name, arguments: args = {} } = request.params;
|
|
118
108
|
switch (name) {
|
|
119
109
|
case "authorize": {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
return {
|
|
123
|
-
content: [{ type: "text", text: "✅ 已授权,可直接使用工具。" }],
|
|
124
|
-
};
|
|
125
|
-
}
|
|
110
|
+
// Always force fresh OAuth flow when user explicitly authorizes
|
|
111
|
+
(0, auth_js_1.clearTokens)(HOST);
|
|
126
112
|
const authUrl = generateAuthUrl();
|
|
127
113
|
const os = process.platform;
|
|
128
114
|
const cmd = os === "darwin" ? "open" : os === "win32" ? "start" : "xdg-open";
|
|
@@ -152,7 +138,6 @@ server.setRequestHandler(types_js_1.CallToolRequestSchema, async (request) => {
|
|
|
152
138
|
expires_at: Date.now() + (tokenData.expires_in ?? 3600) * 1000,
|
|
153
139
|
updated_at: new Date().toISOString(),
|
|
154
140
|
});
|
|
155
|
-
cachedToken = tokenData.access_token;
|
|
156
141
|
return {
|
|
157
142
|
content: [{ type: "text", text: "✅ 授权成功!可以开始使用工具了。" }],
|
|
158
143
|
};
|
|
@@ -164,14 +149,14 @@ server.setRequestHandler(types_js_1.CallToolRequestSchema, async (request) => {
|
|
|
164
149
|
}
|
|
165
150
|
}
|
|
166
151
|
case "status": {
|
|
167
|
-
const
|
|
152
|
+
const tokenResult = await (0, auth_js_1.getValidAccessToken)(HOST, TOKEN_ENDPOINT, CLIENT_ID);
|
|
168
153
|
return {
|
|
169
154
|
content: [
|
|
170
155
|
{
|
|
171
156
|
type: "text",
|
|
172
157
|
text: JSON.stringify({
|
|
173
158
|
remote_url: REMOTE_MCP_URL,
|
|
174
|
-
authorized: !!
|
|
159
|
+
authorized: !!tokenResult,
|
|
175
160
|
tools_count: remoteTools.length,
|
|
176
161
|
}, null, 2),
|
|
177
162
|
},
|
|
@@ -179,10 +164,9 @@ server.setRequestHandler(types_js_1.CallToolRequestSchema, async (request) => {
|
|
|
179
164
|
};
|
|
180
165
|
}
|
|
181
166
|
default: {
|
|
182
|
-
// Check authorization for remote tools
|
|
183
|
-
const
|
|
184
|
-
|
|
185
|
-
if (!cachedToken) {
|
|
167
|
+
// Check authorization for remote tools — re-validates on every call
|
|
168
|
+
const tokenResult = await (0, auth_js_1.getValidAccessToken)(HOST, TOKEN_ENDPOINT, CLIENT_ID);
|
|
169
|
+
if (!tokenResult) {
|
|
186
170
|
const authUrl = generateAuthUrl();
|
|
187
171
|
return {
|
|
188
172
|
content: [
|
|
@@ -194,7 +178,7 @@ server.setRequestHandler(types_js_1.CallToolRequestSchema, async (request) => {
|
|
|
194
178
|
};
|
|
195
179
|
}
|
|
196
180
|
try {
|
|
197
|
-
const result = await callRemoteTool(name, args);
|
|
181
|
+
const result = await callRemoteTool(name, args, tokenResult.access_token);
|
|
198
182
|
return { content: [{ type: "text", text: result }] };
|
|
199
183
|
}
|
|
200
184
|
catch (e) {
|
package/package.json
CHANGED
|
@@ -1,18 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scorehub/mcp-server",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "ScoreHub local MCP proxy — OAuth login, token caching, and tool forwarding to remote MCP endpoint",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|
|
7
7
|
"scorehub-mcp": "./dist/index.js"
|
|
8
8
|
},
|
|
9
|
-
"files": [
|
|
9
|
+
"files": [
|
|
10
|
+
"dist"
|
|
11
|
+
],
|
|
10
12
|
"scripts": {
|
|
11
13
|
"build": "tsc && node -e \"const fs=require('fs');const f='dist/index.js';fs.writeFileSync(f,'#!/usr/bin/env node\\n'+fs.readFileSync(f,'utf8'));fs.chmodSync(f,0o755)\"",
|
|
12
14
|
"dev": "tsx src/index.ts",
|
|
13
15
|
"start": "node dist/index.js"
|
|
14
16
|
},
|
|
15
|
-
"keywords": [
|
|
17
|
+
"keywords": [
|
|
18
|
+
"mcp",
|
|
19
|
+
"scorehub",
|
|
20
|
+
"tiktok",
|
|
21
|
+
"oauth"
|
|
22
|
+
],
|
|
16
23
|
"license": "MIT",
|
|
17
24
|
"dependencies": {
|
|
18
25
|
"@modelcontextprotocol/sdk": "^1.29.0"
|