@scorehub/mcp-server 0.1.2 → 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.
Files changed (2) hide show
  1. package/dist/index.js +12 -27
  2. 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
- let cachedToken = null;
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,13 +36,14 @@ 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",
53
43
  creator_performance: "/mcp/tools/creator-performance",
54
44
  create_conversation: "/mcp/tools/create-conversation",
55
45
  send_message: "/mcp/tools/send-message",
46
+ get_categories: "/mcp/tools/get-categories",
56
47
  };
57
48
  const endpoint = toolEndpoints[name];
58
49
  if (!endpoint) {
@@ -62,7 +53,7 @@ async function callRemoteTool(name, args) {
62
53
  method: "POST",
63
54
  headers: {
64
55
  "Content-Type": "application/json",
65
- ...(cachedToken ? { Authorization: `Bearer ${cachedToken}` } : {}),
56
+ ...(token ? { Authorization: `Bearer ${token}` } : {}),
66
57
  },
67
58
  body: JSON.stringify(args),
68
59
  });
@@ -116,12 +107,8 @@ server.setRequestHandler(types_js_1.CallToolRequestSchema, async (request) => {
116
107
  const { name, arguments: args = {} } = request.params;
117
108
  switch (name) {
118
109
  case "authorize": {
119
- const existing = getStoredToken();
120
- if (existing) {
121
- return {
122
- content: [{ type: "text", text: "✅ 已授权,可直接使用工具。" }],
123
- };
124
- }
110
+ // Always force fresh OAuth flow when user explicitly authorizes
111
+ (0, auth_js_1.clearTokens)(HOST);
125
112
  const authUrl = generateAuthUrl();
126
113
  const os = process.platform;
127
114
  const cmd = os === "darwin" ? "open" : os === "win32" ? "start" : "xdg-open";
@@ -151,7 +138,6 @@ server.setRequestHandler(types_js_1.CallToolRequestSchema, async (request) => {
151
138
  expires_at: Date.now() + (tokenData.expires_in ?? 3600) * 1000,
152
139
  updated_at: new Date().toISOString(),
153
140
  });
154
- cachedToken = tokenData.access_token;
155
141
  return {
156
142
  content: [{ type: "text", text: "✅ 授权成功!可以开始使用工具了。" }],
157
143
  };
@@ -163,14 +149,14 @@ server.setRequestHandler(types_js_1.CallToolRequestSchema, async (request) => {
163
149
  }
164
150
  }
165
151
  case "status": {
166
- const token = getStoredToken();
152
+ const tokenResult = await (0, auth_js_1.getValidAccessToken)(HOST, TOKEN_ENDPOINT, CLIENT_ID);
167
153
  return {
168
154
  content: [
169
155
  {
170
156
  type: "text",
171
157
  text: JSON.stringify({
172
158
  remote_url: REMOTE_MCP_URL,
173
- authorized: !!token,
159
+ authorized: !!tokenResult,
174
160
  tools_count: remoteTools.length,
175
161
  }, null, 2),
176
162
  },
@@ -178,10 +164,9 @@ server.setRequestHandler(types_js_1.CallToolRequestSchema, async (request) => {
178
164
  };
179
165
  }
180
166
  default: {
181
- // Check authorization for remote tools
182
- const token = getStoredToken();
183
- cachedToken = token;
184
- 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) {
185
170
  const authUrl = generateAuthUrl();
186
171
  return {
187
172
  content: [
@@ -193,7 +178,7 @@ server.setRequestHandler(types_js_1.CallToolRequestSchema, async (request) => {
193
178
  };
194
179
  }
195
180
  try {
196
- const result = await callRemoteTool(name, args);
181
+ const result = await callRemoteTool(name, args, tokenResult.access_token);
197
182
  return { content: [{ type: "text", text: result }] };
198
183
  }
199
184
  catch (e) {
package/package.json CHANGED
@@ -1,18 +1,25 @@
1
1
  {
2
2
  "name": "@scorehub/mcp-server",
3
- "version": "0.1.2",
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": ["dist"],
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": ["mcp", "scorehub", "tiktok", "oauth"],
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"