smart-image-scraper-mcp 2.9.2 → 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 +1 -1
- package/src/index.js +8 -0
- package/src/services/orchestrator.js +19 -7
package/package.json
CHANGED
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
|
};
|
|
@@ -347,31 +347,43 @@ export class Orchestrator {
|
|
|
347
347
|
metrics.recordRequest();
|
|
348
348
|
const requestId = `req_${Date.now()}_${Math.random().toString(36).substr(2, 6)}`;
|
|
349
349
|
|
|
350
|
-
// 根据关键词数量动态计算超时时间(每个关键词
|
|
350
|
+
// 根据关键词数量动态计算超时时间(每个关键词 8 秒,最少 20 秒,最多 90 秒)
|
|
351
351
|
const keywords = this.parseKeywords(params.query);
|
|
352
352
|
const keywordCount = keywords.length;
|
|
353
|
-
const GLOBAL_TIMEOUT = Math.min(Math.max(keywordCount *
|
|
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
|
+
});
|
|
354
366
|
|
|
355
367
|
try {
|
|
356
|
-
logger.info(`[Orchestrator] Starting request: ${requestId}, keywords: ${keywordCount}, timeout: ${GLOBAL_TIMEOUT/1000}s`);
|
|
357
|
-
|
|
358
368
|
// 添加全局超时熔断机制
|
|
359
369
|
const result = await Promise.race([
|
|
360
370
|
this._executeInternal(params),
|
|
361
|
-
|
|
362
|
-
setTimeout(() => reject(new Error(`REQUEST_TIMEOUT: 请求超时(${GLOBAL_TIMEOUT/1000}秒),关键词过多请减少数量`)), GLOBAL_TIMEOUT)
|
|
363
|
-
)
|
|
371
|
+
timeoutPromise
|
|
364
372
|
]);
|
|
365
373
|
|
|
374
|
+
clearTimeout(timeoutId);
|
|
366
375
|
result.requestId = requestId;
|
|
367
376
|
logger.info(`[Orchestrator] Completed request: ${requestId}`);
|
|
368
377
|
return result;
|
|
369
378
|
} catch (error) {
|
|
379
|
+
clearTimeout(timeoutId);
|
|
370
380
|
logger.error(`[Orchestrator] Failed request: ${requestId} - ${error.message}`);
|
|
381
|
+
// 确保返回标准错误格式
|
|
371
382
|
return {
|
|
372
383
|
success: false,
|
|
373
384
|
error: error.message,
|
|
374
385
|
requestId,
|
|
386
|
+
duration: 0,
|
|
375
387
|
};
|
|
376
388
|
}
|
|
377
389
|
}
|