list_collections
Retrieve prompt collections filtered by name or workspace. Returns collection IDs, names, slugs, and timestamps for selecting a collection before creating prompts.
Instructions
List prompt collections in the workspace, optionally filtering by name or workspace. Returns ids, names, slugs, and timestamps so you can choose a collection_id before create_prompt, get_collection, or list_prompts.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| workspace_id | No | Filter by workspace ID | |
| search | No | Search collections by name | |
| current_page | No | Page number for pagination | |
| page_size | No | Results per page (max 100) |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ok | Yes | Whether the tool call succeeded and returned structured data | |
| data | No | Structured success payload when ok is true | |
| error | No | Structured error payload when ok is false |
Implementation Reference
- src/tools/collections.tools.ts:53-82 (handler)The MCP tool handler for 'list_collections'. It calls service.collections.listCollections(params) and returns the total and mapped collection data (id, name, slug, workspace_id, created_at, last_updated_at) as JSON.
server.tool( "list_collections", "List prompt collections in the workspace, optionally filtering by name or workspace. Returns ids, names, slugs, and timestamps so you can choose a collection_id before create_prompt, get_collection, or list_prompts.", COLLECTIONS_TOOL_SCHEMAS.listCollections, async (params) => { const collections = await service.collections.listCollections(params); return { content: [ { type: "text", text: JSON.stringify( { total: collections.total, collections: collections.data.map((collection) => ({ id: collection.id, name: collection.name, slug: collection.slug, workspace_id: collection.workspace_id, created_at: collection.created_at, last_updated_at: collection.last_updated_at, })), }, null, 2, ), }, ], }; }, ); - src/tools/collections.tools.ts:6-20 (schema)Zod schema for list_collections input params: optional workspace_id, search, current_page (positive int), page_size (1-100).
listCollections: { workspace_id: z.string().optional().describe("Filter by workspace ID"), search: z.string().optional().describe("Search collections by name"), current_page: z.coerce .number() .positive() .optional() .describe("Page number for pagination"), page_size: z.coerce .number() .positive() .max(100) .optional() .describe("Results per page (max 100)"), }, - src/tools/collections.tools.ts:48-82 (registration)Registration of the 'list_collections' tool via server.tool() with name, description, schema, and handler callback.
export function registerCollectionsTools( server: McpServer, service: PortkeyService, ): void { // List collections tool server.tool( "list_collections", "List prompt collections in the workspace, optionally filtering by name or workspace. Returns ids, names, slugs, and timestamps so you can choose a collection_id before create_prompt, get_collection, or list_prompts.", COLLECTIONS_TOOL_SCHEMAS.listCollections, async (params) => { const collections = await service.collections.listCollections(params); return { content: [ { type: "text", text: JSON.stringify( { total: collections.total, collections: collections.data.map((collection) => ({ id: collection.id, name: collection.name, slug: collection.slug, workspace_id: collection.workspace_id, created_at: collection.created_at, last_updated_at: collection.last_updated_at, })), }, null, 2, ), }, ], }; }, ); - Service method CollectionsService.listCollections() that calls the HTTP API GET /collections with optional query params.
async listCollections( params?: ListCollectionsParams, ): Promise<ListCollectionsResponse> { return this.get<ListCollectionsResponse>("/collections", { workspace_id: params?.workspace_id, current_page: params?.current_page, page_size: params?.page_size, search: params?.search, }); } - TypeScript interfaces ListCollectionsParams and ListCollectionsResponse used by the list_collections handler and service.
export interface ListCollectionsParams { workspace_id?: string; current_page?: number; page_size?: number; search?: string; } export interface ListCollectionsResponse { data: Collection[]; total: number; object: "list"; }