Skip to main content
Glama

create_relations

Define and establish relationships between entities in a knowledge graph. Specify source, target, and relation type to actively build structured connections for enhanced reasoning and problem-solving.

Instructions

Create multiple new relations between entities in the knowledge graph. Relations should be in active voice

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
relationsYesArray of relations to create

Implementation Reference

  • The core execute function for the 'create_relations' tool. It processes an array of relations, attempts to add each to the graph using graph.addRelation, checks for existence of source/target entities or duplicate relations for failures, collects results, saves the memory store, and returns a JSON string with created/failed counts and details.
    execute: async (args) => { const results = { created: [] as Array<{from: string, to: string, relationType: string}>, failed: [] as Array<{from: string, to: string, relationType: string, reason: string}> }; // Using the lower-level graph for relations for now // In a future update, we can add relation handling to the MemoryStore itself for (const relation of args.relations) { const success = graph.addRelation(relation); if (success) { results.created.push(relation); } else { // Determine failure reason let reason = "Unknown error"; if (!graph.entities.has(relation.from)) { reason = `Source entity '${relation.from}' doesn't exist`; } else if (!graph.entities.has(relation.to)) { reason = `Target entity '${relation.to}' doesn't exist`; } else { reason = "Relation already exists"; } results.failed.push({...relation, reason}); } } // Save changes await memoryStore.save(); // Return as string return JSON.stringify({ created: results.created.length > 0 ? results.created : null, failed: results.failed.length > 0 ? results.failed : null, message: `Created ${results.created.length} new relations. ${results.failed.length} relations failed.` }); }
  • Zod schema defining the input parameters for the create_relations tool: an array of relations.
    export const CreateRelationsSchema = z.object({ relations: z.array(RelationSchema).describe('Array of relations to create') });
  • Registers the 'create_relations' tool on the FastMCP server with name, description, schema, and inline execute handler.
    server.addTool({ name: 'create_relations', description: 'Create multiple new relations between entities in the knowledge graph. Relations should be in active voice', parameters: Schemas.CreateRelationsSchema, execute: async (args) => { const results = { created: [] as Array<{from: string, to: string, relationType: string}>, failed: [] as Array<{from: string, to: string, relationType: string, reason: string}> }; // Using the lower-level graph for relations for now // In a future update, we can add relation handling to the MemoryStore itself for (const relation of args.relations) { const success = graph.addRelation(relation); if (success) { results.created.push(relation); } else { // Determine failure reason let reason = "Unknown error"; if (!graph.entities.has(relation.from)) { reason = `Source entity '${relation.from}' doesn't exist`; } else if (!graph.entities.has(relation.to)) { reason = `Target entity '${relation.to}' doesn't exist`; } else { reason = "Relation already exists"; } results.failed.push({...relation, reason}); } } // Save changes await memoryStore.save(); // Return as string return JSON.stringify({ created: results.created.length > 0 ? results.created : null, failed: results.failed.length > 0 ? results.failed : null, message: `Created ${results.created.length} new relations. ${results.failed.length} relations failed.` }); } });
  • Invokes registerMemoryTools(server) as part of registering all tools, which includes the create_relations tool.
    console.error('[INFO] [tools] Registering memory tools...'); registerMemoryTools(server);
  • Zod schema for individual relation objects used in CreateRelationsSchema.
    const RelationSchema = z.object({ from: z.string().min(1).describe('Source entity name'), to: z.string().min(1).describe('Target entity name'), relationType: z.string().min(1).describe('Type of relationship (in active voice)') });

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/flight505/mcp-think-tank'

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