anytype_create_object
Create a new object in an Anytype space with customizable properties, markdown content, and icons to organize information.
Instructions
Crea un nuevo objeto en un espacio
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| space_id | Yes | ID del espacio | |
| name | Yes | Nombre del objeto | |
| type_key | No | Tipo de objeto | page |
| body | No | Contenido del objeto (Markdown) | |
| markdown | No | Contenido del objeto (Markdown) - alias para body | |
| icon | No | Icono | |
| properties | No | Propiedades del objeto | |
| template_id | No | ID de plantilla |
Implementation Reference
- src/handlers/objects.ts:125-162 (handler)The main handler function that implements the logic for creating a new Anytype object, processing properties including tags, making the API POST request, and formatting the response.export async function handleCreateObject(args: any) { const { space_id, properties, ...objectData } = args; // Handle markdown alias if (objectData.markdown && !objectData.body) { objectData.body = objectData.markdown; delete objectData.markdown; } // Process and validate tags if properties are provided let processedProperties = []; if (properties && Array.isArray(properties)) { processedProperties = await validateAndProcessTags(space_id, properties); console.log(`Processed ${processedProperties.length} properties for new object`); } const finalObjectData = { ...objectData, ...(processedProperties.length > 0 && { properties: processedProperties }) }; const response = await makeRequest(`/v1/spaces/${space_id}/objects`, { method: 'POST', body: JSON.stringify(finalObjectData), }); return { content: [{ type: 'text', text: JSON.stringify({ message: 'Object created successfully', object: response, processed_properties: processedProperties.length, tag_assignments: processedProperties.filter(p => p.multi_select || p.select).length }, null, 2) }] }; }
- src/tools/objects.ts:46-62 (schema)The tool schema definition including input parameters, descriptions, and validation rules for anytype_create_object.name: 'anytype_create_object', description: 'Crea un nuevo objeto en un espacio', inputSchema: { type: 'object', properties: { space_id: { type: 'string', description: 'ID del espacio' }, name: { type: 'string', description: 'Nombre del objeto' }, type_key: { type: 'string', description: 'Tipo de objeto', default: 'page' }, body: { type: 'string', description: 'Contenido del objeto (Markdown)' }, markdown: { type: 'string', description: 'Contenido del objeto (Markdown) - alias para body' }, icon: iconSchema, properties: objectPropertiesSchema, template_id: { type: 'string', description: 'ID de plantilla' }, }, required: ['space_id', 'name'], }, },
- src/index.ts:128-129 (registration)The dispatch case in the main MCP server request handler that routes calls to the anytype_create_object tool to its handler function.case 'anytype_create_object': return await handleCreateObject(args);
- src/handlers/objects.ts:9-49 (helper)Helper function used by the handler to validate and process object properties, particularly handling multi-select and select tags.async function validateAndProcessTags(spaceId: string, properties: any[]): Promise<any[]> { if (!properties || !Array.isArray(properties)) { return []; } const processedProperties = []; for (const prop of properties) { const processedProp = { ...prop }; // Handle multi_select properties (tags) if (prop.multi_select && Array.isArray(prop.multi_select)) { try { // Validate that all tag IDs exist // Note: We can't easily validate individual tags without knowing the property_id // This is a limitation of the current API structure console.log(`Processing multi_select property "${prop.key}" with ${prop.multi_select.length} tags`); processedProp.multi_select = prop.multi_select; } catch (error) { console.warn(`Warning: Could not validate tags for property "${prop.key}":`, error); // Keep the tags anyway, let the API handle validation processedProp.multi_select = prop.multi_select; } } // Handle single select properties if (prop.select) { try { console.log(`Processing select property "${prop.key}" with tag: ${prop.select}`); processedProp.select = prop.select; } catch (error) { console.warn(`Warning: Could not validate tag for property "${prop.key}":`, error); processedProp.select = prop.select; } } processedProperties.push(processedProp); } return processedProperties; }