@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@liangshanli/mcp-server-project-standards",
3
- "version": "1.1.0",
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": {
@@ -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.0.0';
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
- index: {
596
- type: 'number',
597
- description: 'Index of API to delete or execute (required for "delete" and "execute" actions)'
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
- index: { type: 'number' }
634
+ url: { type: 'string' }
634
635
  },
635
- required: ['index']
636
+ required: ['url']
636
637
  },
637
638
  {
638
639
  properties: {
639
640
  action: { const: 'execute' },
640
- index: { type: 'number' }
641
+ url: { type: 'string' }
641
642
  },
642
- required: ['index']
643
+ required: ['url']
643
644
  },
644
645
  {
645
646
  properties: {
@@ -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.index - 要执行的接口索引(执行时必需)
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, index } = params || {};
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 (!index && index !== 0) {
203
- throw new Error('Missing index parameter for delete action');
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
- if (index >= 0 && index < apiDebugConfig.list.length) {
216
- const deletedItem = apiDebugConfig.list.splice(index, 1)[0];
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: true,
226
- message: `Successfully deleted API at index ${index}`,
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 (!index && index !== 0) {
238
- throw new Error('Missing index parameter for execute action');
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
- throw new Error('API list not found or invalid');
251
+ apiDebugConfig.list = [];
247
252
  }
248
253
 
249
- if (index < 0 || index >= apiDebugConfig.list.length) {
250
- throw new Error(`Invalid index: ${index}. Must be between 0 and ${apiDebugConfig.list.length - 1}`);
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
- const apiItem = apiDebugConfig.list[index];
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
- const fullUrl = baseUrl + apiItem.url;
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[index].data = responseData;
421
- apiDebugConfig.list[index].status = response.status;
422
- apiDebugConfig.list[index].statusText = response.statusText;
423
- apiDebugConfig.list[index].responseHeaders = Object.fromEntries(response.headers.entries());
424
- apiDebugConfig.list[index].lastExecuted = new Date().toISOString();
425
- apiDebugConfig.list[index].success = isHttpSuccess;
426
- apiDebugConfig.list[index].error = isHttpSuccess ? null : `HTTP ${response.status}: ${response.statusText}`;
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[index].data = null;
431
- apiDebugConfig.list[index].status = null;
432
- apiDebugConfig.list[index].statusText = null;
433
- apiDebugConfig.list[index].responseHeaders = null;
434
- apiDebugConfig.list[index].lastExecuted = new Date().toISOString();
435
- apiDebugConfig.list[index].success = false;
436
- apiDebugConfig.list[index].error = error;
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[index].lastExecuted = new Date().toISOString();
455
- apiDebugConfig.list[index].success = false;
456
- apiDebugConfig.list[index].error = requestError.message;
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
- if (apiDebugConfig.list && apiDebugConfig.list[index]) {
500
- apiDebugConfig.list[index].lastExecuted = new Date().toISOString();
501
- apiDebugConfig.list[index].success = false;
502
- apiDebugConfig.list[index].error = err.message;
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) {