Skip to content

feat(mcp): add all_projects flag to mem_search for cross-project search #171

@carlos-mora-sm

Description

@carlos-mora-sm

📋 Pre-flight Checks

  • I have searched existing issues and this is not a duplicate
  • I understand this issue needs status:approved before a PR can be opened

🔍 Problem Description

When working on a project, it's common to need context from a related project — a decision made last week in a different repo, a pattern established in another service, or a known gotcha from a dependency project.

Currently, mem_search always restricts results to the current/default project. There's no way to reach across projects from within the MCP tool.

The CLI already supports this via engram search "query" (without --project), which searches globally. The MCP tool has no equivalent.

Real scenario: while working on project-A, I need to recall an architectural decision logged under project-B. Today this requires either multiple mem_search calls with explicit project values, or falling back to the CLI outside the agent context.

💡 Proposed Solution

Add an optional boolean parameter all_projects to mem_search.

Example usage:

mem_search(query: "auth middleware decision", all_projects: true)

When all_projects: true, the tool skips the default project assignment and passes an empty project to Store.Search(), which already handles global search correctly (no WHERE project = ? clause is added).

When all_projects is false or omitted, behavior is unchanged.

📦 Affected Area

MCP Server (tools, transport)

🔄 Alternatives Considered

Passing project: "" explicitly — doesn't work because the handler replaces empty project with cfg.DefaultProject before calling Store.Search().

📎 Additional Context

Root cause is in internal/mcp/mcp.go, handleSearch() (~line 634):

if project == "" {
    project = cfg.DefaultProject  // always overwrites empty project
}

The CLI (cmd/engram/main.go, cmdSearch) doesn't apply this default, so opts.Project stays "" and Store.Search() performs a global query.

The store layer already supports global search — Store.Search() only adds WHERE o.project = ? when opts.Project != "" (internal/store/store.go, ~line 1536).

The fix is minimal:

if project == "" && !allProjects {
    project = cfg.DefaultProject
}

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