Skip to main content
Glama

delete_relation

Remove specific entity relations by specifying source, target, and relation type, enhancing data management on the libSQL-based server.

Instructions

Delete a specific relation between entities

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sourceYesSource entity name
targetYesTarget entity name
typeYesType of relation

Implementation Reference

  • The handler function that implements the core logic of the 'delete_relation' MCP tool. It calls the database delete_relation method and formats the success or error response.
    async ({ source, target, type }) => {
    	try {
    		await db.delete_relation(source, target, type);
    		return {
    			content: [
    				{
    					type: 'text' as const,
    					text: `Successfully deleted relation: ${source} -> ${target} (${type})`,
    				},
    			],
    		};
    	} 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,
    		};
    	}
    },
  • Valibot schema defining the input parameters for the delete_relation tool: source, target, and type as strings.
    const DeleteRelationSchema = v.object({
    	source: v.string(),
    	target: v.string(),
    	type: v.string(),
    });
  • src/index.ts:277-282 (registration)
    Registration of the 'delete_relation' tool on the MCP server, specifying name, description, and schema.
    server.tool<typeof DeleteRelationSchema>(
    	{
    		name: 'delete_relation',
    		description: 'Delete a specific relation between entities',
    		schema: DeleteRelationSchema,
    	},
  • Database helper method that performs the actual SQL DELETE operation for a specific relation and handles errors.
    async delete_relation(
    	source: string,
    	target: string,
    	type: string,
    ): Promise<void> {
    	try {
    		const result = await this.client.execute({
    			sql: 'DELETE FROM relations WHERE source = ? AND target = ? AND relation_type = ?',
    			args: [source, target, type],
    		});
    
    		if (result.rowsAffected === 0) {
    			throw new Error(
    				`Relation not found: ${source} -> ${target} (${type})`,
    			);
    		}
    	} catch (error) {
    		throw new Error(
    			`Failed to delete relation: ${
    				error instanceof Error ? error.message : String(error)
    			}`,
    		);
    	}
    }
Install Server

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