Skip to main content
Glama

neo4j-query

Execute Cypher queries against Neo4j graph databases to retrieve, create, update, or delete data nodes and relationships using parameterized queries.

Instructions

Execute a Cypher query against the Neo4j database

Input Schema

NameRequiredDescriptionDefault
parametersNoQuery parameters (optional)
queryYesThe Cypher query to execute

Input Schema (JSON Schema)

{ "properties": { "parameters": { "additionalProperties": true, "description": "Query parameters (optional)", "type": "object" }, "query": { "description": "The Cypher query to execute", "type": "string" } }, "required": [ "query" ], "type": "object" }

Implementation Reference

  • The core handler function that executes the Cypher query against the Neo4j database using a driver session and returns the result records.
    async executeQuery(query: string, parameters: Record<string, any> = {}) { const session = this.driver.session(); try { const result = await session.run(query, parameters); return result.records; } finally { await session.close(); } }
  • Input schema definition for the 'neo4j-query' tool, specifying the required 'query' parameter and optional 'parameters' object.
    inputSchema: { type: "object", properties: { query: { type: "string", description: "The Cypher query to execute" }, parameters: { type: "object", description: "Query parameters (optional)", additionalProperties: true } }, required: ["query"] }
  • src/index.ts:97-115 (registration)
    Registration of the 'neo4j-query' tool in the ListTools response, including name, description, and input schema.
    { name: "neo4j-query", description: "Execute a Cypher query against the Neo4j database", inputSchema: { type: "object", properties: { query: { type: "string", description: "The Cypher query to execute" }, parameters: { type: "object", description: "Query parameters (optional)", additionalProperties: true } }, required: ["query"] } }
  • src/index.ts:125-134 (registration)
    Dispatch registration in the CallToolRequest handler switch statement that routes 'neo4j-query' calls to the executeQuery method.
    switch (request.params.name) { case "neo4j-query": response = await this.executeQuery( args.query as string, args.parameters as Record<string, any> ); break; default: throw new McpError(ErrorCode.MethodNotFound, `Unknown tool: ${request.params.name}`); }
  • Helper function to format the Neo4j query results into a readable text string for the tool response.
    function formatResults(records: neo4j.Record[]) { if (!records || records.length === 0) { return "No results found."; } const output: string[] = ["Results:"]; records.forEach((record, index) => { output.push(`\nRecord ${index + 1}:`); record.keys.forEach(key => { const value = record.get(key); output.push(`${String(key)}: ${formatValue(value)}`); }); }); return output.join('\n'); }

Other Tools

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/Tobarrientos2/neo4j-mcpserver'

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