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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "smart-image-scraper-mcp",
3
- "version": "2.11.2",
3
+ "version": "2.11.4",
4
4
  "description": "全网智能图片抓取 MCP 服务器 - 支持 Bing/Google 图片搜索、验证和下载",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -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 连接池配置 - 复用 TCP 连接,大幅提升性能
13
- // 添加 timeout 确保空闲连接被及时释放,避免连接池耗尽
12
+ // HTTP 连接配置 - 禁用 keepAlive 避免连续调用时 socket 耗尽
13
+ // MCP 每次调用独立,keepalive 复用收益小,反而导致连接池堵塞
14
14
  const httpAgent = new http.Agent({
15
- keepAlive: true, // 启用 Keep-Alive
16
- keepAliveMsecs: 1000, // Keep-Alive 探测间隔
17
- maxSockets: 20, // 降低最大并发连接数,避免资源耗尽
18
- maxFreeSockets: 5, // 降低最大空闲连接数
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: true,
25
- keepAliveMsecs: 1000,
26
- maxSockets: 20, // 降低最大并发连接数
27
- maxFreeSockets: 5, // 降低最大空闲连接数
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': 'keep-alive', // 保持连接
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
- console.error(formatted);
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.NODE_ENV === 'production' ? LogLevel.INFO : LogLevel.DEBUG;
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;