Skip to main content
Glama

update_artifact

Modify existing artifact details in MemoryMesh's knowledge graph, including metadata, attributes, and relationships with characters, quests, and locations.

Instructions

Update an existing artifact in the knowledge graph

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
update_artifactYes

Implementation Reference

  • Main handler function that executes the update_artifact tool logic. Finds the node, processes updates to metadata and edges, performs transactional updates via ApplicationManager.
    export async function handleSchemaUpdate(
        updates: NodeData,
        schema: SchemaConfig,
        nodeType: string,
        applicationManager: ApplicationManager
    ): Promise<ToolResponse> {
        try {
            // Start a transaction to ensure atomic updates
            await applicationManager.beginTransaction();
    
            // Get the complete current state
            const fullGraph = await applicationManager.readGraph();
            const node = fullGraph.nodes.find((n: Node) => n.nodeType === nodeType && n.name === updates.name);
    
            if (!node) {
                await applicationManager.rollback();
                return formatToolError({
                    operation: 'updateSchema',
                    error: `${nodeType} "${updates.name}" not found`,
                    context: {updates, nodeType},
                    suggestions: ["Verify the node exists", "Check node type matches"]
                });
            }
    
            try {
                // Process updates
                const {metadata, edgeChanges} = await updateSchemaNode(
                    updates,
                    node,
                    schema,
                    fullGraph
                );
    
                // Update the node first
                const updatedNode: Node = {
                    ...node,
                    metadata
                };
                await applicationManager.updateNodes([updatedNode]);
    
                // Then handle edges if there are any changes
                if (edgeChanges.remove.length > 0) {
                    await applicationManager.deleteEdges(edgeChanges.remove);
                }
    
                if (edgeChanges.add.length > 0) {
                    await applicationManager.addEdges(edgeChanges.add);
                }
    
                // If everything succeeded, commit the transaction
                await applicationManager.commit();
    
                return formatToolResponse({
                    data: {
                        updatedNode,
                        edgeChanges
                    },
                    actionTaken: `Updated ${nodeType}: ${updatedNode.name}`
                });
    
            } catch (error) {
                // If anything fails, rollback all changes
                await applicationManager.rollback();
                throw error;
            }
    
        } catch (error) {
            if (applicationManager.isInTransaction()) {
                await applicationManager.rollback();
            }
    
            return formatToolError({
                operation: 'updateSchema',
                error: error instanceof Error ? error.message : 'Unknown error occurred',
                context: {updates, schema, nodeType},
                suggestions: [
                    "Check all required fields are provided",
                    "Verify relationship targets exist"
                ],
                recoverySteps: [
                    "Review schema requirements",
                    "Ensure node exists before updating"
                ]
            });
        }
    }
  • Helper function that processes the update data: parses current metadata, applies changes to metadata and computes edge additions/removals for relationships.
    export async function updateSchemaNode(
        updates: NodeData,
        currentNode: Node,
        schema: SchemaConfig,
        currentGraph: Graph
    ): Promise<SchemaUpdateResult> {
        const {metadataConfig, relationships} = schema;
        const metadata = new Map<string, string>();
        const edgeChanges = {
            remove: [] as Edge[],
            add: [] as Edge[]
        };
    
        // Create a set of all schema-defined fields
        const schemaFields = new Set<string>([
            ...metadataConfig.requiredFields,
            ...metadataConfig.optionalFields,
            ...(metadataConfig.excludeFields || []),
            'name',
            'metadata'
        ]);
    
        // Add relationship fields to schema fields
        if (relationships) {
            Object.keys(relationships).forEach(field => schemaFields.add(field));
        }
    
        // Process existing metadata into the Map
        currentNode.metadata.forEach(meta => {
            const colonIndex = meta.indexOf(':');
            if (colonIndex !== -1) {
                const key = meta.substring(0, colonIndex).trim().toLowerCase();
                const value = meta.substring(colonIndex + 1).trim();
                metadata.set(key, value);
            }
        });
    
        const updateMetadataEntry = (key: string, value: unknown) => {
            const formattedValue = Array.isArray(value) ? value.join(', ') : String(value);
            metadata.set(key.toLowerCase(), formattedValue);
        };
    
        // Process standard metadata fields
        const allSchemaFields = [...metadataConfig.requiredFields, ...metadataConfig.optionalFields];
        for (const field of allSchemaFields) {
            if (updates[field] !== undefined && (!relationships || !relationships[field])) {
                updateMetadataEntry(field, updates[field]);
            }
        }
    
        // Process relationships if they exist in the schema
        if (relationships) {
            for (const [field, config] of Object.entries(relationships)) {
                // Only process relationship if it's being updated
                if (updates[field] !== undefined) {
                    // Get all existing edges for this relationship type from this node
                    const existingEdges = currentGraph.edges.filter(edge =>
                        edge.from === currentNode.name &&
                        edge.edgeType === config.edgeType
                    );
    
                    // Only mark edges for removal if they're part of this relationship type
                    edgeChanges.remove.push(...existingEdges);
    
                    // Add new edges
                    const value = updates[field];
                    if (Array.isArray(value)) {
                        value.forEach((target: string) => {
                            edgeChanges.add.push({
                                type: 'edge',
                                from: currentNode.name,
                                to: target,
                                edgeType: config.edgeType
                            });
                        });
                    } else if (value) {
                        edgeChanges.add.push({
                            type: 'edge',
                            from: currentNode.name,
                            to: value as string,
                            edgeType: config.edgeType
                        });
                    }
    
                    updateMetadataEntry(field, value);
                }
            }
        }
    
        // Process additional fields not defined in schema
        for (const [key, value] of Object.entries(updates)) {
            if (!schemaFields.has(key) && value !== undefined) {
                updateMetadataEntry(key, value);
            }
        }
    
        const updatedMetadata = Array.from(metadata).map(([key, value]) => {
            const capitalizedKey = key.charAt(0).toUpperCase() + key.slice(1);
            return `${capitalizedKey}: ${value}`;
        });
    
        return {
            metadata: updatedMetadata,
            edgeChanges
        };
    }
  • Generates the input schema specifically for update tools like update_artifact by copying properties from the base add schema, making them optional, and adding support for metadata and relationships.
    createUpdateSchema(excludeFields: Set<string> = new Set()): SchemaConfig {
        const schemaName = this.schema.name!.replace('add_', 'update_');
        const updateSchemaBuilder = new SchemaBuilder(
            schemaName,
            `Update an existing ${schemaName.replace('update_', '')} in the knowledge graph`
        );
    
        const baseProperties = this.schema.inputSchema!.properties[this.schema.name!.replace('add_', '')].properties;
    
        // Copy properties except excluded ones
        Object.entries(baseProperties).forEach(([propName, propValue]) => {
            if (!excludeFields.has(propName)) {
                if (propValue.type === 'array') {
                    updateSchemaBuilder.addArrayProperty(
                        propName,
                        propValue.description,
                        false,
                        propValue.items?.enum
                    );
                } else {
                    updateSchemaBuilder.addStringProperty(
                        propName,
                        propValue.description,
                        false,
                        propValue.enum
                    );
                }
            }
        });
    
        // Copy relationships
        this.relationships.forEach((config, propName) => {
            if (!excludeFields.has(propName)) {
                updateSchemaBuilder.addRelationship(
                    propName,
                    config.edgeType,
                    config.description || 'Relationship property',
                    config.nodeType || null
                );
            }
        });
    
        // Add metadata array
        updateSchemaBuilder.addArrayProperty(
            'metadata',
            'An array of metadata contents to replace the existing metadata'
        );
    
        return updateSchemaBuilder.build();
    }
  • Dynamically generates Tool objects including the update_<schemaName> tool from loaded schemas and adds them to the registry cache.
    private async generateToolsForSchema(schemaName: string, schema: SchemaBuilder): Promise<Tool[]> {
        const tools: Tool[] = [];
        const baseSchema = schema.build();
    
        // Add tool
        tools.push(baseSchema as unknown as Tool);
    
        // Update tool
        const updateSchema = schema.createUpdateSchema();
        tools.push(updateSchema as unknown as Tool);
    
        // Delete tool
        const deleteSchema: Tool = {
            name: `delete_${schemaName}`,
            description: `Delete
            an existing
            ${schemaName}
            from
            the
            knowledge
            graph`,
            inputSchema: {
                type: "object",
                properties: {
                    [`delete_${schemaName}`]: {
                        type: "object",
                        description: `Delete parameters for ${schemaName}`,
                        properties: {
                            name: {
                                type: "string",
                                description: `The name of the ${schemaName} to delete`
                            }
                        },
                        required: ["name"]
                    }
                },
                required: [`delete_${schemaName}`]
            }
        };
    
        tools.push(deleteSchema);
        return tools;
    }
  • Tool call dispatcher that matches 'update_<schema>' tool names and routes to the specific update handler.
    case 'update': {
        return handleSchemaUpdate(
            args[`update_${schemaName}`],
            schema,
            schemaName,
            knowledgeGraphManager
        );
    }
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 for behavioral disclosure. 'Update an existing artifact' implies a mutation operation, but the description doesn't specify required permissions, whether changes are partial or complete replacements, what happens to unspecified fields, or error conditions (e.g., if artifact doesn't exist). For a mutation tool with zero annotation coverage, this leaves critical behavioral aspects undocumented.

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 that directly states the tool's function. There's no wasted verbiage or unnecessary elaboration. It's appropriately sized for a basic declaration, though this conciseness comes at the cost of completeness.

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

Completeness1/5

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

For a mutation tool with 11 nested parameters, 0% schema description coverage, no annotations, and no output schema, the description is completely inadequate. It doesn't explain what an 'artifact' represents in this context, what fields can be updated, how the update operation works, or what to expect in return. The agent would be operating with minimal guidance in a complex parameter space.

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

Parameters1/5

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

Schema description coverage is 0%, meaning none of the parameters have descriptions in the schema. The tool description provides no information about parameters beyond the single top-level 'update_artifact' object. With 11 nested properties (name, description, effects, etc.) completely undocumented in both schema and description, the agent has no guidance on what these parameters mean or how to use them. This is a severe deficiency.

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

Purpose3/5

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

The description states the verb ('update') and resource ('artifact in the knowledge graph'), which is clear but basic. It distinguishes from deletion tools but doesn't explicitly differentiate from other update_* tools (like update_currency, update_location) that likely operate on different resource types. The purpose is understandable but lacks specificity about what aspects of an artifact can be updated.

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 is provided about when to use this tool versus alternatives. The description doesn't mention prerequisites (e.g., artifact must exist), when to use add_artifact versus update_artifact, or how this differs from other update operations. The agent must infer usage from the tool name alone, which is insufficient for optimal selection.

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

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