@liangshanli/mcp-server-project-standards 2.0.1 → 2.0.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.
package/bin/cli.js CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env node
2
2
  const { spawn } = require('child_process');
3
3
  const path = require('path');
4
4
  const fs = require('fs');
@@ -19,6 +19,8 @@ if (!fs.existsSync(serverPath)) {
19
19
  }
20
20
 
21
21
  writeLog('INFO', `Starting MCP Project Standards server from: ${serverPath}`);
22
+ writeLog('INFO', `Current working directory: ${process.cwd()}`);
23
+ writeLog('INFO', `CLI script directory: ${__dirname}`);
22
24
 
23
25
  let server = null;
24
26
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@liangshanli/mcp-server-project-standards",
3
- "version": "2.0.1",
3
+ "version": "2.0.4",
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": {
@@ -1,98 +1,3 @@
1
-
2
-
3
-
4
-
5
-
6
-
7
-
8
-
9
-
10
-
11
-
12
-
13
-
14
-
15
-
16
-
17
-
18
-
19
-
20
-
21
-
22
-
23
-
24
-
25
-
26
-
27
-
28
-
29
-
30
-
31
-
32
-
33
-
34
-
35
-
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
-
64
-
65
-
66
-
67
-
68
-
69
-
70
-
71
-
72
-
73
-
74
-
75
-
76
-
77
-
78
-
79
-
80
-
81
-
82
-
83
-
84
-
85
-
86
-
87
-
88
-
89
-
90
-
91
-
92
-
93
-
94
-
95
-
96
1
  const fs = require('fs-extra');
97
2
  const path = require('path');
98
3
 
@@ -105,6 +10,7 @@ const database_standards = require('./utils/database_standards');
105
10
  const api_login = require('./utils/api_login');
106
11
  const api_debug = require('./utils/api_debug');
107
12
  const api_config = require('./utils/api_config');
13
+ const api_help = require('./utils/api_help');
108
14
 
109
15
  // Get configuration from file or environment
110
16
  const getConfig = () => {
@@ -274,6 +180,12 @@ class ProjectStandardsMCPServer {
274
180
  return result;
275
181
  }
276
182
 
183
+ // API help tool
184
+ async api_help(params) {
185
+ const result = await api_help(params, this.config, saveConfig);
186
+ return result;
187
+ }
188
+
277
189
 
278
190
 
279
191
 
@@ -617,7 +529,7 @@ class ProjectStandardsMCPServer {
617
529
  // API Login Tool
618
530
  tools.push({
619
531
  name: 'api_login',
620
- description: 'API login authentication tool that uses environment variables for login credentials',
532
+ description: 'API login authentication tool that uses environment variables for login credentials. Automatically extracts token from response and updates Authorization headers. Example: Call with optional baseUrl parameter to override default base URL',
621
533
  inputSchema: {
622
534
  type: 'object',
623
535
  properties: {
@@ -632,7 +544,7 @@ class ProjectStandardsMCPServer {
632
544
  // API Debug Tool
633
545
  tools.push({
634
546
  name: 'api_debug',
635
- description: 'API debugging tool for directly executing API requests with automatic content-type detection and flexible body format support',
547
+ description: 'API debugging tool for directly executing API requests with automatic content-type detection and flexible body format support. Examples: GET /api/users with query params, POST /api/login with JSON body {"username":"admin","password":"123456"}, PUT /api/users/123 with form data "name=John&email=john@example.com"',
636
548
  inputSchema: {
637
549
  type: 'object',
638
550
  properties: {
@@ -719,17 +631,33 @@ class ProjectStandardsMCPServer {
719
631
  }
720
632
  });
721
633
 
634
+ // API Help Tool
635
+ tools.push({
636
+ name: 'api_help',
637
+ description: 'API help tool that provides detailed documentation and examples for all API debugging tools. Use this to understand how to use api_debug, api_login, and api_config tools effectively',
638
+ inputSchema: {
639
+ type: 'object',
640
+ properties: {
641
+ tool: {
642
+ type: 'string',
643
+ description: 'Specific tool name to get help for (optional: api_debug, api_login, api_config)',
644
+ examples: ['api_debug', 'api_login', 'api_config']
645
+ }
646
+ }
647
+ }
648
+ });
649
+
722
650
  // API Config Tool
723
651
  tools.push({
724
652
  name: 'api_config',
725
- description: 'API configuration management tool for managing API settings, endpoints, and configurations',
653
+ description: 'API configuration management tool for managing API settings, endpoints, and configurations. Examples: get config, set baseUrl to "https://api.example.com", updateHeaders with {"Authorization":"Bearer token"}, search APIs by keyword, list all configured APIs',
726
654
  inputSchema: {
727
655
  type: 'object',
728
656
  properties: {
729
657
  action: {
730
658
  type: 'string',
731
- enum: ['get', 'set', 'updateBaseUrl', 'updateHeaders', 'deleteHeader', 'search', 'list'],
732
- description: 'Action to perform: "get" to retrieve config, "set" to update config, "updateBaseUrl" to update base URL, "updateHeaders" to update headers, "deleteHeader" to delete header, "search" to search APIs, "list" to list all APIs'
659
+ enum: ['get', 'set', 'updateBaseUrl', 'updateHeaders', 'deleteHeader', 'addApi', 'search', 'list'],
660
+ description: 'Action to perform: "get" to retrieve config, "set" to update config, "updateBaseUrl" to update base URL, "updateHeaders" to update headers, "deleteHeader" to delete header, "addApi" to add API endpoint, "search" to search APIs, "list" to list all APIs'
733
661
  },
734
662
  config: {
735
663
  type: 'object',
@@ -795,6 +723,41 @@ class ProjectStandardsMCPServer {
795
723
  type: 'string',
796
724
  description: 'Name of header to delete (required for "deleteHeader" action)'
797
725
  },
726
+ api: {
727
+ type: 'object',
728
+ description: 'API configuration (required for "addApi" action)',
729
+ properties: {
730
+ url: {
731
+ type: 'string',
732
+ description: 'API endpoint URL'
733
+ },
734
+ method: {
735
+ type: 'string',
736
+ enum: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH'],
737
+ description: 'HTTP method'
738
+ },
739
+ description: {
740
+ type: 'string',
741
+ description: 'API description'
742
+ },
743
+ query: {
744
+ type: 'object',
745
+ description: 'Query parameters'
746
+ },
747
+ body: {
748
+ description: 'Request body'
749
+ },
750
+ contentType: {
751
+ type: 'string',
752
+ description: 'Content-Type for request body'
753
+ },
754
+ header: {
755
+ type: 'object',
756
+ description: 'Additional headers for this specific request'
757
+ }
758
+ },
759
+ required: ['url']
760
+ },
798
761
  keyword: {
799
762
  type: 'string',
800
763
  description: 'Search keyword (required for "search" action)'
@@ -840,6 +803,13 @@ class ProjectStandardsMCPServer {
840
803
  },
841
804
  required: ['headerName']
842
805
  },
806
+ {
807
+ properties: {
808
+ action: { const: 'addApi' },
809
+ api: { type: 'object' }
810
+ },
811
+ required: ['api']
812
+ },
843
813
  {
844
814
  properties: {
845
815
  action: { const: 'search' },
@@ -3,21 +3,22 @@ const { loadApiConfig, saveApiConfig } = require('./api_common');
3
3
  /**
4
4
  * API 配置工具 - 专门处理API配置管理
5
5
  * @param {Object} params - 参数
6
- * @param {string} params.action - 操作类型 ('get', 'set', 'updateBaseUrl', 'updateHeaders', 'deleteHeader', 'search', 'list')
6
+ * @param {string} params.action - 操作类型 ('get', 'set', 'updateBaseUrl', 'updateHeaders', 'deleteHeader', 'addApi', 'search', 'list')
7
7
  * @param {Object} params.config - API配置(set 时必需)
8
8
  * @param {string} params.baseUrl - 基础URL(updateBaseUrl 时必需)
9
9
  * @param {Object} params.headers - 请求头(updateHeaders 时必需)
10
10
  * @param {string} params.headerName - 要删除的请求头名称(deleteHeader 时必需)
11
+ * @param {Object} params.api - API配置(addApi 时必需)
11
12
  * @param {string} params.keyword - 搜索关键词(search 时必需)
12
13
  * @param {Object} config - 服务器配置
13
14
  * @param {Function} saveConfig - 保存配置函数
14
15
  * @returns {Object} API配置结果
15
16
  */
16
17
  async function api_config(params, config, saveConfig) {
17
- const { action, config: apiConfig, baseUrl, headers, headerName, keyword } = params || {};
18
+ const { action, config: apiConfig, baseUrl, headers, headerName, api, keyword } = params || {};
18
19
 
19
20
  if (!action) {
20
- throw new Error('Missing action parameter. Must be "get", "set", "updateBaseUrl", "updateHeaders", "deleteHeader", "search", or "list"');
21
+ throw new Error('Missing action parameter. Must be "get", "set", "updateBaseUrl", "updateHeaders", "deleteHeader", "addApi", "search", or "list"');
21
22
  }
22
23
 
23
24
  if (action === 'get') {
@@ -162,6 +163,53 @@ async function api_config(params, config, saveConfig) {
162
163
  } catch (err) {
163
164
  throw new Error(`Failed to delete header: ${err.message}`);
164
165
  }
166
+ } else if (action === 'addApi') {
167
+ if (!api || !api.url) {
168
+ throw new Error('Missing or invalid api parameter for addApi action. API must have url property');
169
+ }
170
+
171
+ try {
172
+ const apiDebugConfig = loadApiConfig();
173
+
174
+ if (!apiDebugConfig.list) {
175
+ apiDebugConfig.list = [];
176
+ }
177
+
178
+ // 检查是否已存在相同URL的API
179
+ const existingIndex = apiDebugConfig.list.findIndex(item => item.url === api.url);
180
+
181
+ if (existingIndex >= 0) {
182
+ // 更新现有API
183
+ apiDebugConfig.list[existingIndex] = { ...apiDebugConfig.list[existingIndex], ...api };
184
+ const saved = saveApiConfig(apiDebugConfig);
185
+ if (!saved) {
186
+ throw new Error('Failed to save API configuration');
187
+ }
188
+
189
+ return {
190
+ success: true,
191
+ message: `Successfully updated existing API: ${api.url}`,
192
+ api: apiDebugConfig.list[existingIndex],
193
+ timestamp: new Date().toISOString()
194
+ };
195
+ } else {
196
+ // 添加新API
197
+ apiDebugConfig.list.push(api);
198
+ const saved = saveApiConfig(apiDebugConfig);
199
+ if (!saved) {
200
+ throw new Error('Failed to save API configuration');
201
+ }
202
+
203
+ return {
204
+ success: true,
205
+ message: `Successfully added new API: ${api.url}`,
206
+ api: api,
207
+ timestamp: new Date().toISOString()
208
+ };
209
+ }
210
+ } catch (err) {
211
+ throw new Error(`Failed to add API: ${err.message}`);
212
+ }
165
213
  } else if (action === 'search') {
166
214
  if (!keyword) {
167
215
  throw new Error('Missing keyword parameter for search action');
@@ -0,0 +1,182 @@
1
+ /**
2
+ * API 帮助工具 - 返回API调试工具的详细说明和示例
3
+ * @param {Object} params - 参数
4
+ * @param {string} params.tool - 要查看的工具名称(可选,默认返回所有工具)
5
+ * @param {Object} config - 服务器配置
6
+ * @param {Function} saveConfig - 保存配置函数
7
+ * @returns {Object} 工具说明和示例
8
+ */
9
+ async function api_help(params, config, saveConfig) {
10
+ const { tool } = params || {};
11
+
12
+ const helpContent = {
13
+ api_debug: {
14
+ name: 'api_debug',
15
+ description: 'API调试工具 - 直接执行API请求',
16
+ usage: '直接传入URL和参数即可执行API请求,无需复杂的action参数',
17
+ supportedFormats: [
18
+ 'JSON对象: {"username": "admin", "password": "123456"}',
19
+ '表单数据: "username=admin&password=123456"',
20
+ '纯文本: "Hello World"',
21
+ 'XML: "<user><name>John</name><email>john@example.com</email></user>"',
22
+ 'HTML: "<html><body>Content</body></html>"'
23
+ ],
24
+ autoContentTypeDetection: {
25
+ 'JSON对象': 'application/json',
26
+ '表单数据': 'application/x-www-form-urlencoded',
27
+ 'XML': 'application/xml',
28
+ 'HTML': 'text/html',
29
+ '纯文本': 'text/plain'
30
+ },
31
+ examples: [
32
+ {
33
+ description: '简单GET请求',
34
+ request: {
35
+ url: '/api/users',
36
+ method: 'GET',
37
+ query: { page: 1, limit: 10 }
38
+ }
39
+ },
40
+ {
41
+ description: 'POST请求带JSON体',
42
+ request: {
43
+ url: '/api/login',
44
+ method: 'POST',
45
+ body: { username: 'admin', password: '123456' },
46
+ headers: { 'Content-Type': 'application/json' }
47
+ }
48
+ },
49
+ {
50
+ description: 'PUT请求带表单数据',
51
+ request: {
52
+ url: '/api/users/123',
53
+ method: 'PUT',
54
+ body: 'name=John&email=john@example.com',
55
+ contentType: 'application/x-www-form-urlencoded'
56
+ }
57
+ },
58
+ {
59
+ description: 'DELETE请求带认证',
60
+ request: {
61
+ url: '/api/users/123',
62
+ method: 'DELETE',
63
+ headers: { 'Authorization': 'Bearer token123' }
64
+ }
65
+ }
66
+ ],
67
+ bestPractices: [
68
+ '使用相对URL: /api/endpoint 而不是完整URL',
69
+ '通过api_config工具设置baseUrl',
70
+ '让工具自动检测内容类型,除非有特殊需求',
71
+ 'GET请求使用query参数而不是body',
72
+ '通过headers参数设置认证信息'
73
+ ]
74
+ },
75
+ api_login: {
76
+ name: 'api_login',
77
+ description: 'API登录工具 - 使用环境变量进行登录认证',
78
+ usage: '无需参数,直接从环境变量获取登录信息',
79
+ environmentVariables: {
80
+ 'API_DEBUG_LOGIN_URL': '登录接口URL(默认: /api/login)',
81
+ 'API_DEBUG_LOGIN_METHOD': '登录请求方法(默认: POST)',
82
+ 'API_DEBUG_LOGIN_BODY': '登录请求体模板(支持JSON和字符串格式)',
83
+ 'API_DEBUG_LOGIN_DESCRIPTION': '登录接口描述'
84
+ },
85
+ features: [
86
+ '自动从环境变量获取登录配置',
87
+ '支持JSON和字符串格式的登录体',
88
+ '自动提取token并更新Authorization头',
89
+ '支持自定义baseUrl参数'
90
+ ],
91
+ examples: [
92
+ {
93
+ description: '基本登录(使用环境变量配置)',
94
+ request: {}
95
+ },
96
+ {
97
+ description: '指定baseUrl的登录',
98
+ request: {
99
+ baseUrl: 'https://api.example.com'
100
+ }
101
+ }
102
+ ]
103
+ },
104
+ api_config: {
105
+ name: 'api_config',
106
+ description: 'API配置管理工具 - 管理全局API配置',
107
+ usage: '使用action参数指定操作类型',
108
+ actions: {
109
+ 'get': '获取当前配置',
110
+ 'set': '设置完整配置',
111
+ 'updateBaseUrl': '更新基础URL',
112
+ 'updateHeaders': '更新请求头',
113
+ 'deleteHeader': '删除指定请求头',
114
+ 'addApi': '添加API端点',
115
+ 'search': '搜索API',
116
+ 'list': '列出所有API'
117
+ },
118
+ examples: [
119
+ {
120
+ description: '获取配置',
121
+ request: { action: 'get' }
122
+ },
123
+ {
124
+ description: '更新基础URL',
125
+ request: {
126
+ action: 'updateBaseUrl',
127
+ baseUrl: 'https://api.example.com'
128
+ }
129
+ },
130
+ {
131
+ description: '更新请求头',
132
+ request: {
133
+ action: 'updateHeaders',
134
+ headers: { 'Authorization': 'Bearer token123' }
135
+ }
136
+ },
137
+ {
138
+ description: '搜索API',
139
+ request: {
140
+ action: 'search',
141
+ keyword: 'user'
142
+ }
143
+ },
144
+ {
145
+ description: '添加API端点',
146
+ request: {
147
+ action: 'addApi',
148
+ api: {
149
+ url: '/api/users',
150
+ method: 'GET',
151
+ description: '获取用户列表',
152
+ query: { page: 1, limit: 10 }
153
+ }
154
+ }
155
+ }
156
+ ]
157
+ }
158
+ };
159
+
160
+ if (tool && helpContent[tool]) {
161
+ return {
162
+ success: true,
163
+ tool: helpContent[tool],
164
+ timestamp: new Date().toISOString()
165
+ };
166
+ } else {
167
+ return {
168
+ success: true,
169
+ message: 'API调试工具帮助文档',
170
+ tools: helpContent,
171
+ quickStart: {
172
+ '1. 设置配置': '使用 api_config 工具设置 baseUrl 和 headers',
173
+ '2. 登录认证': '使用 api_login 工具进行登录(如果需要)',
174
+ '3. 调试API': '使用 api_debug 工具执行API请求',
175
+ '4. 查看帮助': '使用 api_help 工具查看详细说明'
176
+ },
177
+ timestamp: new Date().toISOString()
178
+ };
179
+ }
180
+ }
181
+
182
+ module.exports = api_help;