@liangshanli/mcp-server-project-standards 2.0.7 → 2.1.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": "2.0.7",
3
+ "version": "2.1.1",
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": {
@@ -11,6 +11,7 @@ const api_login = require('./utils/api_login');
11
11
  const api_debug = require('./utils/api_debug');
12
12
  const api_config = require('./utils/api_config');
13
13
  const api_help = require('./utils/api_help');
14
+ const api_execute = require('./utils/api_execute');
14
15
 
15
16
  // Get configuration from file or environment
16
17
  const getConfig = () => {
@@ -186,6 +187,12 @@ class ProjectStandardsMCPServer {
186
187
  return result;
187
188
  }
188
189
 
190
+ // API execute tool
191
+ async api_execute(params) {
192
+ const result = await api_execute(params, this.config, saveConfig);
193
+ return result;
194
+ }
195
+
189
196
 
190
197
 
191
198
 
@@ -631,21 +638,68 @@ class ProjectStandardsMCPServer {
631
638
  }
632
639
  });
633
640
 
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
- }
641
+ // API Help Tool
642
+ tools.push({
643
+ name: 'api_help',
644
+ 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',
645
+ inputSchema: {
646
+ type: 'object',
647
+ properties: {
648
+ tool: {
649
+ type: 'string',
650
+ description: 'Specific tool name to get help for (optional: api_debug, api_login, api_config)',
651
+ examples: ['api_debug', 'api_login', 'api_config']
646
652
  }
647
653
  }
648
- });
654
+ }
655
+ });
656
+
657
+ // API Execute Tool
658
+ tools.push({
659
+ name: 'api_execute',
660
+ description: 'Execute API requests by index from configured API list. Examples: execute API at index 0, execute with overrides {"method":"POST","body":{"key":"value"}}',
661
+ inputSchema: {
662
+ type: 'object',
663
+ properties: {
664
+ index: {
665
+ type: 'number',
666
+ description: 'Index of the API to execute from the configured list (required)',
667
+ minimum: 0
668
+ },
669
+ overrides: {
670
+ type: 'object',
671
+ description: 'Optional parameters to override the configured API settings',
672
+ properties: {
673
+ url: {
674
+ type: 'string',
675
+ description: 'Override the API URL'
676
+ },
677
+ method: {
678
+ type: 'string',
679
+ enum: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH'],
680
+ description: 'Override the HTTP method'
681
+ },
682
+ headers: {
683
+ type: 'object',
684
+ description: 'Override or add request headers'
685
+ },
686
+ query: {
687
+ type: 'object',
688
+ description: 'Override query parameters'
689
+ },
690
+ body: {
691
+ description: 'Override request body'
692
+ },
693
+ contentType: {
694
+ type: 'string',
695
+ description: 'Override content type'
696
+ }
697
+ }
698
+ }
699
+ },
700
+ required: ['index']
701
+ }
702
+ });
649
703
 
650
704
  // API Config Tool
651
705
  tools.push({
@@ -188,7 +188,8 @@ async function api_config(params, config, saveConfig) {
188
188
 
189
189
  return {
190
190
  success: true,
191
- message: `Successfully updated existing API: ${api.url}`,
191
+ message: `Successfully updated existing API: ${api.url}. You can now execute it using: api_execute with index ${existingIndex}`,
192
+ index: existingIndex,
192
193
  api: apiDebugConfig.list[existingIndex],
193
194
  timestamp: new Date().toISOString()
194
195
  };
@@ -202,7 +203,8 @@ async function api_config(params, config, saveConfig) {
202
203
 
203
204
  return {
204
205
  success: true,
205
- message: `Successfully added new API: ${api.url}`,
206
+ message: `Successfully added new API: ${api.url}. You can now execute it using: api_execute with index ${apiDebugConfig.list.length - 1}`,
207
+ index: apiDebugConfig.list.length - 1,
206
208
  api: api,
207
209
  timestamp: new Date().toISOString()
208
210
  };
@@ -0,0 +1,138 @@
1
+ const { loadApiConfig, getAllowedMethods } = require('./api_common');
2
+
3
+ /**
4
+ * API 执行工具 - 通过索引执行已配置的API
5
+ * @param {Object} params - 参数
6
+ * @param {number} params.index - API索引(必需)
7
+ * @param {Object} params.overrides - 覆盖参数(可选)
8
+ * @param {string} params.overrides.url - 覆盖URL
9
+ * @param {string} params.overrides.method - 覆盖HTTP方法
10
+ * @param {Object} params.overrides.headers - 覆盖请求头
11
+ * @param {Object} params.overrides.query - 覆盖查询参数
12
+ * @param {*} params.overrides.body - 覆盖请求体
13
+ * @param {string} params.overrides.contentType - 覆盖内容类型
14
+ * @param {Object} config - 服务器配置
15
+ * @param {Function} saveConfig - 保存配置函数
16
+ * @returns {Object} API执行结果
17
+ */
18
+ async function api_execute(params, config, saveConfig) {
19
+ const { index, overrides = {} } = params || {};
20
+
21
+ if (typeof index !== 'number' || index < 0) {
22
+ throw new Error('Invalid index parameter. Must be a non-negative number');
23
+ }
24
+
25
+ try {
26
+ // 加载API配置
27
+ const apiDebugConfig = loadApiConfig();
28
+
29
+ if (!apiDebugConfig.list || !Array.isArray(apiDebugConfig.list)) {
30
+ throw new Error('No API list found in configuration');
31
+ }
32
+
33
+ if (index >= apiDebugConfig.list.length) {
34
+ throw new Error(`API index ${index} is out of range. Available APIs: 0-${apiDebugConfig.list.length - 1}`);
35
+ }
36
+
37
+ // 获取API配置
38
+ const apiConfig = apiDebugConfig.list[index];
39
+
40
+ // 合并配置和覆盖参数
41
+ const finalConfig = {
42
+ url: overrides.url || apiConfig.url,
43
+ method: overrides.method || apiConfig.method || 'GET',
44
+ headers: { ...apiDebugConfig.headers, ...apiConfig.header, ...overrides.headers },
45
+ query: overrides.query || apiConfig.query,
46
+ body: overrides.body || apiConfig.body,
47
+ contentType: overrides.contentType || apiConfig.contentType
48
+ };
49
+
50
+ // 验证HTTP方法
51
+ const allowedMethods = getAllowedMethods();
52
+ if (!allowedMethods.includes(finalConfig.method.toUpperCase())) {
53
+ throw new Error(`HTTP method '${finalConfig.method}' is not allowed. Allowed methods: ${allowedMethods.join(', ')}`);
54
+ }
55
+
56
+ // 构建完整URL
57
+ let fullUrl;
58
+ if (finalConfig.url.startsWith('http://') || finalConfig.url.startsWith('https://')) {
59
+ fullUrl = finalConfig.url;
60
+ } else {
61
+ fullUrl = apiDebugConfig.baseUrl + finalConfig.url;
62
+ }
63
+
64
+ // 添加查询参数
65
+ if (finalConfig.query && Object.keys(finalConfig.query).length > 0) {
66
+ const queryString = new URLSearchParams(finalConfig.query).toString();
67
+ fullUrl += (fullUrl.includes('?') ? '&' : '?') + queryString;
68
+ }
69
+
70
+ // 准备请求选项
71
+ const requestOptions = {
72
+ method: finalConfig.method.toUpperCase(),
73
+ headers: finalConfig.headers
74
+ };
75
+
76
+ // 处理请求体
77
+ if (finalConfig.body && ['POST', 'PUT', 'PATCH'].includes(finalConfig.method.toUpperCase())) {
78
+ if (typeof finalConfig.body === 'object') {
79
+ requestOptions.body = JSON.stringify(finalConfig.body);
80
+ if (!finalConfig.headers['Content-Type']) {
81
+ requestOptions.headers['Content-Type'] = 'application/json';
82
+ }
83
+ } else {
84
+ requestOptions.body = finalConfig.body;
85
+ if (finalConfig.contentType && !finalConfig.headers['Content-Type']) {
86
+ requestOptions.headers['Content-Type'] = finalConfig.contentType;
87
+ }
88
+ }
89
+ }
90
+
91
+ // 执行请求
92
+ const startTime = Date.now();
93
+ const response = await fetch(fullUrl, requestOptions);
94
+ const endTime = Date.now();
95
+
96
+ // 处理响应
97
+ let responseData;
98
+ const contentType = response.headers.get('content-type') || '';
99
+
100
+ if (contentType.includes('application/json')) {
101
+ responseData = await response.json();
102
+ } else {
103
+ responseData = await response.text();
104
+ }
105
+
106
+ return {
107
+ success: true,
108
+ index: index,
109
+ api: {
110
+ url: apiConfig.url,
111
+ method: apiConfig.method || 'GET',
112
+ description: apiConfig.description
113
+ },
114
+ request: {
115
+ url: fullUrl,
116
+ method: finalConfig.method,
117
+ headers: finalConfig.headers,
118
+ body: finalConfig.body,
119
+ query: finalConfig.query
120
+ },
121
+ response: {
122
+ status: response.status,
123
+ statusText: response.statusText,
124
+ headers: Object.fromEntries(response.headers.entries()),
125
+ data: responseData
126
+ },
127
+ timing: {
128
+ duration: endTime - startTime,
129
+ timestamp: new Date().toISOString()
130
+ }
131
+ };
132
+
133
+ } catch (err) {
134
+ throw new Error(`Failed to execute API at index ${index}: ${err.message}`);
135
+ }
136
+ }
137
+
138
+ module.exports = api_execute;
@@ -1,10 +1,10 @@
1
1
  /**
2
- * API 帮助工具 - 返回API调试工具的详细说明和示例
3
- * @param {Object} params - 参数
4
- * @param {string} params.tool - 要查看的工具名称(可选,默认返回所有工具)
5
- * @param {Object} config - 服务器配置
6
- * @param {Function} saveConfig - 保存配置函数
7
- * @returns {Object} 工具说明和示例
2
+ * API Help Tool - Returns detailed documentation and examples for API debugging tools
3
+ * @param {Object} params - Parameters
4
+ * @param {string} params.tool - Tool name to view (optional, returns all tools by default)
5
+ * @param {Object} config - Server configuration
6
+ * @param {Function} saveConfig - Save configuration function
7
+ * @returns {Object} Tool documentation and examples
8
8
  */
9
9
  async function api_help(params, config, saveConfig) {
10
10
  const { tool } = params || {};
@@ -12,25 +12,25 @@ async function api_help(params, config, saveConfig) {
12
12
  const helpContent = {
13
13
  api_debug: {
14
14
  name: 'api_debug',
15
- description: 'API调试工具 - 直接执行API请求',
16
- usage: '直接传入URL和参数即可执行API请求,无需复杂的action参数',
15
+ description: 'API Debug Tool - Direct API request execution',
16
+ usage: 'Directly pass URL and parameters to execute API requests without complex action parameters',
17
17
  supportedFormats: [
18
- 'JSON对象: {"username": "admin", "password": "123456"}',
19
- '表单数据: "username=admin&password=123456"',
20
- '纯文本: "Hello World"',
18
+ 'JSON Object: {"username": "admin", "password": "123456"}',
19
+ 'Form Data: "username=admin&password=123456"',
20
+ 'Plain Text: "Hello World"',
21
21
  'XML: "<user><name>John</name><email>john@example.com</email></user>"',
22
22
  'HTML: "<html><body>Content</body></html>"'
23
23
  ],
24
24
  autoContentTypeDetection: {
25
- 'JSON对象': 'application/json',
26
- '表单数据': 'application/x-www-form-urlencoded',
25
+ 'JSON Object': 'application/json',
26
+ 'Form Data': 'application/x-www-form-urlencoded',
27
27
  'XML': 'application/xml',
28
28
  'HTML': 'text/html',
29
- '纯文本': 'text/plain'
29
+ 'Plain Text': 'text/plain'
30
30
  },
31
31
  examples: [
32
32
  {
33
- description: '简单GET请求',
33
+ description: 'Simple GET request',
34
34
  request: {
35
35
  url: '/api/users',
36
36
  method: 'GET',
@@ -38,7 +38,7 @@ async function api_help(params, config, saveConfig) {
38
38
  }
39
39
  },
40
40
  {
41
- description: 'POST请求带JSON',
41
+ description: 'POST request with JSON body',
42
42
  request: {
43
43
  url: '/api/login',
44
44
  method: 'POST',
@@ -47,7 +47,7 @@ async function api_help(params, config, saveConfig) {
47
47
  }
48
48
  },
49
49
  {
50
- description: 'PUT请求带表单数据',
50
+ description: 'PUT request with form data',
51
51
  request: {
52
52
  url: '/api/users/123',
53
53
  method: 'PUT',
@@ -56,7 +56,7 @@ async function api_help(params, config, saveConfig) {
56
56
  }
57
57
  },
58
58
  {
59
- description: 'DELETE请求带认证',
59
+ description: 'DELETE request with authentication',
60
60
  request: {
61
61
  url: '/api/users/123',
62
62
  method: 'DELETE',
@@ -65,36 +65,36 @@ async function api_help(params, config, saveConfig) {
65
65
  }
66
66
  ],
67
67
  bestPractices: [
68
- '使用相对URL: /api/endpoint 而不是完整URL',
69
- '通过api_config工具设置baseUrl',
70
- '让工具自动检测内容类型,除非有特殊需求',
71
- 'GET请求使用query参数而不是body',
72
- '通过headers参数设置认证信息'
68
+ 'Use relative URLs: /api/endpoint instead of full URLs',
69
+ 'Set baseUrl through api_config tool',
70
+ 'Let the tool auto-detect content type unless you have special needs',
71
+ 'Use query parameters for GET requests instead of body',
72
+ 'Set authentication information through headers parameter'
73
73
  ]
74
74
  },
75
75
  api_login: {
76
76
  name: 'api_login',
77
- description: 'API登录工具 - 使用环境变量进行登录认证',
78
- usage: '无需参数,直接从环境变量获取登录信息',
77
+ description: 'API Login Tool - Authentication using environment variables',
78
+ usage: 'No parameters required, directly gets login information from environment variables',
79
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': '登录接口描述'
80
+ 'API_DEBUG_LOGIN_URL': 'Login API URL (default: /api/login)',
81
+ 'API_DEBUG_LOGIN_METHOD': 'Login request method (default: POST)',
82
+ 'API_DEBUG_LOGIN_BODY': 'Login request body template (supports JSON and string formats)',
83
+ 'API_DEBUG_LOGIN_DESCRIPTION': 'Login API description'
84
84
  },
85
85
  features: [
86
- '自动从环境变量获取登录配置',
87
- '支持JSON和字符串格式的登录体',
88
- '自动提取token并更新Authorization',
89
- '支持自定义baseUrl参数'
86
+ 'Automatically gets login configuration from environment variables',
87
+ 'Supports JSON and string formats for login body',
88
+ 'Automatically extracts token and updates Authorization header',
89
+ 'Supports custom baseUrl parameter'
90
90
  ],
91
91
  examples: [
92
92
  {
93
- description: '基本登录(使用环境变量配置)',
93
+ description: 'Basic login (using environment variable configuration)',
94
94
  request: {}
95
95
  },
96
96
  {
97
- description: '指定baseUrl的登录',
97
+ description: 'Login with specified baseUrl',
98
98
  request: {
99
99
  baseUrl: 'https://api.example.com'
100
100
  }
@@ -103,57 +103,98 @@ async function api_help(params, config, saveConfig) {
103
103
  },
104
104
  api_config: {
105
105
  name: 'api_config',
106
- description: 'API配置管理工具 - 管理全局API配置',
107
- usage: '使用action参数指定操作类型',
106
+ description: 'API Configuration Management Tool - Manage global API configuration',
107
+ usage: 'Use action parameter to specify operation type',
108
108
  actions: {
109
- 'get': '获取当前配置',
110
- 'set': '设置完整配置',
111
- 'updateBaseUrl': '更新基础URL',
112
- 'updateHeaders': '更新请求头',
113
- 'deleteHeader': '删除指定请求头',
114
- 'addApi': '添加API端点',
115
- 'search': '搜索API',
116
- 'list': '列出所有API'
109
+ 'get': 'Get current configuration',
110
+ 'set': 'Set complete configuration',
111
+ 'updateBaseUrl': 'Update base URL',
112
+ 'updateHeaders': 'Update request headers',
113
+ 'deleteHeader': 'Delete specified header',
114
+ 'addApi': 'Add API endpoint',
115
+ 'search': 'Search APIs',
116
+ 'list': 'List all APIs'
117
117
  },
118
118
  examples: [
119
119
  {
120
- description: '获取配置',
120
+ description: 'Get configuration',
121
121
  request: { action: 'get' }
122
122
  },
123
123
  {
124
- description: '更新基础URL',
124
+ description: 'Update base URL',
125
125
  request: {
126
126
  action: 'updateBaseUrl',
127
127
  baseUrl: 'https://api.example.com'
128
128
  }
129
129
  },
130
130
  {
131
- description: '更新请求头',
131
+ description: 'Update request headers',
132
132
  request: {
133
133
  action: 'updateHeaders',
134
134
  headers: { 'Authorization': 'Bearer token123' }
135
135
  }
136
136
  },
137
137
  {
138
- description: '搜索API',
138
+ description: 'Search APIs',
139
139
  request: {
140
140
  action: 'search',
141
141
  keyword: 'user'
142
142
  }
143
143
  },
144
144
  {
145
- description: '添加API端点',
145
+ description: 'Add API endpoint',
146
146
  request: {
147
147
  action: 'addApi',
148
148
  api: {
149
149
  url: '/api/users',
150
150
  method: 'GET',
151
- description: '获取用户列表',
151
+ description: 'Get user list',
152
152
  query: { page: 1, limit: 10 }
153
153
  }
154
154
  }
155
155
  }
156
156
  ]
157
+ },
158
+ api_execute: {
159
+ name: 'api_execute',
160
+ description: 'API Execute Tool - Execute configured APIs by index',
161
+ usage: 'Use index parameter to specify API index, optional overrides parameter to override configuration',
162
+ parameters: {
163
+ index: 'API index (required, non-negative integer)',
164
+ overrides: 'Override parameters (optional object)'
165
+ },
166
+ overrides: {
167
+ url: 'Override API URL',
168
+ method: 'Override HTTP method',
169
+ headers: 'Override or add request headers',
170
+ query: 'Override query parameters',
171
+ body: 'Override request body',
172
+ contentType: 'Override content type'
173
+ },
174
+ examples: [
175
+ {
176
+ description: 'Execute API at index 0',
177
+ request: { index: 0 }
178
+ },
179
+ {
180
+ description: 'Execute API at index 1 with method override',
181
+ request: {
182
+ index: 1,
183
+ overrides: { method: 'POST' }
184
+ }
185
+ },
186
+ {
187
+ description: 'Execute API with body and header overrides',
188
+ request: {
189
+ index: 2,
190
+ overrides: {
191
+ method: 'PUT',
192
+ body: { name: 'New Name' },
193
+ headers: { 'Content-Type': 'application/json' }
194
+ }
195
+ }
196
+ }
197
+ ]
157
198
  }
158
199
  };
159
200
 
@@ -166,13 +207,14 @@ async function api_help(params, config, saveConfig) {
166
207
  } else {
167
208
  return {
168
209
  success: true,
169
- message: 'API调试工具帮助文档',
210
+ message: 'API Debugging Tools Help Documentation',
170
211
  tools: helpContent,
171
212
  quickStart: {
172
- '1. 设置配置': '使用 api_config 工具设置 baseUrl headers',
173
- '2. 登录认证': '使用 api_login 工具进行登录(如果需要)',
174
- '3. 调试API': '使用 api_debug 工具执行API请求',
175
- '4. 查看帮助': '使用 api_help 工具查看详细说明'
213
+ '1. Set Configuration': 'Use api_config tool to set baseUrl and headers',
214
+ '2. Add APIs': 'Use api_config tool with addApi action to add API endpoints',
215
+ '3. Login Authentication': 'Use api_login tool for authentication (if needed)',
216
+ '4. Execute APIs': 'Use api_execute tool to execute APIs by index, or use api_debug tool for direct execution',
217
+ '5. View Help': 'Use api_help tool to view detailed documentation'
176
218
  },
177
219
  timestamp: new Date().toISOString()
178
220
  };