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