anytype_create_type
Create custom object types in Anytype by defining unique keys, names, properties, and layouts for structured data organization.
Instructions
Crea un nuevo tipo de objeto
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| space_id | Yes | ID del espacio | |
| key | No | Clave única del tipo | |
| name | Yes | Nombre del tipo | |
| plural_name | No | Nombre plural del tipo (se auto-genera si no se proporciona) | |
| description | No | Descripción del tipo | |
| icon | No | Icono | |
| layout | No | Layout del tipo (default: basic) | |
| properties | No | IDs de propiedades |
Implementation Reference
- src/handlers/types-tags.ts:26-64 (handler)The core handler function that implements the 'anytype_create_type' tool. It validates inputs, auto-generates missing fields like plural_name and key, constructs the request body, and makes a POST request to the Anytype API endpoint /v1/spaces/{space_id}/types.export async function handleCreateType(args: any) { const { space_id, name, plural_name, description, icon, key, layout, properties, ...typeData } = args; // Validate required fields based on API testing and best practices if (!name) { return { content: [{ type: 'text', text: JSON.stringify({ error: 'Missing required field', message: 'Field "name" is required for creating a type', required_fields: ['name', 'plural_name'], provided_fields: Object.keys(args) }, null, 2) }] }; } // Auto-generate plural_name if not provided const finalPluralName = plural_name || (name.endsWith('s') ? name : name + 's'); // Build request body according to API specification with required plural_name and key const requestBody = { name, plural_name: finalPluralName, // Required field (not documented but mandatory) description, icon, key: key || `${name.toLowerCase().replace(/\s+/g, '_')}_${Date.now()}`, // Generate unique key if not provided layout: layout || 'basic', // Default to basic layout (required field) properties: properties || [], // Array of property IDs ...typeData }; const response = await makeRequest(`/v1/spaces/${space_id}/types`, { method: 'POST', body: JSON.stringify(requestBody), }); return { content: [{ type: 'text', text: JSON.stringify(response, null, 2) }] }; }
- src/tools/types.ts:31-47 (schema)The input schema definition for the 'anytype_create_type' tool, defining parameters like space_id, name, key, plural_name, etc., and marking required fields.{ name: 'anytype_create_type', description: 'Crea un nuevo tipo de objeto', inputSchema: { type: 'object', properties: { space_id: { type: 'string', description: 'ID del espacio' }, key: { type: 'string', description: 'Clave única del tipo' }, name: { type: 'string', description: 'Nombre del tipo' }, plural_name: { type: 'string', description: 'Nombre plural del tipo (se auto-genera si no se proporciona)' }, description: { type: 'string', description: 'Descripción del tipo' }, icon: iconSchema, layout: { type: 'string', description: 'Layout del tipo (default: basic)' }, properties: { type: 'array', items: { type: 'string' }, description: 'IDs de propiedades' }, }, required: ['space_id', 'name'], },
- src/index.ts:152-153 (registration)Registration of the tool handler in the main switch dispatcher for CallToolRequest in the MCP server.case 'anytype_create_type': return await handleCreateType(args);
- src/index.ts:54-67 (registration)Import statement registering the handleCreateType handler function from types-tags module.import { handleListTypes, handleGetType, handleCreateType, handleUpdateType, handleDeleteType, handleListTags, handleGetTag, handleCreateTag, handleUpdateTag, handleDeleteTag, handleListTemplates, handleGetTemplate } from './handlers/types-tags.js';
- src/index.ts:85-93 (registration)Inclusion of typeTools (containing the tool schema) in the combined tools list registered with the MCP server for ListToolsRequest.const tools = [ ...spaceTools, ...objectTools, ...propertyTools, ...typeTools, ...tagTools, ...templateTools, ...listTools, ];