Skip to main content
Glama

create_entities

Add multiple new entities to a knowledge graph, specifying names, types, and associated observations for semantic indexing and search.

Instructions

Create multiple new entities in the knowledge graph

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
entitiesYes

Implementation Reference

  • The main handler function for the 'create_entities' tool. It validates the input entities array, calls knowledgeGraphManager.createEntities, and returns a formatted text response.
    export const createEntitiesHandler: ToolHandler = async (args) => {
      if (!args.entities || !Array.isArray(args.entities)) {
        throw new Error("The 'entities' parameter is required and must be an array");
      }
    
      // Valider chaque entité
      for (const entity of args.entities) {
        if (!entity.name || typeof entity.name !== 'string') {
          throw new Error("Each entity must have a 'name' string property");
        }
        if (!entity.entityType || typeof entity.entityType !== 'string') {
          throw new Error("Each entity must have an 'entityType' string property");
        }
        if (!entity.observations || !Array.isArray(entity.observations)) {
          throw new Error("Each entity must have an 'observations' array property");
        }
      }
    
      try {
        const result = await knowledgeGraphManager.createEntities(args.entities);
        return { 
          content: [{ 
            type: "text", 
            text: JSON.stringify(result, null, 2) 
          }] 
        };
      } catch (error) {
        console.error("Error in create_entities tool:", error);
        throw error;
      }
    };
  • The tool definition including name, description, and input schema for validating the entities parameter.
    export const createEntitiesTool: ToolDefinition = {
      name: "create_entities",
      description: "Create multiple new entities in the knowledge graph",
      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"
                },
              },
              required: ["name", "entityType", "observations"],
            },
          },
        },
        required: ["entities"],
      },
    };
  • Core helper function in KnowledgeGraphManager that loads the graph from memory.json, filters out existing entities by name, adds new ones, saves the graph, and returns the added entities.
    async createEntities(entities: EntityInput[]): Promise<EntityInput[]> {
      const graph = await this.loadGraph();
      const newEntities = entities.filter(e => !graph.entities.some(existingEntity => existingEntity.name === e.name));
      graph.entities.push(...newEntities);
      await this.saveGraph(graph);
      return newEntities;
    }
  • The getExpectedTools function lists 'create_entities' as one of the expected tools to be automatically registered by the AutoRegistry system.
    export function getExpectedTools(): string[] {
      return [
        // Outils Graph (9 outils)
        'create_entities',
        'create_relations',
        'add_observations',
        'delete_entities',
        'delete_observations',
        'delete_relations',
        'read_graph',
        'search_nodes',
        'open_nodes',
    
        // Outils RAG (5 outils - avec injection_rag comme outil principal)
        'injection_rag',      // Nouvel outil principal
        'index_project',      // Alias déprécié (rétrocompatibilité)
        'search_code',
        'manage_projects',
        'update_project'
      ];

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/ali-48/rag-mcp-server'

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