Skip to content

MCP Server: Auto-expand subgroup queries when no group_ids specified #1136

@LongSunnyDay

Description

@LongSunnyDay

Problem

When using hierarchical group_ids like evadenta:business, evadenta:procedures, etc., the MCP server's search functions (search_nodes, search_memory_facts, get_episodes) return no results when called without explicit group_ids.

Current Behavior

# Config: --group-id evadenta
# Data stored in: evadenta:business, evadenta:procedures, evadenta:architecture

search_nodes(query="deployment")  # Returns: No relevant nodes found

The enforce_group_scope() function returns ["evadenta"] when no group_ids are provided, but the search performs an exact match, missing all evadenta:* subgroups.

Expected Behavior

search_nodes(query="deployment")  # Returns: nodes from evadenta:business, evadenta:procedures, etc.

Proposed Solution

Add a helper function that queries the database for all group_ids matching the configured prefix:

async def get_matching_group_ids(prefix: str) -> list[str]:
    """Query database for all group_ids that equal prefix OR start with prefix:"""
    # Query: WHERE n.group_id = $prefix OR n.group_id STARTS WITH $prefix_colon
    # Returns: ["evadenta:business", "evadenta:procedures", "evadenta:architecture", ...]

Then modify search_nodes, search_memory_facts, and get_episodes to use this when no group_ids are explicitly provided.

Use Case

Multi-category knowledge storage where data is organized into subgroups:

  • project:architecture - design decisions
  • project:procedures - deployment/dev workflows
  • project:debugging - troubleshooting lessons
  • project:business - domain rules

Users expect default queries to search across all their subgroups, not require explicit enumeration.

Implementation

I have a working implementation (~50 lines) that:

  1. Adds get_matching_group_ids() async function
  2. Modifies the three search functions to auto-expand subgroups
  3. Maintains backward compatibility (only affects queries with no explicit group_ids)
  4. Preserves existing scope enforcement for security

Happy to submit a PR if this approach aligns with the project's direction.

Environment

  • graphiti-core version: latest
  • MCP server transport: stdio
  • Database: Neo4j

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions