Skip to main content
Glama

Create or update entities with observations

create_entities

Create and update knowledge graph entities with observations to build persistent memory for AI assistants using SQLite storage.

Instructions

Create or update entities with observations

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
entitiesYes

Implementation Reference

  • The core database handler function that executes the create_entities logic. Validates input entities, checks if entities exist (upsert), manages observations in a SQL transaction, and performs SQLite operations.
    async create_entities(
    	entities: Array<{
    		name: string;
    		entityType: string;
    		observations: string[];
    	}>,
    ): Promise<void> {
    	const transaction = this.db.transaction(() => {
    		for (const entity of entities) {
    			// Validate entity name
    			if (
    				!entity.name ||
    				typeof entity.name !== 'string' ||
    				entity.name.trim() === ''
    			) {
    				throw new Error('Entity name must be a non-empty string');
    			}
    
    			// Validate entity type
    			if (
    				!entity.entityType ||
    				typeof entity.entityType !== 'string' ||
    				entity.entityType.trim() === ''
    			) {
    				throw new Error(
    					`Invalid entity type for entity "${entity.name}"`,
    				);
    			}
    
    			// Validate observations
    			if (
    				!Array.isArray(entity.observations) ||
    				entity.observations.length === 0
    			) {
    				throw new Error(
    					`Entity "${entity.name}" must have at least one observation`,
    				);
    			}
    
    			if (
    				!entity.observations.every(
    					(obs) => typeof obs === 'string' && obs.trim() !== '',
    				)
    			) {
    				throw new Error(
    					`Entity "${entity.name}" has invalid observations. All observations must be non-empty strings`,
    				);
    			}
    
    			// Check if entity exists
    			const existing = this.db
    				.prepare('SELECT name FROM entities WHERE name = ?')
    				.get(entity.name);
    
    			if (existing) {
    				// Update existing entity
    				this.db
    					.prepare(
    						'UPDATE entities SET entity_type = ? WHERE name = ?',
    					)
    					.run(entity.entityType, entity.name);
    			} else {
    				// Insert new entity
    				this.db
    					.prepare(
    						'INSERT INTO entities (name, entity_type) VALUES (?, ?)',
    					)
    					.run(entity.name, entity.entityType);
    			}
    
    			// Clear old observations
    			this.db
    				.prepare('DELETE FROM observations WHERE entity_name = ?')
    				.run(entity.name);
    
    			// Add new observations
    			const insert_obs = this.db.prepare(
    				'INSERT INTO observations (entity_name, content) VALUES (?, ?)',
    			);
    			for (const observation of entity.observations) {
    				insert_obs.run(entity.name, observation);
    			}
    		}
    	});
    
    	try {
    		transaction();
    	} catch (error) {
    		// Wrap all errors with context
    		throw new Error(
    			`Entity operation failed: ${
    				error instanceof Error ? error.message : String(error)
    			}`,
    		);
    	}
    }
  • Valibot schema defining the input validation for create_entities tool. Specifies that entities must be an array of objects containing name (string), entityType (string), and observations (array of strings).
    const CreateEntitiesSchema = v.object({
    	entities: v.array(
    		v.object({
    			name: v.string(),
    			entityType: v.string(),
    			observations: v.array(v.string()),
    		}),
    	),
    });
  • src/index.ts:64-103 (registration)
    MCP tool registration for 'create_entities'. Defines the tool name, description, binds the schema, and provides the handler function that calls db.create_entities() and returns success/error responses.
    server.tool<typeof CreateEntitiesSchema>(
    	{
    		name: 'create_entities',
    		description: 'Create or update entities with observations',
    		schema: CreateEntitiesSchema,
    	},
    	async ({ entities }) => {
    		try {
    			await db.create_entities(entities);
    			return {
    				content: [
    					{
    						type: 'text' as const,
    						text: `Successfully processed ${entities.length} entities (created new or updated existing)`,
    					},
    				],
    			};
    		} 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,
    			};
    		}
    	},
    );
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden. While 'Create or update' suggests upsert semantics, it fails to specify merge behavior (observations appended or replaced?), side effects, return values, or authorization requirements.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness3/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely brief (6 words), but this conciseness results from under-specification rather than efficient information density. It wastes the opportunity to provide essential context.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the nested object structure (entities with name/entityType/observations), zero schema descriptions, and no output schema, the description is inadequate. It omits critical details about the data model and operation results.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, yet the description does not compensate by explaining the entities array structure, the semantic meaning of observations, or valid values for entityType. It merely mentions 'observations' without elaborating.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose2/5

Does the description clearly state what the tool does and how it differs from similar tools?

Tautological: description restates name/title.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance provided on when to use this tool versus alternatives (e.g., when to create entities vs. relations), nor any prerequisites or conditions for the update behavior.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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-sqlite'

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