Skip to main content
Glama

create_entities

Add multiple entities to the Memento MCP knowledge graph memory system, specifying type, observations, and optional metadata for enhanced data organization and retrieval.

Instructions

Create multiple new entities in your Memento MCP knowledge graph memory system

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
entitiesYes

Implementation Reference

  • The primary handler function for the 'create_entities' MCP tool. It extracts entities from args, delegates to KnowledgeGraphManager.createEntities, and formats the result as MCP response content.
    export async function handleCreateEntities( args: Record<string, unknown>, // eslint-disable-next-line @typescript-eslint/no-explicit-any knowledgeGraphManager: any ): Promise<{ content: Array<{ type: string; text: string }> }> { const result = await knowledgeGraphManager.createEntities(args.entities); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2), }, ], }; }
  • The input schema and description for the 'create_entities' tool, defining the expected structure of the entities array with required fields name, entityType, observations.
    { name: 'create_entities', description: 'Create multiple new entities in your Memento MCP knowledge graph memory system', inputSchema: { type: 'object', properties: { entities: { type: 'array', items: { type: 'object', properties: { name: { type: 'string', description: 'The name of the entity', }, entityType: { type: 'string', description: 'The type of the entity', }, observations: { type: 'array', items: { type: 'string', }, description: 'An array of observation contents associated with the entity', }, // Temporal fields - optional id: { type: 'string', description: 'Optional entity ID' }, version: { type: 'number', description: 'Optional entity version' }, createdAt: { type: 'number', description: 'Optional creation timestamp' }, updatedAt: { type: 'number', description: 'Optional update timestamp' }, validFrom: { type: 'number', description: 'Optional validity start timestamp' }, validTo: { type: 'number', description: 'Optional validity end timestamp' }, changedBy: { type: 'string', description: 'Optional user/system identifier' }, }, required: ['name', 'entityType', 'observations'], }, }, }, required: ['entities'], }, },
  • Registration and dispatch logic in the main callToolHandler switch statement that routes 'create_entities' calls to the specific handler.
    switch (name) { case 'create_entities': return await toolHandlers.handleCreateEntities(args, knowledgeGraphManager);
  • Re-export of the handleCreateEntities function from toolHandlers index, making it available for import in callToolHandler.
    export { handleCreateEntities } from './createEntities.js';
  • Supporting method in KnowledgeGraphManager that implements the core entity creation logic: loads graph, merges/updates entities and observations, persists via storageProvider or file, handles embeddings and jobs.
    async createEntities(entities: Entity[]): Promise<Entity[]> { // If no entities to create, load graph, save it unchanged and return empty array early if (!entities || entities.length === 0) { if (!this.storageProvider) { const graph = await this.loadGraph(); await this.saveGraph(graph); } return []; } // Filter entities to only include those we need to create const graph = await this.loadGraph(); const entitiesMap = new Map<string, Entity>(); // Add existing entities to the map for (const entity of graph.entities) { entitiesMap.set(entity.name, entity); } // Process new entities let entitiesArray = [...graph.entities]; const newEntities: Entity[] = []; for (const entity of entities) { // Check if entity already exists if (entitiesMap.has(entity.name)) { // Update existing entity by merging observations const existingEntity = entitiesMap.get(entity.name)!; const updatedObservations = new Set([ ...existingEntity.observations, ...entity.observations, ]); existingEntity.observations = Array.from(updatedObservations); // Update the entity in our map and array entitiesMap.set(entity.name, existingEntity); entitiesArray = entitiesArray.map((e) => (e.name === entity.name ? existingEntity : e)); } else { // Add new entity entitiesMap.set(entity.name, entity); entitiesArray.push(entity); newEntities.push(entity); } } // Update the graph with our modified entities graph.entities = entitiesArray; // Save the graph regardless of whether we have new entities if (!this.storageProvider) { await this.saveGraph(graph); } // If no new entities, just return empty array if (newEntities.length === 0) { return []; } let createdEntities: Entity[] = []; if (this.storageProvider) { // Use storage provider for creating entities createdEntities = await this.storageProvider.createEntities(newEntities); // Add entities with existing embeddings to vector store for (const entity of createdEntities) { if (entity.embedding && entity.embedding.vector) { try { const vectorStore = await this.ensureVectorStore().catch(() => undefined); if (vectorStore) { // Add metadata for filtering const metadata = { name: entity.name, entityType: entity.entityType, }; await vectorStore.addVector(entity.name, entity.embedding.vector, metadata); logger.debug(`Added vector for entity ${entity.name} to vector store`); } } catch (error) { logger.error(`Failed to add vector for entity ${entity.name} to vector store`, error); // Continue with scheduling embedding job } } } // Schedule embedding jobs if manager is provided if (this.embeddingJobManager) { for (const entity of createdEntities) { await this.embeddingJobManager.scheduleEntityEmbedding(entity.name, 1); } } } else { // No storage provider, so use the entities we've already added to the graph // Add entities with existing embeddings to vector store for (const entity of newEntities) { if (entity.embedding && entity.embedding.vector) { try { const vectorStore = await this.ensureVectorStore().catch(() => undefined); if (vectorStore) { // Add metadata for filtering const metadata = { name: entity.name, entityType: entity.entityType, }; await vectorStore.addVector(entity.name, entity.embedding.vector, metadata); logger.debug(`Added vector for entity ${entity.name} to vector store`); } } catch (error) { logger.error(`Failed to add vector for entity ${entity.name} to vector store`, error); // Continue with scheduling embedding job } } } if (this.embeddingJobManager) { for (const entity of newEntities) { await this.embeddingJobManager.scheduleEntityEmbedding(entity.name, 1); } } createdEntities = newEntities; } return createdEntities; }

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/gannonh/memento-mcp'

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