@liangshanli/mcp-server-project-standards 1.0.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.
@@ -0,0 +1,147 @@
1
+ const fs = require('fs-extra');
2
+ const path = require('path');
3
+
4
+ /**
5
+ * Database standards tool - get, set or delete database standards
6
+ * @param {Object} params - Parameters
7
+ * @param {string} params.action - Action to perform ('get', 'set', or 'delete')
8
+ * @param {Array} params.standards - Array of database standards (required for 'set' action)
9
+ * @param {boolean} params.forceOverwrite - Force overwrite array values when action is 'set' and value is array (default: false)
10
+ * @param {string} params.standard - Standard content to delete when action is 'delete'
11
+ * @param {Object} config - Server configuration
12
+ * @param {Function} saveConfig - Function to save configuration (required for 'set' and 'delete' actions)
13
+ * @returns {Array|Object} Database standards array or update result
14
+ */
15
+ async function database_standards(params, config, saveConfig) {
16
+ const { action, standards, forceOverwrite = false, standard } = params || {};
17
+
18
+ if (!action) {
19
+ throw new Error('Missing action parameter. Must be "get", "set", or "delete"');
20
+ }
21
+
22
+ if (action === 'get') {
23
+ try {
24
+ // 从配置文件的 database_standards 字段中获取标准,如果没有则使用默认值
25
+ const databaseStandards = config?.database_standards || [
26
+ 'Use meaningful table names with descriptive prefixes',
27
+ 'Use snake_case for table and column names',
28
+ 'Use singular names for table names',
29
+ 'Use plural names for junction tables',
30
+ 'Include created_at and updated_at timestamps',
31
+ 'Use UUID for primary keys when appropriate',
32
+ 'Create indexes for frequently queried columns',
33
+ 'Use foreign key constraints for data integrity',
34
+ 'Normalize database structure to reduce redundancy',
35
+ 'Use appropriate data types for each column',
36
+ 'Set NOT NULL constraints where data is required',
37
+ 'Use CHECK constraints for data validation',
38
+ 'Create unique constraints for business rules',
39
+ 'Use database transactions for data consistency',
40
+ 'Implement soft deletes instead of hard deletes',
41
+ 'Use database views for complex queries',
42
+ 'Create stored procedures for complex business logic',
43
+ 'Use database triggers sparingly and document them',
44
+ 'Implement database backup and recovery procedures',
45
+ 'Monitor database performance and optimize queries',
46
+ 'Use connection pooling for better performance',
47
+ 'Implement database security best practices',
48
+ 'Use environment-specific database configurations',
49
+ 'Document database schema and relationships',
50
+ 'Version control database migrations',
51
+ 'Test database changes in development first',
52
+ 'Use database monitoring and alerting tools',
53
+ 'Implement database replication for high availability',
54
+ 'Use database partitioning for large tables',
55
+ 'Regularly analyze and optimize database performance'
56
+ ];
57
+
58
+ return databaseStandards;
59
+ } catch (err) {
60
+ throw new Error(`Failed to get database standards: ${err.message}`);
61
+ }
62
+ } else if (action === 'set') {
63
+ if (!Array.isArray(standards)) {
64
+ throw new Error('Standards must be an array for set action');
65
+ }
66
+
67
+ if (!saveConfig) {
68
+ throw new Error('saveConfig function is required for set action');
69
+ }
70
+
71
+ try {
72
+ // 更新配置
73
+ if (!config.database_standards) {
74
+ config.database_standards = [];
75
+ }
76
+
77
+ // 处理数组类型的合并逻辑
78
+ if (!forceOverwrite) {
79
+ // 如果 forceOverwrite 为 false,则合并数组而不是覆盖
80
+ const existingArray = config.database_standards;
81
+ const newArray = [...new Set([...existingArray, ...standards])];
82
+ config.database_standards = newArray;
83
+ } else {
84
+ // 直接覆盖
85
+ config.database_standards = standards;
86
+ }
87
+
88
+ // 保存配置
89
+ const saved = saveConfig(config);
90
+ if (!saved) {
91
+ throw new Error('Failed to save configuration');
92
+ }
93
+
94
+ return {
95
+ success: true,
96
+ message: 'Successfully updated database standards',
97
+ updatedCount: config.database_standards.length,
98
+ forceOverwrite: forceOverwrite,
99
+ timestamp: new Date().toISOString()
100
+ };
101
+ } catch (err) {
102
+ throw new Error(`Failed to update database standards: ${err.message}`);
103
+ }
104
+ } else if (action === 'delete') {
105
+ if (!standard) {
106
+ throw new Error('Missing standard parameter for delete action');
107
+ }
108
+
109
+ if (!saveConfig) {
110
+ throw new Error('saveConfig function is required for delete action');
111
+ }
112
+
113
+ try {
114
+ // 确保 config.database_standards 存在
115
+ if (!config.database_standards) {
116
+ config.database_standards = [];
117
+ }
118
+
119
+ // 查找并删除指定的 standard
120
+ const standardIndex = config.database_standards.indexOf(standard);
121
+ if (standardIndex !== -1) {
122
+ config.database_standards.splice(standardIndex, 1);
123
+
124
+ // 保存配置
125
+ const saved = saveConfig(config);
126
+ if (!saved) {
127
+ throw new Error('Failed to save configuration');
128
+ }
129
+
130
+ return {
131
+ success: true,
132
+ message: `Successfully deleted standard: ${standard}`,
133
+ deletedStandard: standard,
134
+ timestamp: new Date().toISOString()
135
+ };
136
+ } else {
137
+ throw new Error(`Standard '${standard}' not found`);
138
+ }
139
+ } catch (err) {
140
+ throw new Error(`Failed to delete standard: ${err.message}`);
141
+ }
142
+ } else {
143
+ throw new Error('Invalid action. Must be "get", "set", or "delete"');
144
+ }
145
+ }
146
+
147
+ module.exports = database_standards;
@@ -0,0 +1,51 @@
1
+ const fs = require('fs-extra');
2
+ const path = require('path');
3
+
4
+ /**
5
+ * Execute a custom tool
6
+ * @param {Object} params - Parameters
7
+ * @param {string} params.toolName - Name of the custom tool to execute
8
+ * @param {Object} params.arguments - Arguments to pass to the custom tool
9
+ * @param {Object} config - Server configuration
10
+ * @returns {Object} Result of tool execution
11
+ */
12
+ async function execute_custom_tool(params, config) {
13
+ const { toolName, arguments: args } = params || {};
14
+
15
+ if (!toolName) {
16
+ throw new Error('Missing toolName parameter');
17
+ }
18
+
19
+ const tool = (config.customTools || []).find(t => t.name === toolName);
20
+ if (!tool) {
21
+ throw new Error(`Custom tool '${toolName}' not found`);
22
+ }
23
+
24
+ try {
25
+ // Create a safe execution context
26
+ const context = {
27
+ args: args || {},
28
+ config: config,
29
+ fs: fs,
30
+ path: path,
31
+ console: console,
32
+ Date: Date,
33
+ JSON: JSON
34
+ };
35
+
36
+ // Execute the handler code
37
+ const handler = new Function('context', tool.handlerCode);
38
+ const result = handler(context);
39
+
40
+ return {
41
+ success: true,
42
+ result: result,
43
+ toolName: toolName,
44
+ timestamp: new Date().toISOString()
45
+ };
46
+ } catch (err) {
47
+ throw new Error(`Failed to execute custom tool '${toolName}': ${err.message}`);
48
+ }
49
+ }
50
+
51
+ module.exports = execute_custom_tool;
@@ -0,0 +1,203 @@
1
+ const fs = require('fs-extra');
2
+ const path = require('path');
3
+
4
+ /**
5
+ * API standards tool - get, set or delete API standards
6
+ * @param {Object} params - Parameters
7
+ * @param {string} params.action - Action to perform ('get', 'set', or 'delete')
8
+ * @param {string} params.key - Key to update when action is 'set' (interfaceType|successStructure|errorStructure|basicHeaders|requirements)
9
+ * @param {*} params.value - Value to set when action is 'set'
10
+ * @param {boolean} params.forceOverwrite - Force overwrite array values when action is 'set' and value is array (default: false)
11
+ * @param {string} params.headerName - Header name to delete when action is 'delete'
12
+ * @param {string} params.requirement - Requirement content to delete when action is 'delete'
13
+ * @param {Object} config - Server configuration
14
+ * @param {Function} saveConfig - Function to save configuration (required for 'set' and 'delete' actions)
15
+ * @returns {Object} API standards or update result
16
+ */
17
+ async function api_standards(params, config, saveConfig) {
18
+ const { action, key, value, forceOverwrite = false, headerName, requirement } = params || {};
19
+
20
+ if (!action) {
21
+ throw new Error('Missing action parameter. Must be "get", "set", or "delete"');
22
+ }
23
+
24
+ if (action === 'get') {
25
+ try {
26
+ // 从配置文件的 api_standards 字段中获取标准,如果没有则使用默认值
27
+ const apiStandards = config?.api_standards || {
28
+ interfaceType: 'restful',
29
+ successStructure: {
30
+ code: 'number',
31
+ message: 'string',
32
+ data: 'object|array',
33
+ timestamp: 'string'
34
+ },
35
+ errorStructure: {
36
+ code: 'number',
37
+ message: 'string',
38
+ error: 'string',
39
+ timestamp: 'string'
40
+ },
41
+ basicHeaders: {
42
+ 'Content-Type': 'application/json',
43
+ 'Accept': 'application/json',
44
+ 'Authorization': 'Bearer token',
45
+ 'X-Request-ID': 'string'
46
+ },
47
+ requirements: [
48
+ 'Unified response format',
49
+ 'Error code standards',
50
+ 'Parameter validation',
51
+ 'API documentation'
52
+ ]
53
+ };
54
+
55
+ return apiStandards;
56
+ } catch (err) {
57
+ throw new Error(`Failed to get API standards: ${err.message}`);
58
+ }
59
+ } else if (action === 'set') {
60
+ if (!key) {
61
+ throw new Error('Missing key parameter for set action');
62
+ }
63
+
64
+ if (!['interfaceType', 'successStructure', 'errorStructure', 'basicHeaders', 'requirements'].includes(key)) {
65
+ throw new Error('Invalid key. Must be one of: interfaceType, successStructure, errorStructure, basicHeaders, requirements');
66
+ }
67
+
68
+ if (typeof value !== 'string' && !Array.isArray(value)) {
69
+ throw new Error('Value must be a string or array');
70
+ }
71
+
72
+ if (!saveConfig) {
73
+ throw new Error('saveConfig function is required for set action');
74
+ }
75
+
76
+ try {
77
+ // 确保 config.api_standards 存在
78
+ if (!config.api_standards) {
79
+ config.api_standards = {};
80
+ }
81
+
82
+ // 处理数组类型的合并逻辑
83
+ if (Array.isArray(value) && !forceOverwrite) {
84
+ // 如果 forceOverwrite 为 false,则合并数组而不是覆盖
85
+ if (!config.api_standards[key]) {
86
+ config.api_standards[key] = [];
87
+ }
88
+
89
+ // 确保现有值是数组
90
+ if (!Array.isArray(config.api_standards[key])) {
91
+ config.api_standards[key] = [];
92
+ }
93
+
94
+ // 合并数组,去重
95
+ const existingArray = config.api_standards[key];
96
+ const newArray = [...new Set([...existingArray, ...value])];
97
+ config.api_standards[key] = newArray;
98
+ } else {
99
+ // 直接覆盖
100
+ config.api_standards[key] = value;
101
+ }
102
+
103
+ // 保存配置
104
+ const saved = saveConfig(config);
105
+ if (!saved) {
106
+ throw new Error('Failed to save configuration');
107
+ }
108
+
109
+ return {
110
+ success: true,
111
+ message: `Successfully updated ${key}`,
112
+ updatedField: key,
113
+ newValue: config.api_standards[key],
114
+ forceOverwrite: forceOverwrite,
115
+ timestamp: new Date().toISOString()
116
+ };
117
+ } catch (err) {
118
+ throw new Error(`Failed to update API standards: ${err.message}`);
119
+ }
120
+ } else if (action === 'delete') {
121
+ if (!headerName && !requirement) {
122
+ throw new Error('Missing headerName or requirement parameter for delete action');
123
+ }
124
+
125
+ if (headerName && requirement) {
126
+ throw new Error('Cannot delete both header and requirement at the same time. Please specify either headerName or requirement');
127
+ }
128
+
129
+ if (!saveConfig) {
130
+ throw new Error('saveConfig function is required for delete action');
131
+ }
132
+
133
+ try {
134
+ // 确保 config.api_standards 存在
135
+ if (!config.api_standards) {
136
+ config.api_standards = {};
137
+ }
138
+
139
+ // 删除 header
140
+ if (headerName) {
141
+ // 确保 basicHeaders 存在
142
+ if (!config.api_standards.basicHeaders) {
143
+ config.api_standards.basicHeaders = {};
144
+ }
145
+
146
+ // 删除指定的 header
147
+ if (config.api_standards.basicHeaders.hasOwnProperty(headerName)) {
148
+ delete config.api_standards.basicHeaders[headerName];
149
+
150
+ // 保存配置
151
+ const saved = saveConfig(config);
152
+ if (!saved) {
153
+ throw new Error('Failed to save configuration');
154
+ }
155
+
156
+ return {
157
+ success: true,
158
+ message: `Successfully deleted header: ${headerName}`,
159
+ deletedHeader: headerName,
160
+ timestamp: new Date().toISOString()
161
+ };
162
+ } else {
163
+ throw new Error(`Header '${headerName}' not found`);
164
+ }
165
+ }
166
+
167
+ // 删除 requirement
168
+ if (requirement) {
169
+ // 确保 requirements 存在
170
+ if (!config.api_standards.requirements) {
171
+ config.api_standards.requirements = [];
172
+ }
173
+
174
+ // 查找并删除指定的 requirement
175
+ const requirementIndex = config.api_standards.requirements.indexOf(requirement);
176
+ if (requirementIndex !== -1) {
177
+ config.api_standards.requirements.splice(requirementIndex, 1);
178
+
179
+ // 保存配置
180
+ const saved = saveConfig(config);
181
+ if (!saved) {
182
+ throw new Error('Failed to save configuration');
183
+ }
184
+
185
+ return {
186
+ success: true,
187
+ message: `Successfully deleted requirement: ${requirement}`,
188
+ deletedRequirement: requirement,
189
+ timestamp: new Date().toISOString()
190
+ };
191
+ } else {
192
+ throw new Error(`Requirement '${requirement}' not found`);
193
+ }
194
+ }
195
+ } catch (err) {
196
+ throw new Error(`Failed to delete: ${err.message}`);
197
+ }
198
+ } else {
199
+ throw new Error('Invalid action. Must be "get", "set", or "delete"');
200
+ }
201
+ }
202
+
203
+ module.exports = api_standards;
@@ -0,0 +1,139 @@
1
+ const fs = require('fs-extra');
2
+ const path = require('path');
3
+
4
+ /**
5
+ * Development standards tool - get, set or delete development standards
6
+ * @param {Object} params - Parameters
7
+ * @param {string} params.action - Action to perform ('get', 'set', or 'delete')
8
+ * @param {Array} params.standards - Array of development standards (required for 'set' action)
9
+ * @param {boolean} params.forceOverwrite - Force overwrite array values when action is 'set' and value is array (default: false)
10
+ * @param {string} params.standard - Standard content to delete when action is 'delete'
11
+ * @param {Object} config - Server configuration
12
+ * @param {Function} saveConfig - Function to save configuration (required for 'set' and 'delete' actions)
13
+ * @returns {Array|Object} Development standards array or update result
14
+ */
15
+ async function development_standards(params, config, saveConfig) {
16
+ const { action, standards, forceOverwrite = false, standard } = params || {};
17
+
18
+ if (!action) {
19
+ throw new Error('Missing action parameter. Must be "get", "set", or "delete"');
20
+ }
21
+
22
+ if (action === 'get') {
23
+ try {
24
+ // 从配置文件的 development_standards 字段中获取标准,如果没有则使用默认值
25
+ const developmentStandards = config?.development_standards || [
26
+ 'Use 2 spaces for indentation',
27
+ 'Use single quotes instead of double quotes',
28
+ 'Use camelCase for functions and variables',
29
+ 'Use PascalCase for class names',
30
+ 'Use UPPER_SNAKE_CASE for constants',
31
+ 'Use kebab-case for file names',
32
+ 'Keep lines under 100 characters',
33
+ 'Keep functions under 50 lines',
34
+ 'Keep files under 300 lines',
35
+ 'Use JSDoc format for code comments',
36
+ 'Use OpenAPI/Swagger for API documentation',
37
+ 'Include README.md in project root',
38
+ 'Include CHANGELOG.md in project root',
39
+ 'Separate production and development dependencies',
40
+ 'Use environment variables for sensitive information',
41
+ 'Validate input and output data',
42
+ 'Prevent XSS attacks',
43
+ 'Enable CORS for cross-origin support',
44
+ 'Use Redis or memory cache',
45
+ 'Enable Gzip or Brotli compression',
46
+ 'Monitor application metrics',
47
+ 'Use structured logging'
48
+ ];
49
+
50
+ return developmentStandards;
51
+ } catch (err) {
52
+ throw new Error(`Failed to get development standards: ${err.message}`);
53
+ }
54
+ } else if (action === 'set') {
55
+ if (!Array.isArray(standards)) {
56
+ throw new Error('Standards must be an array for set action');
57
+ }
58
+
59
+ if (!saveConfig) {
60
+ throw new Error('saveConfig function is required for set action');
61
+ }
62
+
63
+ try {
64
+ // 更新配置
65
+ if (!config.development_standards) {
66
+ config.development_standards = [];
67
+ }
68
+
69
+ // 处理数组类型的合并逻辑
70
+ if (!forceOverwrite) {
71
+ // 如果 forceOverwrite 为 false,则合并数组而不是覆盖
72
+ const existingArray = config.development_standards;
73
+ const newArray = [...new Set([...existingArray, ...standards])];
74
+ config.development_standards = newArray;
75
+ } else {
76
+ // 直接覆盖
77
+ config.development_standards = standards;
78
+ }
79
+
80
+ // 保存配置
81
+ const saved = saveConfig(config);
82
+ if (!saved) {
83
+ throw new Error('Failed to save configuration');
84
+ }
85
+
86
+ return {
87
+ success: true,
88
+ message: 'Successfully updated development standards',
89
+ updatedCount: config.development_standards.length,
90
+ forceOverwrite: forceOverwrite,
91
+ timestamp: new Date().toISOString()
92
+ };
93
+ } catch (err) {
94
+ throw new Error(`Failed to update development standards: ${err.message}`);
95
+ }
96
+ } else if (action === 'delete') {
97
+ if (!standard) {
98
+ throw new Error('Missing standard parameter for delete action');
99
+ }
100
+
101
+ if (!saveConfig) {
102
+ throw new Error('saveConfig function is required for delete action');
103
+ }
104
+
105
+ try {
106
+ // 确保 config.development_standards 存在
107
+ if (!config.development_standards) {
108
+ config.development_standards = [];
109
+ }
110
+
111
+ // 查找并删除指定的 standard
112
+ const standardIndex = config.development_standards.indexOf(standard);
113
+ if (standardIndex !== -1) {
114
+ config.development_standards.splice(standardIndex, 1);
115
+
116
+ // 保存配置
117
+ const saved = saveConfig(config);
118
+ if (!saved) {
119
+ throw new Error('Failed to save configuration');
120
+ }
121
+
122
+ return {
123
+ success: true,
124
+ message: `Successfully deleted standard: ${standard}`,
125
+ deletedStandard: standard,
126
+ timestamp: new Date().toISOString()
127
+ };
128
+ } else {
129
+ throw new Error(`Standard '${standard}' not found`);
130
+ }
131
+ } catch (err) {
132
+ throw new Error(`Failed to delete standard: ${err.message}`);
133
+ }
134
+ } else {
135
+ throw new Error('Invalid action. Must be "get", "set", or "delete"');
136
+ }
137
+ }
138
+
139
+ module.exports = development_standards;
@@ -0,0 +1,87 @@
1
+ const path = require('path');
2
+ const fs = require('fs-extra');
3
+
4
+ /**
5
+ * Project information tool - get or set project information
6
+ * @param {Object} params - Parameters
7
+ * @param {string} params.action - Action to perform ('get' or 'set')
8
+ * @param {string} params.key - Key to update when action is 'set' (projectName|developmentLanguage|basicInfo)
9
+ * @param {*} params.value - Value to set when action is 'set'
10
+ * @param {Object} config - Server configuration
11
+ * @param {Function} saveConfig - Function to save configuration (required for 'set' action)
12
+ * @returns {Object} Project information or update result
13
+ */
14
+ async function project_info(params, config, saveConfig) {
15
+ const { action, key, value } = params || {};
16
+
17
+ if (!action) {
18
+ throw new Error('Missing action parameter. Must be "get" or "set"');
19
+ }
20
+
21
+ if (action === 'get') {
22
+ try {
23
+ // 从配置文件的 project_info 字段中获取项目信息,如果没有则使用默认值
24
+ const projectInfo = config?.project_info || '';
25
+ const projectName = projectInfo.projectName || '';
26
+ const developmentLanguage = projectInfo.developmentLanguage || '';
27
+ const basicInfo = projectInfo.basicInfo || '';
28
+
29
+ return {
30
+ // 项目名称
31
+ projectName: projectName,
32
+
33
+ // 开发语言
34
+ developmentLanguage: developmentLanguage,
35
+
36
+ // 基本信息
37
+ basicInfo: basicInfo,
38
+
39
+ timestamp: new Date().toISOString()
40
+ };
41
+ } catch (err) {
42
+ throw new Error(`Failed to get project information: ${err.message}`);
43
+ }
44
+ } else if (action === 'set') {
45
+ if (!key) {
46
+ throw new Error('Missing key parameter for set action');
47
+ }
48
+
49
+ if (!['projectName', 'developmentLanguage', 'basicInfo'].includes(key)) {
50
+ throw new Error('Invalid key. Must be one of: projectName, developmentLanguage, basicInfo');
51
+ }
52
+
53
+ if (!saveConfig) {
54
+ throw new Error('saveConfig function is required for set action');
55
+ }
56
+
57
+ try {
58
+ // 确保 config.project_info 存在
59
+ if (!config.project_info) {
60
+ config.project_info = {};
61
+ }
62
+
63
+ // 更新指定字段
64
+ config.project_info[key] = value;
65
+
66
+ // 保存配置
67
+ const saved = saveConfig(config);
68
+ if (!saved) {
69
+ throw new Error('Failed to save configuration');
70
+ }
71
+
72
+ return {
73
+ success: true,
74
+ message: `Successfully updated ${key}`,
75
+ updatedField: key,
76
+ newValue: value,
77
+ timestamp: new Date().toISOString()
78
+ };
79
+ } catch (err) {
80
+ throw new Error(`Failed to update project info: ${err.message}`);
81
+ }
82
+ } else {
83
+ throw new Error('Invalid action. Must be "get" or "set"');
84
+ }
85
+ }
86
+
87
+ module.exports = project_info;