create_connection
Establish relationships between stored memories in a Neo4j graph database, enabling AI agents to connect information with semantic links and metadata for structured knowledge representation.
Instructions
Create a connection between two memories (its good to have connected memories)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| fromMemoryId | Yes | ID of the source memory | |
| toMemoryId | Yes | ID of the target memory | |
| type | Yes | Relationship type such as KNOWS, WORKS_ON, LIVES_IN, HAS_SKILL, PARTICIPATES_IN | |
| properties | No | Optional relationship metadata (e.g. {since: "2023-01", role: "Manager", status: "active"}) |
Implementation Reference
- src/handlers/index.ts:213-233 (handler)MCP tool handler for 'create_connection': validates input arguments using isCreateConnectionArgs and invokes Neo4jClient.createRelationship to establish the connection, returning the result as JSON.case 'create_connection': { if (!isCreateConnectionArgs(args)) { throw new McpError(ErrorCode.InvalidParams, 'Invalid create_connection arguments'); } const result = await neo4j.createRelationship( args.fromMemoryId, args.toMemoryId, args.type, args.properties || { created_at: new Date().toISOString() } ); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2), }, ], }; }
- src/tools/definitions.ts:64-90 (schema)JSON schema definition for the create_connection tool, including input parameters and descriptions, exported as part of the tools array.{ name: 'create_connection', description: 'Create a connection between two memories (its good to have connected memories)', inputSchema: { type: 'object', properties: { fromMemoryId: { type: 'number', description: 'ID of the source memory', }, toMemoryId: { type: 'number', description: 'ID of the target memory', }, type: { type: 'string', description: 'Relationship type such as KNOWS, WORKS_ON, LIVES_IN, HAS_SKILL, PARTICIPATES_IN', }, properties: { type: 'object', description: 'Optional relationship metadata (e.g. {since: "2023-01", role: "Manager", status: "active"})', additionalProperties: true, }, }, required: ['fromMemoryId', 'toMemoryId', 'type'], }, },
- src/neo4j-client.ts:73-86 (helper)Neo4jClient method that executes the Cypher query to create a directed relationship between two nodes by their IDs.async createRelationship(fromNodeId: number, toNodeId: number, relationType: string, properties: Neo4jQueryParams = {}): Promise<any> { const result = await this.executeQuery( `MATCH (a), (b) WHERE id(a) = $fromId AND id(b) = $toId CREATE (a)-[r:${relationType} $props]->(b) RETURN r as relationship`, { fromId: neo4j.int(fromNodeId), toId: neo4j.int(toNodeId), props: properties, } ); return result[0]; }
- src/server.ts:37-59 (registration)Registers the tools (including create_connection schema) for listTools requests and sets up the callTool handler that dispatches to handleToolCall based on tool name.private setupToolHandlers(): void { // Tool list handler this.server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools, })); // Tool execution handler this.server.setRequestHandler(CallToolRequestSchema, async (request) => { if (!this.neo4j) { return { content: [ { type: 'text', text: 'Neo4j connection not configured. Please set NEO4J_URI, NEO4J_USERNAME, and NEO4J_PASSWORD environment variables.', }, ], isError: true, }; } const { name, arguments: args } = request.params; return handleToolCall(name, args, this.neo4j); }); }
- src/types.ts:22-27 (schema)TypeScript interface defining the input arguments for create_connection, used for validation.export interface CreateConnectionArgs { fromMemoryId: number; toMemoryId: number; type: string; properties?: Record<string, any>; }