List Collections
list_collectionsRetrieve a list of all collections defined in your ElmapiCMS project.
Instructions
List all collections in the project
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools/collections.ts:10-18 (registration)Tool registration for list_collections. No inputSchema means no parameters. Calls GET /collections via the API client and returns the result as JSON text.
server.registerTool("list_collections", { title: "List Collections", description: "List all collections in the project", }, async () => { const result = await client.get("/collections"); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }], }; }); - src/tools/collections.ts:13-18 (handler)The handler function for list_collections. It fetches all collections from the ElmapiCMS API via GET /collections and returns them as formatted JSON text.
}, async () => { const result = await client.get("/collections"); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }], }; }); - src/client.ts:94-112 (helper)The ElmapiClient.get() helper method called by the list_collections handler. Builds a GET request with optional query params, sends it with auth headers, and handles the response.
async get( path: string, params?: Record<string, unknown> ): Promise<unknown> { const url = new URL(`${this.baseUrl}${path}`); if (params) { const flatPairs = this.flattenParams(params); for (const [key, value] of flatPairs) { url.searchParams.append(key, value); } } const response = await fetch(url.toString(), { method: "GET", headers: this.headers(), }); return this.handleResponse(response); }