Skip to content

Commit 8a9d722

Browse files
IlyaasKclaude
andcommitted
Keep empty list responses as structured JSON
itemsJsonResponse swapped to a plain-text body when a full inventory was empty, so profiles/proxies/extensions list returned text on empty but JSON otherwise — an inconsistent shape for agents. Emit emptyText as a `note` inside the normal { items, has_more, next_offset } payload instead. Preserves the empty-inventory guidance (now structured) while paginated empty pages stay note-free, keeping the full-vs-paginated distinction. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 6012a5a commit 8a9d722

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

src/lib/mcp/responses.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,17 @@ export function itemsJsonResponse<T, U = T>(
2929
items: T[],
3030
options: ItemsJsonResponseOptions<T, U> = {},
3131
) {
32-
if (items.length === 0 && options.emptyText) {
33-
return textResponse(options.emptyText);
34-
}
32+
// Keep the response shape uniform JSON for every list outcome. When empty,
33+
// surface emptyText as a `note` (e.g. setup guidance) rather than swapping to
34+
// a plain-text body, so agents always get { items, has_more, next_offset }.
35+
const note =
36+
items.length === 0 ? (options.emptyText ?? options.note) : options.note;
3537

3638
return jsonResponse({
3739
items: options.mapItem ? items.map(options.mapItem) : items,
3840
has_more: options.has_more,
3941
next_offset: options.next_offset,
40-
...(options.note && { note: options.note }),
42+
...(note && { note }),
4143
});
4244
}
4345

0 commit comments

Comments
 (0)