@liangshanli/mcp-server-project-standards 2.1.7 → 2.1.10
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/package.json +2 -2
- package/src/utils/api_debug.js +141 -47
- package/src/utils/api_execute.js +6 -0
- package/src/utils/api_login.js +15 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@liangshanli/mcp-server-project-standards",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.10",
|
|
4
4
|
"description": "MCP Project Standards server with project info, structure, API standards, development standards, API debugging, login authentication and configuration management tools",
|
|
5
5
|
"main": "bin/cli.js",
|
|
6
6
|
"bin": {
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"license": "MIT",
|
|
31
31
|
"repository": {
|
|
32
32
|
"type": "git",
|
|
33
|
-
"url": "https://github.com/liliangshan/mcp-server-project-standards"
|
|
33
|
+
"url": "git+https://github.com/liliangshan/mcp-server-project-standards.git"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"fs-extra": "^11.2.0",
|
package/src/utils/api_debug.js
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
const { getAllowedMethods, loadApiConfig, saveApiConfig, detectContentType } = require('./api_common');
|
|
2
|
+
const https = require('https');
|
|
3
|
+
|
|
4
|
+
// 为 HTTPS 请求创建跳过证书验证的 agent
|
|
5
|
+
const httpsAgent = new https.Agent({
|
|
6
|
+
rejectUnauthorized: false
|
|
7
|
+
});
|
|
2
8
|
|
|
3
9
|
/**
|
|
4
10
|
* API 调试工具 - 直接执行API请求
|
|
@@ -33,34 +39,34 @@ async function api_debug(params, config, saveConfig) {
|
|
|
33
39
|
|
|
34
40
|
if (!url) {
|
|
35
41
|
return {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
42
|
+
contentType: "text",
|
|
43
|
+
content: [
|
|
44
|
+
{
|
|
45
|
+
type: "text",
|
|
46
|
+
text: "⚠️ IMPORTANT: You MUST use addApi to add the API to the list first! Use api_config tool.\n\n🔧 Step 1: Add API to Configuration (REQUIRED)\n\nCall: api_config with action=\"addApi\" and api={\"url\":\"${url}\",\"method\":\"${requestMethod}\",\"body\":\"your corrected JSON here\"}\n\n⚠️ REMINDER: You MUST use api_config with addApi to add the API to the list!"
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
type: "text",
|
|
50
|
+
text: "🔧 Step 2: Execute API by Index\n\nAfter adding the API, call: api_execute with index=<returned index>\n\nThis will execute the pre-configured API with the correct format."
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
type: "text",
|
|
54
|
+
text: "🚨 REMINDER: You MUST use addApi first!\n\n- Use api_config with action=\"addApi\" to add the API to the list\n- Then use api_execute with the returned index to execute"
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
type: "text",
|
|
58
|
+
text: "💡 IMPORTANT: Remember to use addApi!\n\n- First: api_config with action=\"addApi\" to add the API\n- Second: api_execute with index to run the API"
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
type: "text",
|
|
62
|
+
text: "📋 Final Reminder: Use addApi → Then api_execute\n\n1. First: api_config with action=\"addApi\"\n2. Then: api_execute with index=<number>\n\nThis is the ONLY way to handle invalid JSON requests."
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
type: "text",
|
|
66
|
+
text: "⚠️ ESSENTIAL: You MUST use addApi!\n\n- First: api_config with action=\"addApi\" to add the API\n- Second: api_execute with index to run the API"
|
|
67
|
+
}
|
|
68
|
+
]
|
|
69
|
+
};
|
|
64
70
|
}
|
|
65
71
|
|
|
66
72
|
try {
|
|
@@ -190,11 +196,18 @@ async function api_debug(params, config, saveConfig) {
|
|
|
190
196
|
|
|
191
197
|
try {
|
|
192
198
|
// 执行请求
|
|
193
|
-
|
|
199
|
+
const fetchOptions = {
|
|
194
200
|
method: requestMethod,
|
|
195
201
|
headers: finalHeaders,
|
|
196
202
|
body: requestBody
|
|
197
|
-
}
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
// 为 HTTPS 请求添加 agent 以跳过证书验证
|
|
206
|
+
if (finalRequestUrl.startsWith('https')) {
|
|
207
|
+
fetchOptions.agent = httpsAgent;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
response = await fetch(finalRequestUrl, fetchOptions);
|
|
198
211
|
|
|
199
212
|
// 获取响应数据
|
|
200
213
|
const responseContentType = response.headers.get('content-type');
|
|
@@ -215,23 +228,104 @@ async function api_debug(params, config, saveConfig) {
|
|
|
215
228
|
}
|
|
216
229
|
|
|
217
230
|
if (success && response) {
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
231
|
+
// 自动将接口添加到配置列表中
|
|
232
|
+
try {
|
|
233
|
+
const apiConfig = loadApiConfig();
|
|
234
|
+
if (!apiConfig.list) {
|
|
235
|
+
apiConfig.list = [];
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// 检查是否已存在相同的接口
|
|
239
|
+
const existingApiIndex = apiConfig.list.findIndex(api =>
|
|
240
|
+
api.url === url && api.method === requestMethod
|
|
241
|
+
);
|
|
242
|
+
|
|
243
|
+
if (existingApiIndex === -1) {
|
|
244
|
+
// 如果不存在,添加到列表
|
|
245
|
+
const newApi = {
|
|
246
|
+
url: url,
|
|
247
|
+
method: requestMethod,
|
|
248
|
+
description: `API added from api_debug: ${url}`,
|
|
249
|
+
headers: headers,
|
|
250
|
+
query: query,
|
|
251
|
+
body: body,
|
|
252
|
+
contentType: contentType
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
apiConfig.list.push(newApi);
|
|
256
|
+
saveApiConfig(apiConfig);
|
|
257
|
+
|
|
258
|
+
return {
|
|
259
|
+
success: true,
|
|
260
|
+
message: `Successfully executed API: ${url} (Added to list at index ${apiConfig.list.length - 1})`,
|
|
261
|
+
apiIndex: apiConfig.list.length - 1,
|
|
262
|
+
request: {
|
|
263
|
+
url: finalRequestUrl,
|
|
264
|
+
method: requestMethod,
|
|
265
|
+
headers: finalHeaders,
|
|
266
|
+
body: requestBody
|
|
267
|
+
},
|
|
268
|
+
response: {
|
|
269
|
+
status: response.status,
|
|
270
|
+
statusText: response.statusText,
|
|
271
|
+
headers: Object.fromEntries(response.headers.entries()),
|
|
272
|
+
data: responseData
|
|
273
|
+
},
|
|
274
|
+
timestamp: new Date().toISOString()
|
|
275
|
+
};
|
|
276
|
+
} else {
|
|
277
|
+
// 如果已存在,更新接口信息
|
|
278
|
+
apiConfig.list[existingApiIndex] = {
|
|
279
|
+
...apiConfig.list[existingApiIndex],
|
|
280
|
+
url: url,
|
|
281
|
+
method: requestMethod,
|
|
282
|
+
headers: headers,
|
|
283
|
+
query: query,
|
|
284
|
+
body: body,
|
|
285
|
+
contentType: contentType
|
|
286
|
+
};
|
|
287
|
+
saveApiConfig(apiConfig);
|
|
288
|
+
|
|
289
|
+
return {
|
|
290
|
+
success: true,
|
|
291
|
+
message: `Successfully executed API: ${url} (Updated existing API at index ${existingApiIndex})`,
|
|
292
|
+
apiIndex: existingApiIndex,
|
|
293
|
+
request: {
|
|
294
|
+
url: finalRequestUrl,
|
|
295
|
+
method: requestMethod,
|
|
296
|
+
headers: finalHeaders,
|
|
297
|
+
body: requestBody
|
|
298
|
+
},
|
|
299
|
+
response: {
|
|
300
|
+
status: response.status,
|
|
301
|
+
statusText: response.statusText,
|
|
302
|
+
headers: Object.fromEntries(response.headers.entries()),
|
|
303
|
+
data: responseData
|
|
304
|
+
},
|
|
305
|
+
timestamp: new Date().toISOString()
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
} catch (saveError) {
|
|
309
|
+
// 如果保存失败,仍然返回成功响应
|
|
310
|
+
console.error('Failed to save API to list:', saveError.message);
|
|
311
|
+
return {
|
|
312
|
+
success: true,
|
|
313
|
+
message: `Successfully executed API: ${url} (Failed to save to list)`,
|
|
314
|
+
request: {
|
|
315
|
+
url: finalRequestUrl,
|
|
316
|
+
method: requestMethod,
|
|
317
|
+
headers: finalHeaders,
|
|
318
|
+
body: requestBody
|
|
319
|
+
},
|
|
320
|
+
response: {
|
|
321
|
+
status: response.status,
|
|
322
|
+
statusText: response.statusText,
|
|
323
|
+
headers: Object.fromEntries(response.headers.entries()),
|
|
324
|
+
data: responseData
|
|
325
|
+
},
|
|
326
|
+
timestamp: new Date().toISOString()
|
|
327
|
+
};
|
|
328
|
+
}
|
|
235
329
|
} else {
|
|
236
330
|
return {
|
|
237
331
|
success: false,
|
package/src/utils/api_execute.js
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
const { loadApiConfig, getAllowedMethods } = require('./api_common');
|
|
2
2
|
|
|
3
|
+
// 设置全局环境变量以跳过证书验证
|
|
4
|
+
if (!process.env.NODE_TLS_REJECT_UNAUTHORIZED) {
|
|
5
|
+
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
|
|
6
|
+
}
|
|
7
|
+
|
|
3
8
|
/**
|
|
4
9
|
* API 执行工具 - 通过索引执行已配置的API
|
|
5
10
|
* @param {Object} params - 参数
|
|
@@ -131,6 +136,7 @@ async function api_execute(params, config, saveConfig) {
|
|
|
131
136
|
};
|
|
132
137
|
|
|
133
138
|
} catch (err) {
|
|
139
|
+
console.error(err);
|
|
134
140
|
throw new Error(`Failed to execute API at index ${index}: ${err.message}`);
|
|
135
141
|
}
|
|
136
142
|
}
|
package/src/utils/api_login.js
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
const { getLoginUrl, getLoginMethod, getLoginBody, loadApiConfig, saveApiConfig } = require('./api_common');
|
|
2
|
+
const https = require('https');
|
|
3
|
+
|
|
4
|
+
// 为 HTTPS 请求创建跳过证书验证的 agent
|
|
5
|
+
const httpsAgent = new https.Agent({
|
|
6
|
+
rejectUnauthorized: false
|
|
7
|
+
});
|
|
2
8
|
|
|
3
9
|
/**
|
|
4
10
|
* API 登录工具 - 直接执行登录请求(从环境变量获取登录信息)
|
|
@@ -57,11 +63,18 @@ async function api_login(params, config, saveConfig) {
|
|
|
57
63
|
let error = null;
|
|
58
64
|
|
|
59
65
|
try {
|
|
60
|
-
|
|
66
|
+
const fetchOptions = {
|
|
61
67
|
method: loginMethod,
|
|
62
68
|
headers: headers,
|
|
63
69
|
body: loginBody
|
|
64
|
-
}
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
// 为 HTTPS 请求添加 agent 以跳过证书验证
|
|
73
|
+
if (fullLoginUrl.startsWith('https')) {
|
|
74
|
+
fetchOptions.agent = httpsAgent;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
response = await fetch(fullLoginUrl, fetchOptions);
|
|
65
78
|
|
|
66
79
|
// 获取响应数据
|
|
67
80
|
const contentType = response.headers.get('content-type');
|