@liangshanli/mcp-server-project-standards 1.1.0 → 1.2.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/package.json +1 -1
- package/src/server-final.js +11 -10
- package/src/utils/api_debug.js +69 -49
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@liangshanli/mcp-server-project-standards",
|
|
3
|
-
"version": "1.1
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "MCP Project Standards server with project info, structure, API standards, development standards and custom tools",
|
|
5
5
|
"main": "bin/cli.js",
|
|
6
6
|
"bin": {
|
package/src/server-final.js
CHANGED
|
@@ -54,7 +54,7 @@ console.error('==============================================');
|
|
|
54
54
|
class ProjectStandardsMCPServer {
|
|
55
55
|
constructor() {
|
|
56
56
|
this.name = 'project-standards-mcp-server';
|
|
57
|
-
this.version = '1.
|
|
57
|
+
this.version = '1.2.1';
|
|
58
58
|
this.initialized = false;
|
|
59
59
|
this.config = getConfig();
|
|
60
60
|
this.needsProjectFolder = this.config === null;
|
|
@@ -499,7 +499,7 @@ class ProjectStandardsMCPServer {
|
|
|
499
499
|
);
|
|
500
500
|
|
|
501
501
|
// 构建 API 调试工具描述
|
|
502
|
-
let apiDebugDescription = 'API debugging tool for testing and executing API requests';
|
|
502
|
+
let apiDebugDescription = 'API debugging tool for testing and executing API requests. Use URL to identify APIs instead of index numbers.';
|
|
503
503
|
|
|
504
504
|
// 检查是否设置了登录接口环境变量
|
|
505
505
|
const loginUrl = process.env.API_DEBUG_LOGIN_URL;
|
|
@@ -524,6 +524,7 @@ class ProjectStandardsMCPServer {
|
|
|
524
524
|
}
|
|
525
525
|
|
|
526
526
|
apiDebugDescription += '\n\n💡 Usage Instructions:';
|
|
527
|
+
apiDebugDescription += '\n- Use URL to identify APIs for execute and delete operations (not index numbers)';
|
|
527
528
|
apiDebugDescription += '\n- Login API automatically uses environment variable configuration';
|
|
528
529
|
apiDebugDescription += '\n- Non-login APIs must use allowed methods only';
|
|
529
530
|
apiDebugDescription += '\n- Common request headers are automatically updated after successful login';
|
|
@@ -538,7 +539,7 @@ class ProjectStandardsMCPServer {
|
|
|
538
539
|
action: {
|
|
539
540
|
type: 'string',
|
|
540
541
|
enum: ['get', 'set', 'delete', 'execute', 'updateBaseUrl', 'updateHeaders', 'deleteHeader', 'search'],
|
|
541
|
-
description: 'Action to perform: "get" to retrieve config, "set" to update config, "delete" to delete API, "execute" to execute API, "updateBaseUrl" to update base URL, "updateHeaders" to update headers, "deleteHeader" to delete specific header, "search" to search APIs by URL or description'
|
|
542
|
+
description: 'Action to perform: "get" to retrieve config, "set" to update config, "delete" to delete API by URL, "execute" to execute API by URL, "updateBaseUrl" to update base URL, "updateHeaders" to update headers, "deleteHeader" to delete specific header, "search" to search APIs by URL or description'
|
|
542
543
|
},
|
|
543
544
|
config: {
|
|
544
545
|
type: 'object',
|
|
@@ -592,9 +593,9 @@ class ProjectStandardsMCPServer {
|
|
|
592
593
|
}
|
|
593
594
|
}
|
|
594
595
|
},
|
|
595
|
-
|
|
596
|
-
type: '
|
|
597
|
-
description: '
|
|
596
|
+
url: {
|
|
597
|
+
type: 'string',
|
|
598
|
+
description: 'URL of API to delete or execute (required for "delete" and "execute" actions)'
|
|
598
599
|
},
|
|
599
600
|
baseUrl: {
|
|
600
601
|
type: 'string',
|
|
@@ -630,16 +631,16 @@ class ProjectStandardsMCPServer {
|
|
|
630
631
|
{
|
|
631
632
|
properties: {
|
|
632
633
|
action: { const: 'delete' },
|
|
633
|
-
|
|
634
|
+
url: { type: 'string' }
|
|
634
635
|
},
|
|
635
|
-
required: ['
|
|
636
|
+
required: ['url']
|
|
636
637
|
},
|
|
637
638
|
{
|
|
638
639
|
properties: {
|
|
639
640
|
action: { const: 'execute' },
|
|
640
|
-
|
|
641
|
+
url: { type: 'string' }
|
|
641
642
|
},
|
|
642
|
-
required: ['
|
|
643
|
+
required: ['url']
|
|
643
644
|
},
|
|
644
645
|
{
|
|
645
646
|
properties: {
|
package/src/utils/api_debug.js
CHANGED
|
@@ -119,7 +119,7 @@ const detectContentType = (body) => {
|
|
|
119
119
|
* @param {string} params.config.baseUrl - API 基础 URL
|
|
120
120
|
* @param {Object} params.config.headers - 公共请求头
|
|
121
121
|
* @param {Array} params.config.list - API 接口列表
|
|
122
|
-
* @param {string} params.
|
|
122
|
+
* @param {string} params.url - 要执行的接口URL(执行时必需)
|
|
123
123
|
* @param {string} params.baseUrl - 新的基础 URL(updateBaseUrl 时必需)
|
|
124
124
|
* @param {Object} params.headers - 新的公共请求头(updateHeaders 时必需)
|
|
125
125
|
* @param {string} params.headerName - 要删除的请求头名称(deleteHeader 时必需)
|
|
@@ -129,7 +129,7 @@ const detectContentType = (body) => {
|
|
|
129
129
|
* @returns {Object} API 调试结果
|
|
130
130
|
*/
|
|
131
131
|
async function api_debug(params, config, saveConfig) {
|
|
132
|
-
const { action, config: apiConfig,
|
|
132
|
+
const { action, config: apiConfig, url } = params || {};
|
|
133
133
|
|
|
134
134
|
if (!action) {
|
|
135
135
|
throw new Error('Missing action parameter. Must be "get", "set", "delete", "execute", "updateBaseUrl", "updateHeaders", "deleteHeader", or "search"');
|
|
@@ -199,8 +199,8 @@ async function api_debug(params, config, saveConfig) {
|
|
|
199
199
|
throw new Error(`Failed to update API debug config: ${err.message}`);
|
|
200
200
|
}
|
|
201
201
|
} else if (action === 'delete') {
|
|
202
|
-
if (!
|
|
203
|
-
throw new Error('Missing
|
|
202
|
+
if (!url) {
|
|
203
|
+
throw new Error('Missing url parameter for delete action');
|
|
204
204
|
}
|
|
205
205
|
|
|
206
206
|
try {
|
|
@@ -211,31 +211,36 @@ async function api_debug(params, config, saveConfig) {
|
|
|
211
211
|
apiDebugConfig.list = [];
|
|
212
212
|
}
|
|
213
213
|
|
|
214
|
-
//
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
const saved = saveApiConfig(apiDebugConfig);
|
|
220
|
-
if (!saved) {
|
|
221
|
-
throw new Error('Failed to save API configuration');
|
|
222
|
-
}
|
|
223
|
-
|
|
214
|
+
// 查找并删除指定URL的接口
|
|
215
|
+
const originalLength = apiDebugConfig.list.length;
|
|
216
|
+
apiDebugConfig.list = apiDebugConfig.list.filter(item => item.url !== url);
|
|
217
|
+
|
|
218
|
+
if (apiDebugConfig.list.length === originalLength) {
|
|
224
219
|
return {
|
|
225
|
-
success:
|
|
226
|
-
message: `
|
|
227
|
-
deletedItem: deletedItem,
|
|
220
|
+
success: false,
|
|
221
|
+
message: `API with URL "${url}" not found`,
|
|
228
222
|
timestamp: new Date().toISOString()
|
|
229
223
|
};
|
|
230
|
-
} else {
|
|
231
|
-
throw new Error(`Invalid index: ${index}. Must be between 0 and ${apiDebugConfig.list.length - 1}`);
|
|
232
224
|
}
|
|
225
|
+
|
|
226
|
+
// 保存配置
|
|
227
|
+
const saved = saveApiConfig(apiDebugConfig);
|
|
228
|
+
if (!saved) {
|
|
229
|
+
throw new Error('Failed to save API configuration');
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
return {
|
|
233
|
+
success: true,
|
|
234
|
+
message: `Successfully deleted API with URL: ${url}`,
|
|
235
|
+
deletedUrl: url,
|
|
236
|
+
timestamp: new Date().toISOString()
|
|
237
|
+
};
|
|
233
238
|
} catch (err) {
|
|
234
239
|
throw new Error(`Failed to delete API: ${err.message}`);
|
|
235
240
|
}
|
|
236
241
|
} else if (action === 'execute') {
|
|
237
|
-
if (!
|
|
238
|
-
throw new Error('Missing
|
|
242
|
+
if (!url) {
|
|
243
|
+
throw new Error('Missing url parameter for execute action');
|
|
239
244
|
}
|
|
240
245
|
|
|
241
246
|
try {
|
|
@@ -243,14 +248,23 @@ async function api_debug(params, config, saveConfig) {
|
|
|
243
248
|
const apiDebugConfig = loadApiConfig();
|
|
244
249
|
|
|
245
250
|
if (!apiDebugConfig.list || !Array.isArray(apiDebugConfig.list)) {
|
|
246
|
-
|
|
251
|
+
apiDebugConfig.list = [];
|
|
247
252
|
}
|
|
248
253
|
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
254
|
+
// 查找指定URL的接口,如果不存在则创建一个新的
|
|
255
|
+
let apiItem = apiDebugConfig.list.find(item => item.url === url);
|
|
256
|
+
let itemIndex = apiDebugConfig.list.findIndex(item => item.url === url);
|
|
252
257
|
|
|
253
|
-
|
|
258
|
+
if (!apiItem) {
|
|
259
|
+
// 如果接口不存在,创建一个新的接口配置
|
|
260
|
+
apiItem = {
|
|
261
|
+
url: url,
|
|
262
|
+
method: 'GET',
|
|
263
|
+
description: `API: ${url}`
|
|
264
|
+
};
|
|
265
|
+
apiDebugConfig.list.push(apiItem);
|
|
266
|
+
itemIndex = apiDebugConfig.list.length - 1;
|
|
267
|
+
}
|
|
254
268
|
const baseUrl = apiDebugConfig.baseUrl || '';
|
|
255
269
|
const commonHeaders = apiDebugConfig.headers || {};
|
|
256
270
|
|
|
@@ -291,8 +305,13 @@ async function api_debug(params, config, saveConfig) {
|
|
|
291
305
|
}
|
|
292
306
|
}
|
|
293
307
|
|
|
294
|
-
// 构建完整 URL
|
|
295
|
-
|
|
308
|
+
// 构建完整 URL - 如果用户提供的是完整URL,直接使用;否则拼接baseUrl
|
|
309
|
+
let fullUrl;
|
|
310
|
+
if (apiItem.url.startsWith('http://') || apiItem.url.startsWith('https://')) {
|
|
311
|
+
fullUrl = apiItem.url;
|
|
312
|
+
} else {
|
|
313
|
+
fullUrl = baseUrl + apiItem.url;
|
|
314
|
+
}
|
|
296
315
|
|
|
297
316
|
// 合并请求头
|
|
298
317
|
const headers = {
|
|
@@ -417,23 +436,23 @@ async function api_debug(params, config, saveConfig) {
|
|
|
417
436
|
success = isHttpSuccess;
|
|
418
437
|
|
|
419
438
|
// 记录响应信息
|
|
420
|
-
apiDebugConfig.list[
|
|
421
|
-
apiDebugConfig.list[
|
|
422
|
-
apiDebugConfig.list[
|
|
423
|
-
apiDebugConfig.list[
|
|
424
|
-
apiDebugConfig.list[
|
|
425
|
-
apiDebugConfig.list[
|
|
426
|
-
apiDebugConfig.list[
|
|
439
|
+
apiDebugConfig.list[itemIndex].data = responseData;
|
|
440
|
+
apiDebugConfig.list[itemIndex].status = response.status;
|
|
441
|
+
apiDebugConfig.list[itemIndex].statusText = response.statusText;
|
|
442
|
+
apiDebugConfig.list[itemIndex].responseHeaders = Object.fromEntries(response.headers.entries());
|
|
443
|
+
apiDebugConfig.list[itemIndex].lastExecuted = new Date().toISOString();
|
|
444
|
+
apiDebugConfig.list[itemIndex].success = isHttpSuccess;
|
|
445
|
+
apiDebugConfig.list[itemIndex].error = isHttpSuccess ? null : `HTTP ${response.status}: ${response.statusText}`;
|
|
427
446
|
} else {
|
|
428
447
|
// 记录失败信息
|
|
429
448
|
success = false;
|
|
430
|
-
apiDebugConfig.list[
|
|
431
|
-
apiDebugConfig.list[
|
|
432
|
-
apiDebugConfig.list[
|
|
433
|
-
apiDebugConfig.list[
|
|
434
|
-
apiDebugConfig.list[
|
|
435
|
-
apiDebugConfig.list[
|
|
436
|
-
apiDebugConfig.list[
|
|
449
|
+
apiDebugConfig.list[itemIndex].data = null;
|
|
450
|
+
apiDebugConfig.list[itemIndex].status = null;
|
|
451
|
+
apiDebugConfig.list[itemIndex].statusText = null;
|
|
452
|
+
apiDebugConfig.list[itemIndex].responseHeaders = null;
|
|
453
|
+
apiDebugConfig.list[itemIndex].lastExecuted = new Date().toISOString();
|
|
454
|
+
apiDebugConfig.list[itemIndex].success = false;
|
|
455
|
+
apiDebugConfig.list[itemIndex].error = error;
|
|
437
456
|
}
|
|
438
457
|
|
|
439
458
|
// 去重处理:相同的 URL 只保留一份(保留最新的执行结果)
|
|
@@ -451,9 +470,9 @@ async function api_debug(params, config, saveConfig) {
|
|
|
451
470
|
} catch (requestError) {
|
|
452
471
|
// 只有请求相关的错误才保存到 api.json
|
|
453
472
|
try {
|
|
454
|
-
apiDebugConfig.list[
|
|
455
|
-
apiDebugConfig.list[
|
|
456
|
-
apiDebugConfig.list[
|
|
473
|
+
apiDebugConfig.list[itemIndex].lastExecuted = new Date().toISOString();
|
|
474
|
+
apiDebugConfig.list[itemIndex].success = false;
|
|
475
|
+
apiDebugConfig.list[itemIndex].error = requestError.message;
|
|
457
476
|
saveApiConfig(apiDebugConfig);
|
|
458
477
|
} catch (saveErr) {
|
|
459
478
|
console.error('Failed to save request error information:', saveErr.message);
|
|
@@ -496,10 +515,11 @@ async function api_debug(params, config, saveConfig) {
|
|
|
496
515
|
// 如果是在保存配置时出错,也要尝试记录错误信息
|
|
497
516
|
try {
|
|
498
517
|
const apiDebugConfig = loadApiConfig();
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
apiDebugConfig.list[
|
|
502
|
-
apiDebugConfig.list[
|
|
518
|
+
const itemIndex = apiDebugConfig.list.findIndex(item => item.url === url);
|
|
519
|
+
if (apiDebugConfig.list && itemIndex >= 0) {
|
|
520
|
+
apiDebugConfig.list[itemIndex].lastExecuted = new Date().toISOString();
|
|
521
|
+
apiDebugConfig.list[itemIndex].success = false;
|
|
522
|
+
apiDebugConfig.list[itemIndex].error = err.message;
|
|
503
523
|
saveApiConfig(apiDebugConfig);
|
|
504
524
|
}
|
|
505
525
|
} catch (saveErr) {
|