Skip to main content
Glama
knowall-ai

Neo4j Agent Memory MCP Server

by knowall-ai

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
NameRequiredDescriptionDefault
fromMemoryIdYesID of the source memory
toMemoryIdYesID of the target memory
typeYesRelationship type such as KNOWS, WORKS_ON, LIVES_IN, HAS_SKILL, PARTICIPATES_IN
propertiesNoOptional relationship metadata (e.g. {since: "2023-01", role: "Manager", status: "active"})

Implementation Reference

  • 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), }, ], }; }
  • 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'], }, },
  • 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); }); }
  • 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>; }

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/knowall-ai/mcp-neo4j-agent-memory'

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