Skip to main content
Glama

create_relations

Establish directed connections between entities, skipping duplicates. Define source, target, and relation type. Enhances entity mapping and organization within a persistent, offline MCP server environment.

Instructions

Create directed relations between entities. Skips existing relations.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
relationsYesArray of relations to create.

Implementation Reference

  • The core handler function `createRelations` that iterates over the input relations array, resolves source and target entity IDs using the repository (creating if necessary), attempts to create each relation via the repository, and returns the list of successfully inserted relations.
    async createRelations(relations) { const created = []; for (const relation of relations) { const fromId = await this.#repository.getOrCreateEntityId(relation.from, 'Unknown'); const toId = await this.#repository.getOrCreateEntityId(relation.to, 'Unknown'); const inserted = await this.#repository.createRelation(fromId, toId, relation.relationType); if (inserted) { created.push(relation); } } return created; }
  • src/server.js:68-88 (registration)
    Registers the MCP tool 'create_relations' with input schema validation using Zod (array of {from, to, relationType} objects) and delegates execution to KnowledgeGraphManager.createRelations, returning JSON-stringified results in MCP content format.
    this.tool( 'create_relations', 'Create directed relations between entities. Skips existing relations.', { relations: z.array(z.object({ from: z.string().describe('Source entity name.'), to: z.string().describe('Target entity name.'), relationType: z.string().describe('Label or type of the relation.') })).describe('Array of relations to create.') }, async ({ relations }) => ({ content: [{ type: 'text', text: JSON.stringify( await this.#knowledgeGraphManager.createRelations(relations), null, 2 ) }] }) );
  • Zod schema defining the input parameters for the 'create_relations' tool: an array of objects each with 'from' (source entity), 'to' (target entity), and 'relationType' (relation label).
    relations: z.array(z.object({ from: z.string().describe('Source entity name.'), to: z.string().describe('Target entity name.'), relationType: z.string().describe('Label or type of the relation.') })).describe('Array of relations to create.') },

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/iAchilles/memento'

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