smart-image-scraper-mcp 2.11.2 → 2.11.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/package.json
CHANGED
|
@@ -9,24 +9,20 @@ import https from 'https';
|
|
|
9
9
|
import config from '../config/index.js';
|
|
10
10
|
import logger from './logger.js';
|
|
11
11
|
|
|
12
|
-
// HTTP
|
|
13
|
-
//
|
|
12
|
+
// HTTP 连接配置 - 禁用 keepAlive 避免连续调用时 socket 耗尽
|
|
13
|
+
// MCP 每次调用独立,keepalive 复用收益小,反而导致连接池堵塞
|
|
14
14
|
const httpAgent = new http.Agent({
|
|
15
|
-
keepAlive:
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
scheduling: 'lifo', // 后进先出,优先使用最近的连接
|
|
20
|
-
timeout: 10000, // 空闲连接10秒后关闭
|
|
15
|
+
keepAlive: false, // 禁用 Keep-Alive,用完立即释放
|
|
16
|
+
maxSockets: 15, // 最大并发连接数
|
|
17
|
+
maxFreeSockets: 0, // 不保留空闲连接
|
|
18
|
+
scheduling: 'fifo', // 先进先出,公平分配
|
|
21
19
|
});
|
|
22
20
|
|
|
23
21
|
const httpsAgent = new https.Agent({
|
|
24
|
-
keepAlive:
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
scheduling: 'lifo',
|
|
29
|
-
timeout: 10000, // 空闲连接10秒后关闭
|
|
22
|
+
keepAlive: false, // 禁用 Keep-Alive
|
|
23
|
+
maxSockets: 15,
|
|
24
|
+
maxFreeSockets: 0,
|
|
25
|
+
scheduling: 'fifo',
|
|
30
26
|
rejectUnauthorized: false, // 允许自签名证书
|
|
31
27
|
});
|
|
32
28
|
|
|
@@ -47,7 +43,7 @@ const httpClient = axios.create({
|
|
|
47
43
|
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
|
|
48
44
|
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
|
|
49
45
|
'Accept-Encoding': 'gzip, deflate, br',
|
|
50
|
-
'Connection': '
|
|
46
|
+
'Connection': 'close', // 用完关闭,避免 socket 泛滥
|
|
51
47
|
},
|
|
52
48
|
maxRedirects: 5,
|
|
53
49
|
validateStatus: (status) => status < 500,
|
|
@@ -134,8 +134,11 @@ class Logger {
|
|
|
134
134
|
|
|
135
135
|
const formatted = this._format(level, message, data);
|
|
136
136
|
|
|
137
|
-
// 输出到 stderr
|
|
138
|
-
|
|
137
|
+
// 输出到 stderr(使用 process.stderr.write 避免 console.error 阻塞 MCP stdio)
|
|
138
|
+
// 仅输出 WARN 及以上级别到 stderr,减少 IO 压力
|
|
139
|
+
if (level >= LogLevel.WARN) {
|
|
140
|
+
process.stderr.write(formatted + '\n');
|
|
141
|
+
}
|
|
139
142
|
|
|
140
143
|
// 输出到文件(异步写入,避免阻塞事件循环)
|
|
141
144
|
if (this.logFile) {
|
|
@@ -204,7 +207,7 @@ class Logger {
|
|
|
204
207
|
}
|
|
205
208
|
}
|
|
206
209
|
|
|
207
|
-
//
|
|
208
|
-
const defaultLevel = process.env.
|
|
210
|
+
// MCP 模式下默认 WARN 级别,避免 stderr 输出阻塞 stdio 通信
|
|
211
|
+
const defaultLevel = LogLevel[process.env.LOG_LEVEL?.toUpperCase()] ?? LogLevel.WARN;
|
|
209
212
|
export const logger = new Logger({ level: defaultLevel });
|
|
210
213
|
export default logger;
|