Skip to content

Commit d54b6a5

Browse files
authored
feat: add latest tool requests: List Collection Items, Create Collection Items, Update Collection Items, Publish Collection Items (#9)
1 parent 4e9d73a commit d54b6a5

File tree

1 file changed

+124
-0
lines changed

1 file changed

+124
-0
lines changed

src/index.ts

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,130 @@ server.tool(
351351
}
352352
);
353353

354+
// GET https://api.webflow.com/v2/collections/:collection_id/items
355+
server.tool(
356+
"collections-items-list-items",
357+
{
358+
collection_id: z.string(),
359+
cmsLocaleId: z.string().optional(),
360+
offset: z.number().optional(),
361+
limit: z.number().optional(),
362+
name: z.string().optional(),
363+
slug: z.string().optional(),
364+
sortBy: z.enum(["lastPublished", "name", "slug"]).optional(),
365+
sortOrder: z.enum(["asc", "desc"]).optional(),
366+
},
367+
async ({ collection_id, cmsLocaleId, offset, limit, name, slug, sortBy, sortOrder }) => {
368+
const response = await client.collections.items.listItems(collection_id, {
369+
cmsLocaleId,
370+
offset,
371+
limit,
372+
name,
373+
slug,
374+
sortBy,
375+
sortOrder,
376+
});
377+
return {
378+
content: [{ type: "text", text: JSON.stringify(response) }],
379+
};
380+
}
381+
);
382+
383+
// CollectionItemPostSingle
384+
export const CollectionItemPostSingleSchema = z.object({
385+
id: z.string().optional(),
386+
cmsLocaleId: z.string().optional(),
387+
lastPublished: z.string().optional(),
388+
lastUpdated: z.string().optional(),
389+
createdOn: z.string().optional(),
390+
isArchived: z.boolean().optional(),
391+
isDraft: z.boolean().optional(),
392+
fieldData: z.record(z.any()).and(
393+
z.object({
394+
name: z.string(),
395+
slug: z.string()
396+
})
397+
)
398+
})
399+
400+
// request: Webflow.collections.ItemsCreateItemRequest
401+
const WebflowCollectionsItemsCreateItemRequestSchema = z.union([
402+
CollectionItemPostSingleSchema,
403+
z.object({
404+
items: z.array(CollectionItemPostSingleSchema).optional()
405+
})
406+
])
407+
408+
// POST https://api.webflow.com/v2/collections/:collection_id/items
409+
server.tool(
410+
"collections-items-create-item",
411+
{
412+
collection_id: z.string(),
413+
request: WebflowCollectionsItemsCreateItemRequestSchema,
414+
},
415+
async ({ collection_id, request }) => {
416+
const response = await client.collections.items.createItem(collection_id, request)
417+
return {
418+
content: [{ type: "text", text: JSON.stringify(response) }],
419+
};
420+
}
421+
);
422+
423+
// CollectionItemWithIdInput
424+
export const CollectionItemWithIdInputSchema = z.object({
425+
id: z.string(),
426+
cmsLocaleId: z.string().optional(),
427+
lastPublished: z.string().optional(),
428+
lastUpdated: z.string().optional(),
429+
createdOn: z.string().optional(),
430+
isArchived: z.boolean().optional(),
431+
isDraft: z.boolean().optional(),
432+
fieldData: z.record(z.any()).and(
433+
z.object({
434+
name: z.string(),
435+
slug: z.string(),
436+
})
437+
)
438+
})
439+
440+
441+
// request: Webflow.collections.ItemsUpdateItemsRequest
442+
const WebflowCollectionsItemsUpdateItemsRequestSchema = z.object({
443+
items: z.array(CollectionItemWithIdInputSchema).optional()
444+
})
445+
446+
// PATCH https://api.webflow.com/v2/collections/:collection_id/items
447+
server.tool(
448+
"collections-items-update-items",
449+
{
450+
collection_id: z.string(),
451+
request: WebflowCollectionsItemsUpdateItemsRequestSchema,
452+
},
453+
async ({ collection_id, request }) => {
454+
const response = await client.collections.items.updateItems(collection_id, request)
455+
return {
456+
content: [{ type: "text", text: JSON.stringify(response) }],
457+
};
458+
}
459+
);
460+
461+
// POST https://api.webflow.com/v2/collections/:collection_id/items/publish
462+
server.tool(
463+
"collections-items-publish-items",
464+
{
465+
collection_id: z.string(),
466+
itemIds: z.array(z.string()),
467+
},
468+
async ({ collection_id, itemIds }) => {
469+
const response = await client.collections.items.publishItem(collection_id, {
470+
itemIds: itemIds
471+
});
472+
return {
473+
content: [{ type: "text", text: JSON.stringify(response) }],
474+
};
475+
}
476+
)
477+
354478
// Start receiving messages on stdin and sending messages on stdout
355479
const transport = new StdioServerTransport();
356480
await server.connect(transport);

0 commit comments

Comments
 (0)