mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-30 00:20:07 +00:00
feat(mcp): list_collection_places pages a long list compactly (#2647)
A read tool that answers one list a page at a time (100 by default, up to 500) as compact one-line JSON rows, filtered by status, label or "no label", with the list's labels, the matching total and a cursor. The cursor is the last place's position (sort_order, created_at, id), so labelling a page while paging through unlabelled places skips none. getCollection orders by the same keys, id last, so both tools agree on ties.
This commit is contained in:
@@ -2,8 +2,10 @@ import {
|
||||
collectionDeleteManyRequestSchema,
|
||||
collectionItemsRequestSchema,
|
||||
collectionMembershipSchema,
|
||||
collectionPlacesPageRequestSchema,
|
||||
collectionPlaceUpdateRequestSchema,
|
||||
collectionReorderRequestSchema,
|
||||
COLLECTION_PLACES_PAGE_DEFAULT,
|
||||
collectionSavePlaceRequestSchema,
|
||||
collectionStatusSchema,
|
||||
isVisitedCollectionStatus,
|
||||
@@ -134,3 +136,28 @@ describe('collectionMembershipSchema', () => {
|
||||
expect(collectionMembershipSchema.parse({ saved: true, lists: [list] }).lists[0]?.color).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('collectionPlacesPageRequestSchema', () => {
|
||||
// #2647: a page of a list for list_collection_places.
|
||||
it('takes a list alone, or a cursor, a limit of 1 to 500 and the filters', () => {
|
||||
expect(collectionPlacesPageRequestSchema.safeParse({ collectionId: 4 }).success).toBe(true);
|
||||
const full = {
|
||||
collectionId: 4,
|
||||
cursor: 'WzAsIiIsMV0',
|
||||
limit: 500,
|
||||
status: 'revisit',
|
||||
labelId: 7,
|
||||
unlabeled: false,
|
||||
};
|
||||
expect(collectionPlacesPageRequestSchema.parse(full)).toEqual(full);
|
||||
for (const page of [
|
||||
{},
|
||||
{ collectionId: 4, limit: 0 },
|
||||
{ collectionId: 4, limit: 501 },
|
||||
{ collectionId: 4, status: 'gone' },
|
||||
]) {
|
||||
expect(collectionPlacesPageRequestSchema.safeParse(page).success, JSON.stringify(page)).toBe(false);
|
||||
}
|
||||
expect(COLLECTION_PLACES_PAGE_DEFAULT).toBe(100);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -294,6 +294,38 @@ export const collectionItemsRequestSchema = z.object({
|
||||
});
|
||||
export type CollectionItemsRequest = z.infer<typeof collectionItemsRequestSchema>;
|
||||
|
||||
export const COLLECTION_PLACES_PAGE_DEFAULT = 100;
|
||||
export const COLLECTION_PLACES_PAGE_MAX = 500;
|
||||
|
||||
/**
|
||||
* One page of a list's places for an MCP client (list_collection_places, #2647):
|
||||
* get_collection answers a long list as one block a client cuts in the middle.
|
||||
* Pages follow the list's own order and continue from a cursor rather than an
|
||||
* offset, so labelling the places of one page while filtering on `unlabeled`
|
||||
* cannot make the next page skip any.
|
||||
*/
|
||||
export const collectionPlacesPageRequestSchema = z.object({
|
||||
collectionId: idSchema,
|
||||
cursor: z
|
||||
.string()
|
||||
.max(200)
|
||||
.optional()
|
||||
.describe('Where to go on: the next_cursor of the page before. Leave it out for the first page.'),
|
||||
limit: z
|
||||
.number()
|
||||
.int()
|
||||
.min(1)
|
||||
.max(COLLECTION_PLACES_PAGE_MAX)
|
||||
.optional()
|
||||
.describe(
|
||||
`How many places at most (default ${COLLECTION_PLACES_PAGE_DEFAULT}, at most ${COLLECTION_PLACES_PAGE_MAX})`,
|
||||
),
|
||||
status: z.enum(COLLECTION_STATUSES).optional().describe('Only places with this status'),
|
||||
labelId: idSchema.optional().describe('Only places carrying this label of the list'),
|
||||
unlabeled: z.boolean().optional().describe('true: only places without any label. Not together with labelId.'),
|
||||
});
|
||||
export type CollectionPlacesPageRequest = z.infer<typeof collectionPlacesPageRequestSchema>;
|
||||
|
||||
// Fusion invitations. user_id is NUMERIC ONLY — the UI always sends an id from availableUsers.
|
||||
export const collectionInviteRequestSchema = z.object({
|
||||
collection_id: z.number(),
|
||||
|
||||
Reference in New Issue
Block a user