Skip to main content
Glama

create_access_token

Create a new access token for a Storyblok space, specifying access level (draft/published) and optional branch, story, or cache restrictions.

Instructions

Create a new access token in the current Storyblok space via the Management API.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
accessYesThe access level for the token (e.g., 'draft', 'published')
nameNoOptional name for the token
branch_idNoOptional branch ID to associate with the token
story_idsNoOptional list of story IDs to restrict access
min_cacheNoOptional minimum cache time in seconds

Implementation Reference

  • The registerAccessTokens function registers all access token tools (including create_access_token) with the MCP server via server.tool().
    export function registerAccessTokens(server: McpServer): void {
      // Tool: retrieve_multiple_access_tokens
      server.tool(
        'retrieve_multiple_access_tokens',
        'Retrieve all access tokens for the current Storyblok space using the Management API.',
        {},
        async () => {
          try {
            const data = await apiGet('/api_keys/');
            return createJsonResponse(data);
          } catch (error) {
            if (error instanceof APIError) {
              return createErrorResponse(error);
            }
            throw error;
          }
        }
      );
    
      // Tool: create_access_token
      server.tool(
        'create_access_token',
        'Create a new access token in the current Storyblok space via the Management API.',
        {
          access: z
            .string()
            .describe("The access level for the token (e.g., 'draft', 'published')"),
          name: z.string().optional().describe('Optional name for the token'),
          branch_id: z
            .number()
            .optional()
            .describe('Optional branch ID to associate with the token'),
          story_ids: z
            .array(z.number())
            .optional()
            .describe('Optional list of story IDs to restrict access'),
          min_cache: z
            .number()
            .optional()
            .describe('Optional minimum cache time in seconds'),
        },
        async ({ access, name, branch_id, story_ids, min_cache }) => {
          try {
            const apiKey: Record<string, unknown> = { access };
            if (name !== undefined) apiKey.name = name;
            if (branch_id !== undefined) apiKey.branch_id = branch_id;
            if (story_ids !== undefined) apiKey.story_ids = story_ids;
            if (min_cache !== undefined) apiKey.min_cache = min_cache;
    
            const payload = { api_key: apiKey };
            const data = await apiPost('/api_keys/', payload);
            return createJsonResponse(data);
          } catch (error) {
            if (error instanceof APIError) {
              return createErrorResponse(error);
            }
            throw error;
          }
        }
      );
    
      // Tool: update_access_token
      server.tool(
        'update_access_token',
        'Update an existing access token in the current Storyblok space via the Management API.',
        {
          token_id: z.number().describe('The ID of the access token to update'),
          access: z.string().optional().describe('New access level for the token'),
          name: z.string().optional().describe('New name for the token'),
          branch_id: z
            .number()
            .optional()
            .describe('New branch ID to associate with the token'),
          story_ids: z
            .array(z.number())
            .optional()
            .describe('New list of story IDs to restrict access'),
          min_cache: z
            .number()
            .optional()
            .describe('New minimum cache time in seconds'),
        },
        async ({ token_id, access, name, branch_id, story_ids, min_cache }) => {
          try {
            const apiKey: Record<string, unknown> = {};
            if (access !== undefined) apiKey.access = access;
            if (name !== undefined) apiKey.name = name;
            if (branch_id !== undefined) apiKey.branch_id = branch_id;
            if (story_ids !== undefined) apiKey.story_ids = story_ids;
            if (min_cache !== undefined) apiKey.min_cache = min_cache;
    
            const payload = { api_key: apiKey };
            const url = buildManagementUrl(`/api_keys/${token_id}`);
            const response = await fetch(url, {
              method: 'PUT',
              headers: getManagementHeaders(),
              body: JSON.stringify(payload),
            });
    
            if (response.status === 204) {
              return {
                content: [{ type: 'text' as const, text: 'Access Token updated successfully.' }],
              };
            } else {
              return {
                isError: true,
                content: [
                  {
                    type: 'text' as const,
                    text: `Failed to update access token. Status code: ${response.status}`,
                  },
                ],
              };
            }
          } catch (error) {
            if (error instanceof APIError) {
              return createErrorResponse(error);
            }
            throw error;
          }
        }
      );
    
      // Tool: delete_access_token
      server.tool(
        'delete_access_token',
        'Delete an access token from the current Storyblok space using the Management API.',
        {
          token_id: z.number().describe('The ID of the access token to delete'),
        },
        async ({ token_id }) => {
          try {
            const url = buildManagementUrl(`/api_keys/${token_id}`);
            const response = await fetch(url, {
              method: 'DELETE',
              headers: getManagementHeaders(),
            });
    
            if (response.status === 204) {
              return {
                content: [{ type: 'text' as const, text: 'Access Token deleted successfully.' }],
              };
            } else {
              return {
                isError: true,
                content: [
                  {
                    type: 'text' as const,
                    text: `Failed to delete Access token. Status code: ${response.status}`,
                  },
                ],
              };
            }
          } catch (error) {
            if (error instanceof APIError) {
              return createErrorResponse(error);
            }
            throw error;
          }
        }
      );
    }
  • The create_access_token tool handler: accepts 'access' (required), and optional 'name', 'branch_id', 'story_ids', 'min_cache'; builds an apiKey payload and calls apiPost('/api_keys/', payload) to create a new access token via the Storyblok Management API.
    // Tool: create_access_token
    server.tool(
      'create_access_token',
      'Create a new access token in the current Storyblok space via the Management API.',
      {
        access: z
          .string()
          .describe("The access level for the token (e.g., 'draft', 'published')"),
        name: z.string().optional().describe('Optional name for the token'),
        branch_id: z
          .number()
          .optional()
          .describe('Optional branch ID to associate with the token'),
        story_ids: z
          .array(z.number())
          .optional()
          .describe('Optional list of story IDs to restrict access'),
        min_cache: z
          .number()
          .optional()
          .describe('Optional minimum cache time in seconds'),
      },
      async ({ access, name, branch_id, story_ids, min_cache }) => {
        try {
          const apiKey: Record<string, unknown> = { access };
          if (name !== undefined) apiKey.name = name;
          if (branch_id !== undefined) apiKey.branch_id = branch_id;
          if (story_ids !== undefined) apiKey.story_ids = story_ids;
          if (min_cache !== undefined) apiKey.min_cache = min_cache;
    
          const payload = { api_key: apiKey };
          const data = await apiPost('/api_keys/', payload);
          return createJsonResponse(data);
        } catch (error) {
          if (error instanceof APIError) {
            return createErrorResponse(error);
          }
          throw error;
        }
      }
    );
  • Zod schema defining the input parameters for create_access_token: 'access' (required string), 'name' (optional string), 'branch_id' (optional number), 'story_ids' (optional array of numbers), 'min_cache' (optional number).
    {
      access: z
        .string()
        .describe("The access level for the token (e.g., 'draft', 'published')"),
      name: z.string().optional().describe('Optional name for the token'),
      branch_id: z
        .number()
        .optional()
        .describe('Optional branch ID to associate with the token'),
      story_ids: z
        .array(z.number())
        .optional()
        .describe('Optional list of story IDs to restrict access'),
      min_cache: z
        .number()
        .optional()
        .describe('Optional minimum cache time in seconds'),
    },
  • Import of registerAccessTokens from the access-tokens module.
    import { registerAccessTokens } from './access-tokens.js';
  • Registration call: registerAccessTokens(server) is invoked within registerAllTools to wire up all access token tools including create_access_token.
    registerAccessTokens(server);
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, and the description does not disclose any behavioral traits such as side effects (e.g., whether creating a token invalidates others), authentication requirements, rate limits, or other consequences. This leaves the agent unaware of potential impacts.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, well-structured sentence that conveys the essential information without any redundant or unnecessary words. It is appropriately concise.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool has 5 parameters and no output schema, the description is incomplete. It does not explain the return value (e.g., the created token details) or any important behavioral context like the token lifecycle or restrictions. Sibling tools for retrieval, update, and deletion exist, so more context would help the agent understand when to use this tool.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema covers 100% of parameter descriptions. The description adds no additional meaning beyond what the schema provides, so a baseline score of 3 is appropriate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description explicitly states 'Create a new access token in the current Storyblok space via the Management API.' It uses a specific verb (create) and resource (access token), and the context of 'current Storyblok space' differentiates it from sibling tools like update_access_token or delete_access_token.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description does not provide explicit guidance on when to use this tool versus alternatives such as update_access_token or retrieve_multiple_access_tokens. It is adequate for understanding the basic action, but lacks exclusions or recommendations for context.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/hypescale/storyblok-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server