Reorder Fields
reorder_fieldsRearrange fields in a collection by assigning new display order positions to each field UUID.
Instructions
Update the display order of fields within a collection
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| collection_slug | Yes | The collection slug | |
| fields | Yes | Array of { uuid, order } objects |
Implementation Reference
- src/tools/fields.ts:88-111 (registration)Registration of the 'reorder_fields' tool via server.registerTool, including its title, description, and Zod-based input schema.
// ── reorder_fields ──────────────────────────────────────────────── server.registerTool("reorder_fields", { title: "Reorder Fields", description: "Update the display order of fields within a collection", inputSchema: { collection_slug: z.string().describe("The collection slug"), fields: z .array( z.object({ uuid: z.string().describe("Field UUID"), order: z.number().describe("New display order (0-based)"), }) ) .describe("Array of { uuid, order } objects"), }, }, async ({ collection_slug, fields }) => { const result = await client.post( `/collections/${collection_slug}/fields/reorder`, { fields } ); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }], }; }); - src/tools/fields.ts:92-102 (schema)Input schema for reorder_fields: requires 'collection_slug' (string) and 'fields' (array of { uuid: string, order: number } objects).
inputSchema: { collection_slug: z.string().describe("The collection slug"), fields: z .array( z.object({ uuid: z.string().describe("Field UUID"), order: z.number().describe("New display order (0-based)"), }) ) .describe("Array of { uuid, order } objects"), }, - src/tools/fields.ts:103-111 (handler)Handler that sends a POST request to /collections/{collection_slug}/fields/reorder with the provided fields array, returning the API response.
}, async ({ collection_slug, fields }) => { const result = await client.post( `/collections/${collection_slug}/fields/reorder`, { fields } ); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }], }; }); - src/client.ts:114-173 (helper)The ElmapiClient.post() method used by the handler to make the HTTP POST request to the ElmapiCMS API.
async post(path: string, body?: unknown): Promise<unknown> { const response = await fetch(`${this.baseUrl}${path}`, { method: "POST", headers: this.headers(), body: body ? JSON.stringify(body) : undefined, }); return this.handleResponse(response); } async put(path: string, body?: unknown): Promise<unknown> { const response = await fetch(`${this.baseUrl}${path}`, { method: "PUT", headers: this.headers(), body: body ? JSON.stringify(body) : undefined, }); return this.handleResponse(response); } async delete(path: string, body?: unknown): Promise<unknown> { const response = await fetch(`${this.baseUrl}${path}`, { method: "DELETE", headers: this.headers(), body: body ? JSON.stringify(body) : undefined, }); return this.handleResponse(response); } /** * Upload a file via multipart/form-data. * Accepts a Buffer, the original filename, and its MIME type. */ async uploadFile( path: string, fileBuffer: Buffer, filename: string, mimeType: string ): Promise<unknown> { const blob = new Blob([new Uint8Array(fileBuffer)], { type: mimeType }); const formData = new FormData(); formData.append("file", blob, filename); const headers: Record<string, string> = { Accept: "application/json", Authorization: `Bearer ${this.token}`, "project-id": this.projectId, // Do NOT set Content-Type — fetch sets it with the boundary automatically }; const response = await fetch(`${this.baseUrl}${path}`, { method: "POST", headers, body: formData, }); return this.handleResponse(response); } }