smart-image-scraper-mcp 2.9.1 → 2.9.3

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.9.1",
3
+ "version": "2.9.3",
4
4
  "description": "全网智能图片抓取 MCP 服务器 - 支持 Bing/Google 图片搜索、验证和下载",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
package/src/index.js CHANGED
@@ -200,6 +200,14 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
200
200
  // 格式化输出
201
201
  const formattedResult = orchestrator.formatResult(result);
202
202
 
203
+ // 如果任务失败,标记为错误
204
+ if (!result.success) {
205
+ return {
206
+ content: [{ type: 'text', text: formattedResult }],
207
+ isError: true,
208
+ };
209
+ }
210
+
203
211
  return {
204
212
  content: [{ type: 'text', text: formattedResult }],
205
213
  };
@@ -346,28 +346,44 @@ export class Orchestrator {
346
346
  async execute(params) {
347
347
  metrics.recordRequest();
348
348
  const requestId = `req_${Date.now()}_${Math.random().toString(36).substr(2, 6)}`;
349
- const GLOBAL_TIMEOUT = 30000; // 30秒全局超时
349
+
350
+ // 根据关键词数量动态计算超时时间(每个关键词 8 秒,最少 20 秒,最多 90 秒)
351
+ const keywords = this.parseKeywords(params.query);
352
+ const keywordCount = keywords.length;
353
+ const GLOBAL_TIMEOUT = Math.min(Math.max(keywordCount * 8000, 20000), 90000);
354
+
355
+ logger.info(`[Orchestrator] Starting request: ${requestId}, keywords: ${keywordCount}, timeout: ${GLOBAL_TIMEOUT/1000}s`);
356
+
357
+ // 创建超时控制器
358
+ let timeoutId;
359
+ const timeoutPromise = new Promise((_, reject) => {
360
+ timeoutId = setTimeout(() => {
361
+ const errorMsg = `REQUEST_TIMEOUT: 请求超时(${GLOBAL_TIMEOUT/1000}秒),关键词过多请减少数量或稍后重试`;
362
+ logger.error(`[Orchestrator] ${errorMsg}`);
363
+ reject(new Error(errorMsg));
364
+ }, GLOBAL_TIMEOUT);
365
+ });
350
366
 
351
367
  try {
352
- logger.info(`[Orchestrator] Starting request: ${requestId}`);
353
-
354
368
  // 添加全局超时熔断机制
355
369
  const result = await Promise.race([
356
370
  this._executeInternal(params),
357
- new Promise((_, reject) =>
358
- setTimeout(() => reject(new Error('REQUEST_TIMEOUT: 请求超时(30秒),请稍后重试')), GLOBAL_TIMEOUT)
359
- )
371
+ timeoutPromise
360
372
  ]);
361
373
 
374
+ clearTimeout(timeoutId);
362
375
  result.requestId = requestId;
363
376
  logger.info(`[Orchestrator] Completed request: ${requestId}`);
364
377
  return result;
365
378
  } catch (error) {
379
+ clearTimeout(timeoutId);
366
380
  logger.error(`[Orchestrator] Failed request: ${requestId} - ${error.message}`);
381
+ // 确保返回标准错误格式
367
382
  return {
368
383
  success: false,
369
384
  error: error.message,
370
385
  requestId,
386
+ duration: 0,
371
387
  };
372
388
  }
373
389
  }