@liangshanli/mcp-server-project-standards 1.1.0 → 1.2.0
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 +54 -45
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@liangshanli/mcp-server-project-standards",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
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.0';
|
|
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 {
|
|
@@ -246,11 +251,14 @@ async function api_debug(params, config, saveConfig) {
|
|
|
246
251
|
throw new Error('API list not found or invalid');
|
|
247
252
|
}
|
|
248
253
|
|
|
249
|
-
|
|
250
|
-
|
|
254
|
+
// 查找指定URL的接口
|
|
255
|
+
const apiItem = apiDebugConfig.list.find(item => item.url === url);
|
|
256
|
+
if (!apiItem) {
|
|
257
|
+
throw new Error(`API with URL "${url}" not found`);
|
|
251
258
|
}
|
|
252
259
|
|
|
253
|
-
|
|
260
|
+
// 获取接口在列表中的索引(用于更新数据)
|
|
261
|
+
const itemIndex = apiDebugConfig.list.findIndex(item => item.url === url);
|
|
254
262
|
const baseUrl = apiDebugConfig.baseUrl || '';
|
|
255
263
|
const commonHeaders = apiDebugConfig.headers || {};
|
|
256
264
|
|
|
@@ -417,23 +425,23 @@ async function api_debug(params, config, saveConfig) {
|
|
|
417
425
|
success = isHttpSuccess;
|
|
418
426
|
|
|
419
427
|
// 记录响应信息
|
|
420
|
-
apiDebugConfig.list[
|
|
421
|
-
apiDebugConfig.list[
|
|
422
|
-
apiDebugConfig.list[
|
|
423
|
-
apiDebugConfig.list[
|
|
424
|
-
apiDebugConfig.list[
|
|
425
|
-
apiDebugConfig.list[
|
|
426
|
-
apiDebugConfig.list[
|
|
428
|
+
apiDebugConfig.list[itemIndex].data = responseData;
|
|
429
|
+
apiDebugConfig.list[itemIndex].status = response.status;
|
|
430
|
+
apiDebugConfig.list[itemIndex].statusText = response.statusText;
|
|
431
|
+
apiDebugConfig.list[itemIndex].responseHeaders = Object.fromEntries(response.headers.entries());
|
|
432
|
+
apiDebugConfig.list[itemIndex].lastExecuted = new Date().toISOString();
|
|
433
|
+
apiDebugConfig.list[itemIndex].success = isHttpSuccess;
|
|
434
|
+
apiDebugConfig.list[itemIndex].error = isHttpSuccess ? null : `HTTP ${response.status}: ${response.statusText}`;
|
|
427
435
|
} else {
|
|
428
436
|
// 记录失败信息
|
|
429
437
|
success = false;
|
|
430
|
-
apiDebugConfig.list[
|
|
431
|
-
apiDebugConfig.list[
|
|
432
|
-
apiDebugConfig.list[
|
|
433
|
-
apiDebugConfig.list[
|
|
434
|
-
apiDebugConfig.list[
|
|
435
|
-
apiDebugConfig.list[
|
|
436
|
-
apiDebugConfig.list[
|
|
438
|
+
apiDebugConfig.list[itemIndex].data = null;
|
|
439
|
+
apiDebugConfig.list[itemIndex].status = null;
|
|
440
|
+
apiDebugConfig.list[itemIndex].statusText = null;
|
|
441
|
+
apiDebugConfig.list[itemIndex].responseHeaders = null;
|
|
442
|
+
apiDebugConfig.list[itemIndex].lastExecuted = new Date().toISOString();
|
|
443
|
+
apiDebugConfig.list[itemIndex].success = false;
|
|
444
|
+
apiDebugConfig.list[itemIndex].error = error;
|
|
437
445
|
}
|
|
438
446
|
|
|
439
447
|
// 去重处理:相同的 URL 只保留一份(保留最新的执行结果)
|
|
@@ -451,9 +459,9 @@ async function api_debug(params, config, saveConfig) {
|
|
|
451
459
|
} catch (requestError) {
|
|
452
460
|
// 只有请求相关的错误才保存到 api.json
|
|
453
461
|
try {
|
|
454
|
-
apiDebugConfig.list[
|
|
455
|
-
apiDebugConfig.list[
|
|
456
|
-
apiDebugConfig.list[
|
|
462
|
+
apiDebugConfig.list[itemIndex].lastExecuted = new Date().toISOString();
|
|
463
|
+
apiDebugConfig.list[itemIndex].success = false;
|
|
464
|
+
apiDebugConfig.list[itemIndex].error = requestError.message;
|
|
457
465
|
saveApiConfig(apiDebugConfig);
|
|
458
466
|
} catch (saveErr) {
|
|
459
467
|
console.error('Failed to save request error information:', saveErr.message);
|
|
@@ -496,10 +504,11 @@ async function api_debug(params, config, saveConfig) {
|
|
|
496
504
|
// 如果是在保存配置时出错,也要尝试记录错误信息
|
|
497
505
|
try {
|
|
498
506
|
const apiDebugConfig = loadApiConfig();
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
apiDebugConfig.list[
|
|
502
|
-
apiDebugConfig.list[
|
|
507
|
+
const itemIndex = apiDebugConfig.list.findIndex(item => item.url === url);
|
|
508
|
+
if (apiDebugConfig.list && itemIndex >= 0) {
|
|
509
|
+
apiDebugConfig.list[itemIndex].lastExecuted = new Date().toISOString();
|
|
510
|
+
apiDebugConfig.list[itemIndex].success = false;
|
|
511
|
+
apiDebugConfig.list[itemIndex].error = err.message;
|
|
503
512
|
saveApiConfig(apiDebugConfig);
|
|
504
513
|
}
|
|
505
514
|
} catch (saveErr) {
|