Skip to main content
Glama
create-relations.js3.39 kB
// src/tools/graph/create-relations.ts // Outil: create_relations - Créer de nouvelles relations entre entités import { knowledgeGraphManager } from "../../knowledge-graph/manager.js"; /** * Définition de l'outil create_relations */ export const createRelationsTool = { name: "create_relations", description: "Create multiple new relations between entities in the knowledge graph. Relations should be in active voice", inputSchema: { type: "object", properties: { relations: { type: "array", items: { type: "object", properties: { from: { type: "string", description: "The name of the entity where the relation starts" }, to: { type: "string", description: "The name of the entity where the relation ends" }, relationType: { type: "string", description: "The type of the relation" }, }, required: ["from", "to", "relationType"], }, }, }, required: ["relations"], }, }; /** * Handler pour l'outil create_relations */ export const createRelationsHandler = async (args) => { if (!args.relations || !Array.isArray(args.relations)) { throw new Error("The 'relations' parameter is required and must be an array"); } // Valider chaque relation for (const relation of args.relations) { if (!relation.from || typeof relation.from !== 'string') { throw new Error("Each relation must have a 'from' string property"); } if (!relation.to || typeof relation.to !== 'string') { throw new Error("Each relation must have a 'to' string property"); } if (!relation.relationType || typeof relation.relationType !== 'string') { throw new Error("Each relation must have a 'relationType' string property"); } } try { const result = await knowledgeGraphManager.createRelations(args.relations); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] }; } catch (error) { console.error("Error in create_relations tool:", error); throw error; } }; /** * Fonction utilitaire pour créer une relation simple */ export async function createRelation(from, to, relationType) { return createRelationsHandler({ relations: [{ from, to, relationType }] }); } /** * Test de l'outil (pour usage en développement) */ export async function testCreateRelations() { console.log("Testing create_relations tool..."); const testRelations = [ { from: "Entity A", to: "Entity B", relationType: "CONNECTS_TO" } ]; try { const result = await createRelationsHandler({ relations: testRelations }); console.log("Test passed:", result); return result; } catch (error) { console.error("Test failed:", error); throw error; } }

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