@liangshanli/mcp-server-project-standards 3.0.1 → 3.0.2
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/utils/api_debug.js +7 -0
- package/src/utils/api_execute.js +34 -14
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@liangshanli/mcp-server-project-standards",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.2",
|
|
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": {
|
package/src/utils/api_debug.js
CHANGED
|
@@ -334,6 +334,7 @@ async function api_debug(params, config, saveConfig) {
|
|
|
334
334
|
};
|
|
335
335
|
}
|
|
336
336
|
} else {
|
|
337
|
+
// 失败时也要返回响应数据
|
|
337
338
|
return {
|
|
338
339
|
success: false,
|
|
339
340
|
message: `Failed to execute API: ${url}`,
|
|
@@ -343,6 +344,12 @@ async function api_debug(params, config, saveConfig) {
|
|
|
343
344
|
headers: finalHeaders,
|
|
344
345
|
body: requestBody
|
|
345
346
|
},
|
|
347
|
+
response: response ? {
|
|
348
|
+
status: response.status,
|
|
349
|
+
statusText: response.statusText,
|
|
350
|
+
headers: Object.fromEntries(response.headers.entries()),
|
|
351
|
+
data: responseData
|
|
352
|
+
} : undefined,
|
|
346
353
|
error: error || (response ? `HTTP ${response.status}: ${response.statusText}` : 'Request failed'),
|
|
347
354
|
timestamp: new Date().toISOString()
|
|
348
355
|
};
|
package/src/utils/api_execute.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
const { loadApiConfig, getAllowedMethods } = require('./api_common');
|
|
2
|
+
const https = require('https');
|
|
2
3
|
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
4
|
+
// 为 HTTPS 请求创建跳过证书验证的 agent
|
|
5
|
+
const httpsAgent = new https.Agent({
|
|
6
|
+
rejectUnauthorized: false
|
|
7
|
+
});
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* API 执行工具 - 通过索引执行已配置的API
|
|
@@ -95,21 +96,39 @@ async function api_execute(params, config, saveConfig) {
|
|
|
95
96
|
|
|
96
97
|
// 执行请求
|
|
97
98
|
const startTime = Date.now();
|
|
98
|
-
|
|
99
|
-
const endTime = Date.now();
|
|
100
|
-
|
|
101
|
-
// 处理响应
|
|
99
|
+
let response;
|
|
102
100
|
let responseData;
|
|
103
|
-
|
|
101
|
+
let error = null;
|
|
104
102
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
103
|
+
try {
|
|
104
|
+
// 为 HTTPS 请求添加 agent 以跳过证书验证
|
|
105
|
+
if (fullUrl.startsWith('https')) {
|
|
106
|
+
requestOptions.agent = httpsAgent;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
response = await fetch(fullUrl, requestOptions);
|
|
110
|
+
|
|
111
|
+
// 处理响应
|
|
112
|
+
const contentType = response.headers.get('content-type') || '';
|
|
113
|
+
|
|
114
|
+
if (contentType.includes('application/json')) {
|
|
115
|
+
responseData = await response.json();
|
|
116
|
+
} else {
|
|
117
|
+
responseData = await response.text();
|
|
118
|
+
}
|
|
119
|
+
} catch (fetchError) {
|
|
120
|
+
error = fetchError.message;
|
|
121
|
+
throw new Error(`Failed to execute API request: ${error}`);
|
|
109
122
|
}
|
|
110
123
|
|
|
124
|
+
const endTime = Date.now();
|
|
125
|
+
|
|
126
|
+
// 判断请求是否成功(HTTP 状态码 200-299 为成功)
|
|
127
|
+
const isHttpSuccess = response.status >= 200 && response.status < 300;
|
|
128
|
+
const success = isHttpSuccess;
|
|
129
|
+
|
|
111
130
|
return {
|
|
112
|
-
success:
|
|
131
|
+
success: success,
|
|
113
132
|
index: index,
|
|
114
133
|
api: {
|
|
115
134
|
url: apiConfig.url,
|
|
@@ -129,6 +148,7 @@ async function api_execute(params, config, saveConfig) {
|
|
|
129
148
|
headers: Object.fromEntries(response.headers.entries()),
|
|
130
149
|
data: responseData
|
|
131
150
|
},
|
|
151
|
+
error: success ? undefined : (error || `HTTP ${response.status}: ${response.statusText}`),
|
|
132
152
|
timing: {
|
|
133
153
|
duration: endTime - startTime,
|
|
134
154
|
timestamp: new Date().toISOString()
|