Skip to content

Bug: unified_search fails with "Variable 'd' not defined" error for Project and Task nodes #28

@tyfta

Description

@tyfta

🐛 Bug Report

Problem Description

The unified_search function fails with a Cypher query error when searching for Project and Task nodes:

Variable d not defined (line 11, column 44 (offset: 275))
" WHEN 'Knowledge' THEN (CASE WHEN d IS NOT NULL THEN d.name ELSE null END)"

Root Cause

In src/services/neo4j/searchService/unifiedSearchLogic.ts:

  1. Variable scope issue in returnClause (lines 181-183):

    • Variable d is used for all node types in the CASE statement
    • But d is only defined in optionalMatches for Knowledge nodes
    • This causes Cypher query errors for Project and Task searches
  2. Missing variable definitions in baseWithVariables (lines 235-240):

    • Variables p, k_proj, d are not properly added to baseWithVariables
    • This can cause issues with variable availability in Cypher queries

Impact

  • Function unified_search returns 0 results for all searches
  • Critical functionality broken for project and task management
  • Affects all MCP clients using Atlas

Expected Behavior

  • unified_search should work for all node types (Project, Task, Knowledge)
  • No Cypher query errors
  • Proper search results returned

Steps to Reproduce

  1. Start Atlas MCP server
  2. Try unified_search with any value
  3. Observe error in logs and 0 results returned

Proposed Solution

Fix the variable scope issues in the Cypher query:

  1. Fix returnClause:
CASE $label
  WHEN '${NodeLabels.Knowledge}' THEN (CASE WHEN d IS NOT NULL THEN d.name ELSE null END)
  WHEN '${NodeLabels.Project}' THEN n.taskType
  WHEN '${NodeLabels.Task}' THEN n.taskType
  ELSE n.taskType 
END AS entityType,
  1. Fix baseWithVariables:
let baseWithVariables = ["n"];
if (actualLabel === NodeLabels.Task && assignedToUserIdFilter) {
  baseWithVariables.push("assignee");
}
if (actualLabel === NodeLabels.Task) {
  baseWithVariables.push("p");
}
if (actualLabel === NodeLabels.Knowledge) {
  baseWithVariables.push("k_proj", "d");
}
baseWithVariables = [...new Set(baseWithVariables)];

Environment

  • Atlas MCP Server version: 2.8.15
  • Neo4j version: 5.x
  • Node.js version: 18+

Labels

  • bug
  • high-priority
  • unified-search
  • neo4j

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions