smart-image-scraper-mcp 2.5.1 → 2.5.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.js +16 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "smart-image-scraper-mcp",
3
- "version": "2.5.1",
3
+ "version": "2.5.2",
4
4
  "description": "全网智能图片抓取 MCP 服务器 - 支持 Bing/Google 图片搜索、验证和下载",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
package/src/index.js CHANGED
@@ -26,8 +26,12 @@ import logger from './infrastructure/logger.js';
26
26
  import { gracefulShutdown } from './infrastructure/gracefulShutdown.js';
27
27
  import { healthChecker } from './infrastructure/healthCheck.js';
28
28
  import { metrics } from './infrastructure/metrics.js';
29
+ import { searchCache, validationCache } from './infrastructure/cache.js';
29
30
  import config from './config/index.js';
30
31
 
32
+ // 请求计数器,用于定期清理
33
+ let requestCount = 0;
34
+
31
35
  // 从 package.json 读取版本号
32
36
  const require = createRequire(import.meta.url);
33
37
  const packageJson = require('../package.json');
@@ -269,7 +273,16 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
269
273
  const totalTime = Date.now() - requestStartTime;
270
274
  logger.info(`[MCP] 请求完成: ${totalTime}ms, requestId=${result.requestId}`);
271
275
 
272
- return {
276
+ // 每3个请求清理一次缓存,避免内存累积
277
+ requestCount++;
278
+ if (requestCount >= 3) {
279
+ searchCache.clear();
280
+ validationCache.clear();
281
+ requestCount = 0;
282
+ logger.info('[MCP] 缓存已清理');
283
+ }
284
+
285
+ const response = {
273
286
  content: [
274
287
  {
275
288
  type: 'text',
@@ -277,6 +290,8 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
277
290
  },
278
291
  ],
279
292
  };
293
+
294
+ return response;
280
295
  } catch (innerError) {
281
296
  // 记录失败指标
282
297
  metrics.recordSearch(source, false, Date.now() - startTime);