delete_entity
Remove an entity and its associated data (observations, relations) from the MCP server mcp-memory-libsql. Input the entity name to ensure complete data deletion, enabling efficient entity management.
Instructions
Delete an entity and all its associated data (observations and relations)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | Name of the entity to delete |
Implementation Reference
- src/index.ts:48-50 (schema)Valibot input schema for the delete_entity tool, requiring a 'name' string parameter.const DeleteEntitySchema = v.object({ name: v.string(), });
- src/index.ts:234-240 (registration)MCP server tool registration for 'delete_entity', specifying name, description, and schema.server.tool<typeof DeleteEntitySchema>( { name: 'delete_entity', description: 'Delete an entity and all its associated data (observations and relations)', schema: DeleteEntitySchema, },
- src/index.ts:241-273 (handler)Handler function that executes the delete_entity tool logic: calls database delete_entity, returns success message or error response.async ({ name }) => { try { await db.delete_entity(name); return { content: [ { type: 'text' as const, text: `Successfully deleted entity "${name}" and its associated data`, }, ], }; } catch (error) { return { content: [ { type: 'text' as const, text: JSON.stringify( { error: 'internal_error', message: error instanceof Error ? error.message : 'Unknown error', }, null, 2, ), }, ], isError: true, }; } },
- src/db/client.ts:263-303 (helper)DatabaseManager helper method implementing the actual deletion: checks existence, deletes observations, relations, and entity in batch.async delete_entity(name: string): Promise<void> { try { // Check if entity exists first const existing = await this.client.execute({ sql: 'SELECT name FROM entities WHERE name = ?', args: [name], }); if (existing.rows.length === 0) { throw new Error(`Entity not found: ${name}`); } // Prepare batch statements for deletion const batch_statements = [ { // Delete associated observations first (due to foreign key) sql: 'DELETE FROM observations WHERE entity_name = ?', args: [name], }, { // Delete associated relations (due to foreign key) sql: 'DELETE FROM relations WHERE source = ? OR target = ?', args: [name, name], }, { // Delete the entity sql: 'DELETE FROM entities WHERE name = ?', args: [name], }, ]; // Execute all deletions in a single batch transaction await this.client.batch(batch_statements, 'write'); } catch (error) { throw new Error( `Failed to delete entity "${name}": ${ error instanceof Error ? error.message : String(error) }`, ); } }