Skip to main content
Glama

add_location

Add a new location to MemoryMesh's knowledge graph, including details like name, type, description, status, notable features, and associated characters, quests, or artifacts for enhanced world-building.

Instructions

Add a new location to the knowledge graph

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
locationYes

Implementation Reference

  • Core handler logic for the 'add_location' tool (and similar add_<schema> tools). Checks if node exists, creates nodes and relationships using createSchemaNode, adds them to the graph in a transaction, and returns formatted response.
    switch (operation) {
        case 'add': {
            const nodeData = args[schemaName];
            const existingNodes = await knowledgeGraphManager.openNodes([nodeData.name]);
    
            if (existingNodes.nodes.length > 0) {
                throw new Error(`Node already exists: ${nodeData.name}`);
            }
    
            const {nodes, edges} = await createSchemaNode(nodeData, schema, schemaName);
    
            await knowledgeGraphManager.beginTransaction();
            try {
                await knowledgeGraphManager.addNodes(nodes);
                if (edges.length > 0) {
                    await knowledgeGraphManager.addEdges(edges);
                }
                await knowledgeGraphManager.commit();
    
                return formatToolResponse({
                    data: {nodes, edges},
                    actionTaken: `Created ${schemaName}: ${nodeData.name}`
                });
            } catch (error) {
                await knowledgeGraphManager.rollback();
                throw error;
            }
        }
  • SchemaBuilder.build() method generates the Tool inputSchema for 'add_location' from the schema configuration, used as the tool schema in dynamic tool generation.
    build(): SchemaConfig {
        return {
            ...this.schema as SchemaConfig,
            relationships: Object.fromEntries(this.relationships),
            metadataConfig: this.metadataConfig
        };
    }
  • ToolsRegistry.initialize() registers all dynamic tools (including 'add_location' if location schema exists) into the central tools Map by calling dynamicToolManager.getTools().
    async initialize(knowledgeGraphManager: ApplicationManager): Promise<void> {
        if (this.initialized) {
            return;
        }
    
        try {
            this.knowledgeGraphManager = knowledgeGraphManager;
    
            // Register static tools
            allStaticTools.forEach(tool => {
                this.tools.set(tool.name, tool);
            });
    
            // Initialize and register dynamic tools
            await dynamicToolManager.initialize();
            dynamicToolManager.getTools().forEach(tool => {
                this.tools.set(tool.name, tool);
            });
    
            this.initialized = true;
            console.error(`[ToolsRegistry] Initialized with ${this.tools.size} tools`);
        } catch (error) {
            console.error('[ToolsRegistry] Initialization error:', error);
            throw error;
        }
    }
  • DynamicSchemaToolRegistry.initialize() loads schema files, creates SchemaBuilder instances, generates add/update/delete tools (e.g. 'add_location'), and caches them.
    public async initialize(): Promise<void> {
        try {
            const SCHEMAS_DIR = CONFIG.PATHS.SCHEMAS_DIR;
            const schemaFiles = await fs.readdir(SCHEMAS_DIR);
    
            // Process schema files
            for (const file of schemaFiles) {
                if (file.endsWith('.schema.json')) {
                    const schemaName = path.basename(file, '.schema.json');
                    const schema = await SchemaLoader.loadSchema(schemaName);
                    this.schemas.set(schemaName, schema);
                }
            }
    
            // Generate tools for each schema
            for (const [schemaName, schema] of this.schemas.entries()) {
                const tools = await this.generateToolsForSchema(schemaName, schema);
                tools.forEach(tool => this.toolsCache.set(tool.name, tool));
            }
    
            console.error(`[DynamicSchemaTools] Initialized ${this.schemas.size} schemas and ${this.toolsCache.size} tools`);
        } catch (error) {
            console.error('[DynamicSchemaTools] Initialization error:', error);
            throw error;
        }
    }
  • SchemaBuilder constructor initializes the inputSchema structure specifically for 'add_*' named schemas (like 'add_location'), setting up the object wrapper and properties.
    constructor(name: string, description: string) {
        this.schema = {
            name,
            description,
            inputSchema: {
                type: "object",
                properties: {
                    [name.replace('add_', '')]: {
                        type: "object",
                        properties: {},
                        required: [],
                        additionalProperties: {
                            type: "string",
                            description: "Any additional properties"
                        }
                    }
                },
                required: [name.replace('add_', '')]
            }
        };
    
        this.relationships = new Map();
        this.metadataConfig = {
            requiredFields: [],
            optionalFields: [],
            excludeFields: []
        };
    }

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/CheMiguel23/MemoryMesh'

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