create_tag
Create a new tag in your Storyblok space and optionally associate it with a story using the Management API.
Instructions
Creates a new tag in a Storyblok space via the Management API.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | Name of the tag | |
| story_id | No | Optional story ID to associate with the tag |
Implementation Reference
- src/tools/tags.ts:41-66 (handler)Handler function for the 'create_tag' tool. Accepts 'name' (required) and 'story_id' (optional) parameters, builds a payload, POSTs to Storyblok Management API /tags/ endpoint, and returns the JSON response.
// Tool: create_tag server.tool( 'create_tag', 'Creates a new tag in a Storyblok space via the Management API.', { name: z.string().describe('Name of the tag'), story_id: z.number().optional().describe('Optional story ID to associate with the tag'), }, async ({ name, story_id }) => { try { const payload: { tag: { name: string; story_id?: number } } = { tag: { name }, }; if (story_id !== undefined) { payload.tag.story_id = story_id; } const data = await apiPost('/tags/', payload); return createJsonResponse(data); } catch (error) { if (error instanceof APIError) { return createErrorResponse(error); } throw error; } } ); - src/tools/tags.ts:45-48 (schema)Input schema for 'create_tag' using Zod: 'name' is a required string, 'story_id' is an optional number.
{ name: z.string().describe('Name of the tag'), story_id: z.number().optional().describe('Optional story ID to associate with the tag'), }, - src/tools/index.ts:48-49 (registration)Tool registration: registerTags is called from registerAllTools to register all tag tools including 'create_tag' on the MCP server.
registerTags(server); registerInternalTags(server); - src/utils/api.ts:195-206 (helper)Helper function apiPost which makes POST requests to the Storyblok Management API. Used by the create_tag handler to send the tag creation request.
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); } - src/utils/response.ts:26-30 (helper)Helper function createJsonResponse which serializes data as JSON for the MCP response. Used by the create_tag handler to format the success response.
export function createJsonResponse(data: unknown): McpSuccessResponse { return { content: [{ type: 'text', text: JSON.stringify(data, null, 2) }], }; }