Skip to main content
Glama

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
NameRequiredDescriptionDefault
nameYesName of the entity to delete

Implementation Reference

  • 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, },
  • 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, }; } },
  • 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) }`, ); } }

Other Tools

Related 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/spences10/mcp-memory-libsql'

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