create_datasource_entry
Create a new entry in a Storyblok datasource by providing the datasource ID, entry name, and value.
Instructions
Creates a new datasource entry in a specified Storyblok space.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| datasource_id | Yes | ID of the datasource | |
| name | Yes | Name of the entry | |
| value | Yes | Value of the entry |
Implementation Reference
- src/tools/datasource-entries.ts:70-97 (handler)The handler function for the 'create_datasource_entry' tool. It accepts datasource_id, name, and value, constructs a payload, and POSTs it to the Storyblok API endpoint '/datasource_entries'.
// Tool: create_datasource_entry server.tool( 'create_datasource_entry', 'Creates a new datasource entry in a specified Storyblok space.', { datasource_id: z.number().describe('ID of the datasource'), name: z.string().describe('Name of the entry'), value: z.string().describe('Value of the entry'), }, async ({ datasource_id, name, value }) => { try { const payload = { datasource_entry: { datasource_id, name, value, }, }; const data = await apiPost('/datasource_entries', payload); return createJsonResponse(data); } catch (error) { if (error instanceof APIError) { return createErrorResponse(error); } throw error; } } ); - Zod schema for input validation of the create_datasource_entry tool. Requires datasource_id (number), name (string), and value (string).
{ datasource_id: z.number().describe('ID of the datasource'), name: z.string().describe('Name of the entry'), value: z.string().describe('Value of the entry'), }, - src/tools/datasource-entries.ts:10-97 (registration)Tool registration: registerDatasourceEntries registers the create_datasource_entry tool via server.tool() within a group of datasource entry tools.
export function registerDatasourceEntries(server: McpServer): void { // Tool: retrieve_multiple_datasource_entries server.tool( 'retrieve_multiple_datasource_entries', 'Retrieves multiple datasource entries from a specified Storyblok space. Requires datasource_id or datasource_slug.', { datasource_id: z.number().optional().describe('ID of the datasource'), datasource_slug: z.string().optional().describe('Slug of the datasource'), dimension: z.string().optional().describe('Dimension filter'), }, async ({ datasource_id, datasource_slug, dimension }) => { try { if (!datasource_id && !datasource_slug) { return { isError: true, content: [ { type: 'text' as const, text: "At least one of 'datasource_id' or 'datasource_slug' must be provided.", }, ], }; } const params: Record<string, string> = {}; if (datasource_id) params.datasource_id = String(datasource_id); if (datasource_slug) params.datasource_slug = datasource_slug; if (dimension) params.dimension = dimension; const data = await apiGet('/datasource_entries/', params); return createJsonResponse(data); } catch (error) { if (error instanceof APIError) { return createErrorResponse(error); } throw error; } } ); // Tool: retrieve_single_datasource_entry server.tool( 'retrieve_single_datasource_entry', 'Retrieves a single datasource entry via the Storyblok Management API.', { datasource_entry_id: z.number().describe('ID of the datasource entry'), }, async ({ datasource_entry_id }) => { try { const data = await apiGet(`/datasource_entries/${datasource_entry_id}`); return createJsonResponse(data); } catch (error) { if (error instanceof APIError) { return createErrorResponse(error); } throw error; } } ); // Tool: create_datasource_entry server.tool( 'create_datasource_entry', 'Creates a new datasource entry in a specified Storyblok space.', { datasource_id: z.number().describe('ID of the datasource'), name: z.string().describe('Name of the entry'), value: z.string().describe('Value of the entry'), }, async ({ datasource_id, name, value }) => { try { const payload = { datasource_entry: { datasource_id, name, value, }, }; const data = await apiPost('/datasource_entries', payload); return createJsonResponse(data); } catch (error) { if (error instanceof APIError) { return createErrorResponse(error); } throw error; } } ); - src/tools/index.ts:18-73 (registration)Import of registerDatasourceEntries from datasource-entries module, and its invocation to register the tool with the MCP server.
import { registerDatasourceEntries } from './datasource-entries.js'; import { registerBranches } from './pipelines.js'; import { registerPresets } from './presets.js'; import { registerReleases } from './releases.js'; import { registerSchedulingStories } from './scheduling-stories.js'; import { registerSpace } from './space.js'; import { registerSpaceRoles } from './space-roles.js'; import { registerTasks } from './tasks.js'; import { registerWebhooks } from './webhooks.js'; import { registerWorkflows } from './workflows.js'; import { registerWorkflowStages } from './workflow-stage.js'; import { registerWorkflowStageChanges } from './workflow-stage-changes.js'; import { registerComponents } from './components.js'; import { registerComponentsFolder } from './components-folder.js'; import { registerAssets } from './assets.js'; import { registerAssetsFolders } from './assets-folder.js'; import { registerStories } from './stories.js'; import { registerDiscussions } from './discussions.js'; import { registerExtensions } from './extensions.js'; import { registerFieldPlugins } from './field-plugins.js'; /** * Registers all tools with the MCP server */ export function registerAllTools(server: McpServer): void { // Simple tools registerPing(server); registerMeta(server); // Tag management registerTags(server); registerInternalTags(server); // Access and authentication registerAccessTokens(server); // Activity tracking registerActivities(server); // Workflow management registerApprovals(server); registerWorkflows(server); registerWorkflowStages(server); registerWorkflowStageChanges(server); // Branch/Pipeline management registerBranches(server); registerBranchDeployments(server); // User management registerCollaborators(server); registerSpaceRoles(server); // Data sources registerDatasources(server); registerDatasourceEntries(server); - src/utils/api.ts:195-206 (helper)The apiPost helper function used by the create_datasource_entry handler to POST the payload to the Storyblok Management API.
export async function apiPost<T = unknown>( path: string, body: unknown ): Promise<T> { const url = buildManagementUrl(path); const response = await fetch(url, { method: 'POST', headers: getManagementHeaders(), body: JSON.stringify(body), }); return handleResponse<T>(response, url); }