create_connection
Establish relationships between stored memories in a Neo4j graph database to create semantic connections with customizable types and metadata for AI agent knowledge organization.
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)The main handler logic for the 'create_connection' tool. Validates input arguments using isCreateConnectionArgs and executes neo4j.createRelationship to create a relationship between two memories.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 (registration)Registration of the 'create_connection' tool in the tools array, including name, description, and input schema definition.{ 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/types.ts:22-75 (schema)TypeScript interface and validation function for CreateConnectionArgs used in the handler for input validation.export interface CreateConnectionArgs { fromMemoryId: number; toMemoryId: number; type: string; properties?: Record<string, any>; } export interface UpdateMemoryArgs { nodeId: number; properties: Record<string, any>; } export interface UpdateConnectionArgs { fromMemoryId: number; toMemoryId: number; type: string; properties: Record<string, any>; } export interface DeleteMemoryArgs { nodeId: number; } export interface DeleteConnectionArgs { fromMemoryId: number; toMemoryId: number; type: string; } export interface ListMemoryLabelsArgs { // No arguments needed for this tool } export function isCreateMemoryArgs(args: unknown): args is CreateMemoryArgs { return typeof args === 'object' && args !== null && typeof (args as CreateMemoryArgs).label === 'string' && typeof (args as CreateMemoryArgs).properties === 'object'; } export function isSearchMemoriesArgs(args: unknown): args is SearchMemoriesArgs { if (typeof args !== 'object' || args === null) return false; const searchArgs = args as SearchMemoriesArgs; if (searchArgs.query !== undefined && typeof searchArgs.query !== 'string') return false; if (searchArgs.since_date !== undefined && typeof searchArgs.since_date !== 'string') return false; return true; } export function isCreateConnectionArgs(args: unknown): args is CreateConnectionArgs { return ( typeof args === 'object' && args !== null && typeof (args as CreateConnectionArgs).fromMemoryId === 'number' && typeof (args as CreateConnectionArgs).toMemoryId === 'number' && typeof (args as CreateConnectionArgs).type === 'string' ); }