docs: surface Kijiji AND-matching behavior in tool, API, and MCP responses
Kijiji zero-result queries (e.g. 'macbook air m1 apple silicon') are confusing because the failure mode is non-obvious. Surface the root cause everywhere the caller can see it: - MCP tool description warns about AND-matching and gives a concrete before/after example - API 404 body includes the actionable hint via emptySearchResponse(hint) - Core scraper logs the built URL and tip on page-1 zero results - MCP handler unwraps the API message field so the hint reaches the LLM
This commit is contained in:
@@ -31,9 +31,9 @@ export function parseNonNegativeIntegerParam(
|
||||
return value;
|
||||
}
|
||||
|
||||
export function emptySearchResponse(): Response {
|
||||
return Response.json(
|
||||
{ message: "Search didn't return any results!" },
|
||||
{ status: 404 },
|
||||
);
|
||||
export function emptySearchResponse(hint?: string): Response {
|
||||
const message = hint
|
||||
? `Search didn't return any results! ${hint}`
|
||||
: "Search didn't return any results!";
|
||||
return Response.json({ message }, { status: 404 });
|
||||
}
|
||||
|
||||
@@ -73,7 +73,10 @@ export async function kijijiRoute(req: Request): Promise<Response> {
|
||||
{ hideUnstableResults: true },
|
||||
);
|
||||
if (items.results.length === 0 && items.unstableResults.length === 0) {
|
||||
return emptySearchResponse();
|
||||
return emptySearchResponse(
|
||||
`Kijiji matches ALL words in the query against listing titles. ` +
|
||||
`Try a shorter or more common query (e.g. "macbook air m1" instead of "macbook air m1 apple silicon").`,
|
||||
);
|
||||
}
|
||||
return Response.json(items, { status: 200 });
|
||||
}
|
||||
@@ -86,7 +89,10 @@ export async function kijijiRoute(req: Request): Promise<Response> {
|
||||
{},
|
||||
);
|
||||
if (!items || items.length === 0) {
|
||||
return emptySearchResponse();
|
||||
return emptySearchResponse(
|
||||
`Kijiji matches ALL words in the query against listing titles. ` +
|
||||
`Try a shorter or more common query (e.g. "macbook air m1" instead of "macbook air m1 apple silicon").`,
|
||||
);
|
||||
}
|
||||
return Response.json(items, { status: 200 });
|
||||
} catch (error) {
|
||||
|
||||
@@ -394,7 +394,8 @@ describe("API routes", () => {
|
||||
|
||||
expect(response.status).toBe(404);
|
||||
const body = await response.json();
|
||||
expect(body.message).toBe("Search didn't return any results!");
|
||||
expect(body.message).toStartWith("Search didn't return any results!");
|
||||
expect(body.message).toContain("Kijiji matches ALL words");
|
||||
});
|
||||
|
||||
test("ebayRoute forwards maxItems to core in default mode", async () => {
|
||||
|
||||
Reference in New Issue
Block a user