update_datasource
Update an existing Storyblok datasource by its ID, with options to change name, slug, or dimensions.
Instructions
Updates an existing datasource in a specified Storyblok space.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| datasource_id | Yes | ID of the datasource to update | |
| name | No | New name for the datasource | |
| slug | No | New slug for the datasource | |
| dimensions | No | Array of dimension objects |
Implementation Reference
- src/tools/data-sources.ts:88-118 (handler)The 'update_datasource' tool handler. Uses apiPut to send a PUT request to '/datasources/{datasource_id}' with optional fields (name, slug, dimensions_attributes). Returns JSON response or error.
// Tool: update_datasource server.tool( 'update_datasource', 'Updates an existing datasource in a specified Storyblok space.', { datasource_id: z.number().describe('ID of the datasource to update'), name: z.string().optional().describe('New name for the datasource'), slug: z.string().optional().describe('New slug for the datasource'), dimensions: z .array(z.record(z.unknown())) .optional() .describe('Array of dimension objects'), }, async ({ datasource_id, name, slug, dimensions }) => { try { const datasource: Record<string, unknown> = {}; if (name !== undefined) datasource.name = name; if (slug !== undefined) datasource.slug = slug; if (dimensions !== undefined) datasource.dimensions_attributes = dimensions; const payload = { datasource }; const data = await apiPut(`/datasources/${datasource_id}`, payload); return createJsonResponse(data); } catch (error) { if (error instanceof APIError) { return createErrorResponse(error); } throw error; } } ); - src/tools/data-sources.ts:92-100 (schema)Zod schema for the 'update_datasource' tool: requires datasource_id (number), optional name (string), optional slug (string), optional dimensions (array of record).
{ datasource_id: z.number().describe('ID of the datasource to update'), name: z.string().optional().describe('New name for the datasource'), slug: z.string().optional().describe('New slug for the datasource'), dimensions: z .array(z.record(z.unknown())) .optional() .describe('Array of dimension objects'), }, - src/tools/index.ts:72-72 (registration)Registration of the datasource tools module, which includes 'update_datasource', via registerDatasources(server) call.
registerDatasources(server); - src/tools/data-sources.ts:10-141 (registration)The registerDatasources function that registers all 5 datasource tools (including 'update_datasource') with the MCP server.
export function registerDatasources(server: McpServer): void { // Tool: retrieve_multiple_datasources server.tool( 'retrieve_multiple_datasources', 'Retrieves multiple datasources from a specified Storyblok space.', { search: z.string().optional().describe('Search string'), by_ids: z.string().optional().describe('Comma-separated list of datasource IDs'), }, async ({ search, by_ids }) => { try { const params: Record<string, string> = {}; if (search) params.search = search; if (by_ids) params.by_ids = by_ids; const data = await apiGet('/datasources', params); return createJsonResponse(data); } catch (error) { if (error instanceof APIError) { return createErrorResponse(error); } throw error; } } ); // Tool: retrieve_single_datasource server.tool( 'retrieve_single_datasource', 'Retrieves a single datasource from a specified Storyblok space.', { datasource_id: z.number().describe('ID of the datasource to retrieve'), }, async ({ datasource_id }) => { try { const data = await apiGet(`/datasources/${datasource_id}`); return createJsonResponse(data); } catch (error) { if (error instanceof APIError) { return createErrorResponse(error); } throw error; } } ); // Tool: create_datasource server.tool( 'create_datasource', 'Creates a new datasource in a specified Storyblok space.', { name: z.string().describe('Name of the datasource'), slug: z.string().describe('Slug of the datasource'), dimensions: z .array(z.record(z.unknown())) .optional() .describe('Array of dimension objects'), }, async ({ name, slug, dimensions }) => { try { const payload = { datasource: { name, slug, dimensions_attributes: dimensions ?? [], }, }; const data = await apiPost('/datasources', payload); return createJsonResponse(data); } catch (error) { if (error instanceof APIError) { return createErrorResponse(error); } throw error; } } ); // Tool: update_datasource server.tool( 'update_datasource', 'Updates an existing datasource in a specified Storyblok space.', { datasource_id: z.number().describe('ID of the datasource to update'), name: z.string().optional().describe('New name for the datasource'), slug: z.string().optional().describe('New slug for the datasource'), dimensions: z .array(z.record(z.unknown())) .optional() .describe('Array of dimension objects'), }, async ({ datasource_id, name, slug, dimensions }) => { try { const datasource: Record<string, unknown> = {}; if (name !== undefined) datasource.name = name; if (slug !== undefined) datasource.slug = slug; if (dimensions !== undefined) datasource.dimensions_attributes = dimensions; const payload = { datasource }; const data = await apiPut(`/datasources/${datasource_id}`, payload); return createJsonResponse(data); } catch (error) { if (error instanceof APIError) { return createErrorResponse(error); } throw error; } } ); // Tool: delete_datasource server.tool( 'delete_datasource', 'Deletes a datasource from a specified Storyblok space.', { datasource_id: z.number().describe('ID of the datasource to delete'), }, async ({ datasource_id }) => { try { await apiDelete(`/datasources/${datasource_id}`); return { content: [{ type: 'text' as const, text: 'DataSource deleted successfully' }], }; } catch (error) { if (error instanceof APIError) { return createErrorResponse(error); } throw error; } } ); } - src/utils/api.ts:211-222 (helper)The apiPut helper function used by the handler to make the PUT HTTP request. Builds URL from path, sends JSON body with auth headers, and handles the response.
export async function apiPut<T = unknown>( path: string, body: unknown ): Promise<T> { const url = buildManagementUrl(path); const response = await fetch(url, { method: 'PUT', headers: getManagementHeaders(), body: JSON.stringify(body), }); return handleResponse<T>(response, url); }