feat: add 60-second timeouts to MCP request handlers for reliability
This commit is contained in:
@@ -8,7 +8,7 @@
|
|||||||
"build:mcp": "bun build ./packages/mcp-server/src/index.ts --target=bun --outdir=./dist/mcp --minify",
|
"build:mcp": "bun build ./packages/mcp-server/src/index.ts --target=bun --outdir=./dist/mcp --minify",
|
||||||
"build:all": "bun run build:api && bun run build:mcp",
|
"build:all": "bun run build:api && bun run build:mcp",
|
||||||
"build": "bun run clean && bun run build:all",
|
"build": "bun run clean && bun run build:all",
|
||||||
"start": "./start.sh"
|
"start": "./scripts/start.sh"
|
||||||
},
|
},
|
||||||
"private": true,
|
"private": true,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
|
|||||||
@@ -115,13 +115,21 @@ export async function handleMcpRequest(req: Request): Promise<Response> {
|
|||||||
priceMin: args.priceMin,
|
priceMin: args.priceMin,
|
||||||
priceMax: args.priceMax,
|
priceMax: args.priceMax,
|
||||||
};
|
};
|
||||||
const items = await fetchKijijiItems(
|
const items = await Promise.race([
|
||||||
|
fetchKijijiItems(
|
||||||
query,
|
query,
|
||||||
1,
|
1,
|
||||||
"https://www.kijiji.ca",
|
"https://www.kijiji.ca",
|
||||||
searchOptions,
|
searchOptions,
|
||||||
{},
|
{},
|
||||||
);
|
),
|
||||||
|
new Promise((_, reject) =>
|
||||||
|
setTimeout(
|
||||||
|
() => reject(new Error("Request timed out after 60 seconds")),
|
||||||
|
60000,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
]);
|
||||||
result = items || [];
|
result = items || [];
|
||||||
} else if (name === "search_facebook") {
|
} else if (name === "search_facebook") {
|
||||||
const query = args.query;
|
const query = args.query;
|
||||||
@@ -132,14 +140,22 @@ export async function handleMcpRequest(req: Request): Promise<Response> {
|
|||||||
error: { code: -32602, message: "query parameter is required" },
|
error: { code: -32602, message: "query parameter is required" },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
const items = await fetchFacebookItems(
|
const items = await Promise.race([
|
||||||
|
fetchFacebookItems(
|
||||||
query,
|
query,
|
||||||
1,
|
1,
|
||||||
args.location || "toronto",
|
args.location || "toronto",
|
||||||
args.maxItems || 25,
|
args.maxItems || 25,
|
||||||
args.cookiesSource,
|
args.cookiesSource,
|
||||||
undefined,
|
undefined,
|
||||||
);
|
),
|
||||||
|
new Promise((_, reject) =>
|
||||||
|
setTimeout(
|
||||||
|
() => reject(new Error("Request timed out after 60 seconds")),
|
||||||
|
60000,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
]);
|
||||||
result = items || [];
|
result = items || [];
|
||||||
} else if (name === "search_ebay") {
|
} else if (name === "search_ebay") {
|
||||||
const query = args.query;
|
const query = args.query;
|
||||||
@@ -150,7 +166,8 @@ export async function handleMcpRequest(req: Request): Promise<Response> {
|
|||||||
error: { code: -32602, message: "query parameter is required" },
|
error: { code: -32602, message: "query parameter is required" },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
const items = await fetchEbayItems(query, 1, {
|
const items = await Promise.race([
|
||||||
|
fetchEbayItems(query, 1, {
|
||||||
minPrice: args.minPrice,
|
minPrice: args.minPrice,
|
||||||
maxPrice: args.maxPrice,
|
maxPrice: args.maxPrice,
|
||||||
strictMode: args.strictMode || false,
|
strictMode: args.strictMode || false,
|
||||||
@@ -158,7 +175,14 @@ export async function handleMcpRequest(req: Request): Promise<Response> {
|
|||||||
keywords: args.keywords || [query],
|
keywords: args.keywords || [query],
|
||||||
buyItNowOnly: args.buyItNowOnly !== false,
|
buyItNowOnly: args.buyItNowOnly !== false,
|
||||||
canadaOnly: args.canadaOnly !== false,
|
canadaOnly: args.canadaOnly !== false,
|
||||||
});
|
}),
|
||||||
|
new Promise((_, reject) =>
|
||||||
|
setTimeout(
|
||||||
|
() => reject(new Error("Request timed out after 60 seconds")),
|
||||||
|
60000,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
]);
|
||||||
|
|
||||||
const results = args.maxItems ? items.slice(0, args.maxItems) : items;
|
const results = args.maxItems ? items.slice(0, args.maxItems) : items;
|
||||||
result = results || [];
|
result = results || [];
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ trap 'echo "Received shutdown signal, stopping services..."; kill -TERM $API_PID
|
|||||||
|
|
||||||
# Start API Server in background
|
# Start API Server in background
|
||||||
echo "Starting API Server on port ${API_PORT:-4005}..."
|
echo "Starting API Server on port ${API_PORT:-4005}..."
|
||||||
bun ../dist/api/index.js &
|
bun dist/api/index.js &
|
||||||
API_PID=$!
|
API_PID=$!
|
||||||
|
|
||||||
# Give API server a moment to initialize
|
# Give API server a moment to initialize
|
||||||
@@ -14,7 +14,7 @@ sleep 1
|
|||||||
|
|
||||||
# Start MCP Server in background
|
# Start MCP Server in background
|
||||||
echo "Starting MCP Server on port ${API_PORT:-4006}..."
|
echo "Starting MCP Server on port ${API_PORT:-4006}..."
|
||||||
bun ../dist/mcp/index.js &
|
bun dist/mcp/index.js &
|
||||||
MCP_PID=$!
|
MCP_PID=$!
|
||||||
|
|
||||||
echo "Both services started successfully"
|
echo "Both services started successfully"
|
||||||
|
|||||||
Reference in New Issue
Block a user