Skip to main content
Glama

create_entities

Generate new entities with observations and optional embeddings using MCP server’s libSQL for efficient memory management and semantic knowledge storage.

Instructions

Create new entities with observations and optional embeddings

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
entitiesYes

Implementation Reference

  • Core handler implementation: Validates input entities, performs upsert (update or insert) on entities table, manages observations in transaction per entity.
    async create_entities(
    	entities: Array<{
    		name: string;
    		entityType: string;
    		observations: string[];
    	}>,
    ): Promise<void> {
    	try {
    		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`,
    				);
    			}
    
    			// Start a transaction
    			const txn = await this.client.transaction('write');
    
    			try {
    				// First try to update
    				const result = await txn.execute({
    					sql: 'UPDATE entities SET entity_type = ? WHERE name = ?',
    					args: [entity.entityType, entity.name],
    				});
    
    				// If no rows affected, do insert
    				if (result.rowsAffected === 0) {
    					await txn.execute({
    						sql: 'INSERT INTO entities (name, entity_type) VALUES (?, ?)',
    						args: [entity.name, entity.entityType],
    					});
    				}
    
    				// Clear old observations
    				await txn.execute({
    					sql: 'DELETE FROM observations WHERE entity_name = ?',
    					args: [entity.name],
    				});
    
    				// Add new observations
    				for (const observation of entity.observations) {
    					await txn.execute({
    						sql: 'INSERT INTO observations (entity_name, content) VALUES (?, ?)',
    						args: [entity.name, observation],
    					});
    				}
    
    				await txn.commit();
    			} catch (error) {
    				await txn.rollback();
    				throw error;
    			}
    		}
    	} catch (error) {
    		// Wrap all errors with context
    		throw new Error(
    			`Entity operation failed: ${
    				error instanceof Error ? error.message : String(error)
    			}`,
    		);
    	}
    }
  • Input schema using Valibot for validating the entities array with name, entityType, and observations.
    const CreateEntitiesSchema = v.object({
    	entities: v.array(
    		v.object({
    			name: v.string(),
    			entityType: v.string(),
    			observations: v.array(v.string()),
    		}),
    	),
    });
  • src/index.ts:60-99 (registration)
    MCP server tool registration with name, description, schema, and thin async handler that calls the db.create_entities method and handles response/error.
    server.tool<typeof CreateEntitiesSchema>(
    	{
    		name: 'create_entities',
    		description: 'Create new 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?

No annotations are provided, so the description carries full burden. It states 'Create new entities' which implies a write/mutation operation, but doesn't disclose behavioral traits like permissions needed, whether it's idempotent, rate limits, or what happens on failure. The mention of 'optional embeddings' hints at functionality but lacks operational context.

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

Conciseness5/5

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

The description is a single, efficient sentence with zero waste. It's front-loaded with the core action and resource, and every word ('new entities', 'observations', 'optional embeddings') adds value. No extraneous information or repetition.

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 no annotations, no output schema, and a single but complex parameter (nested array of objects), the description is incomplete. It doesn't explain return values, error handling, or the full scope of entity creation (e.g., validation rules, uniqueness constraints). For a mutation tool with rich nested data, more context is needed.

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

Parameters4/5

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

Schema description coverage is 0%, so the description must compensate. It adds meaning by specifying that entities include 'observations and optional embeddings', which clarifies the purpose of the 'entities' array parameter beyond the schema's structural definition. However, it doesn't detail all nested fields like 'entityType' or 'name', leaving some semantics uncovered.

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

Purpose4/5

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

The description clearly states the verb 'Create' and the resource 'new entities', specifying they include 'observations and optional embeddings'. It distinguishes from siblings like delete_entity (deletion) and read_graph/search_nodes (read operations), though not explicitly named. The purpose is specific but could more directly contrast with create_relations.

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 on when to use this tool versus alternatives is provided. It doesn't mention prerequisites, when not to use it, or compare with siblings like create_relations (for relationships) or search_nodes (for finding existing entities). The description implies usage for entity creation but offers no contextual boundaries.

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

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