update_collection_item
Update an item in a Skema CMS collection by merging new data with the current fields. Provide the collection name, item ID, and the data to merge.
Instructions
Met à jour un item existant (merge partiel)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| collection | Yes | Nom de la collection | |
| id | Yes | ID de l'item à modifier | |
| data | Yes | Données à mettre à jour |
Implementation Reference
- src/index.ts:93-100 (handler)Main handler for 'update_collection_item' tool. Extracts collection, id, data from args and delegates to skema.updateItem().
case "update_collection_item": { const { collection, id, data } = args as { collection: string; id: string; data: Record<string, unknown>; }; result = await skema.updateItem(collection, id, data); break; - src/tools.ts:106-130 (schema)Input schema definition for 'update_collection_item' tool: requires collection (string), id (string), data (object).
{ name: "update_collection_item", description: "Met à jour un item existant (merge partiel)", inputSchema: { type: "object", properties: { collection: { type: "string", description: "Nom de la collection", }, id: { type: "string", description: "ID de l'item à modifier", }, data: { type: "object", description: "Données à mettre à jour", }, }, required: ["collection", "id", "data"], }, }, { name: "delete_collection_item", description: "Supprime un item d'une collection", - src/skema-client.ts:121-129 (helper)Helper function 'updateItem' that calls the remote MCP API with method 'update_collection_item' and parameters collection, id, data.
/** * Met a jour un item */ export const updateItem = ( collection: string, id: string, data: Record<string, unknown> ) => mcpCall("update_collection_item", { collection, id, data }); - src/skema-client.ts:25-145 (registration)The mcpCall function is the underlying transport helper that sends JSON-RPC requests to the Skema API. It is used by updateItem to make the actual HTTP call.
export const mcpCall = async <T = unknown>( toolName: string, args: Record<string, unknown> = {} ): Promise<T> => { requestId++; const response = await fetch(`${BASE_URL}/mcp`, { method: "POST", headers: { "X-API-Key": API_KEY, "Content-Type": "application/json", }, body: JSON.stringify({ jsonrpc: "2.0", id: requestId, method: "tools/call", params: { name: toolName, arguments: args, }, }), }); if (!response.ok) { const error = await response .json() .catch(() => ({ message: "Erreur inconnue" })); throw new Error(error.message || `Erreur HTTP ${response.status}`); } const jsonRpc: JsonRpcResponse<T> = await response.json(); if (jsonRpc.error) { throw new Error(jsonRpc.error.message); } if (!jsonRpc.result?.content?.[0]?.text) { throw new Error("Reponse MCP invalide"); } return JSON.parse(jsonRpc.result.content[0].text); }; /** * Recupere la liste des collections */ export const getCollections = () => mcpCall("get_collections"); /** * Recupere le schema d'une collection */ export const getCollection = (collection: string) => mcpCall("get_collection", { collection }); /** * Liste les items d'une collection */ export const getItems = ( collection: string, options?: { page?: number; perPage?: number; sort?: string; populate?: string; filters?: Record<string, unknown>; } ) => mcpCall("get_collection_items", { collection, page: options?.page, perPage: options?.perPage, sort: options?.sort, populate: options?.populate, filters: options?.filters, }); /** * Recupere un item par son ID */ export const getItem = ( collection: string, id: string, options?: { populate?: string } ) => mcpCall("get_collection_item", { collection, id, populate: options?.populate, }); /** * Cree un nouvel item */ export const createItem = (collection: string, data: Record<string, unknown>) => mcpCall("create_collection_item", { collection, data }); /** * Met a jour un item */ export const updateItem = ( collection: string, id: string, data: Record<string, unknown> ) => mcpCall("update_collection_item", { collection, id, data }); /** * Supprime un item */ export const deleteItem = (collection: string, id: string) => mcpCall("delete_collection_item", { collection, id }); /** * Recherche dans une collection */ export const searchItems = ( collection: string, query: string, options?: { fields?: string; page?: number; perPage?: number } ) => mcpCall("search_collection_items", {