Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 14, 2025

MCP search tools defaulted to "thedotmack" (plugin directory name) instead of the user's active project when project parameter was omitted. Root cause: process.cwd() in the MCP server context points to ~/.claude/plugins/marketplaces/thedotmack/, not the user's working directory.

Changes

SessionStore (src/services/sqlite/SessionStore.ts)

  • Added getMostRecentProject(): queries most recently active project from sdk_sessions table
  • Uses existing idx_sdk_sessions_started index for efficient lookup

SearchManager (src/services/worker/SearchManager.ts)

  • Changed fallback chain in getRecentContext():
    // Before
    const project = args.project || basename(process.cwd());
    
    // After
    const project = args.project || this.sessionStore.getMostRecentProject() || basename(process.cwd());

Documentation

  • Added CHANGELOG entry
  • Updated search-tools.mdx to document automatic project detection

Behavior

Before: Tools without explicit project parameter returned "No previous sessions found for project 'thedotmack'"

After: Tools intelligently default to most recently active project in database

Original prompt

This section details on the original issue you should resolve

<issue_title>[BUG] MCP search tools default to wrong project name (plugin directory instead of user project)</issue_title>
<issue_description>## Bug Description

When using claude-mem MCP search tools (e.g., search, get_recent_context, decisions) without explicitly passing the project parameter, the tools default to the project name "thedotmack" instead of the user's actual project directory.

Expected Behavior

MCP search tools should default to the user's current working directory project name (e.g., T9_Oracle_v8 when running Claude Code from /path/to/T9_Oracle_v8).

Actual Behavior

The tools return:

No previous sessions found for project "thedotmack".

Even when running Claude Code from a completely different project directory.

Root Cause

The issue is in src/shared/paths.ts in the getCurrentProjectName() function:

export function getCurrentProjectName(): string {
  try {
    const gitRoot = execSync('git rev-parse --show-toplevel', {
      cwd: process.cwd(),  // ← BUG: This is the MCP server's cwd, not user's project
      encoding: 'utf8',
      stdio: ['pipe', 'pipe', 'ignore'],
      windowsHide: true
    }).trim();
    return basename(gitRoot);
  } catch {
    return basename(process.cwd());
  }
}

When the MCP server runs, process.cwd() is the plugin installation directory (~/.claude/plugins/marketplaces/thedotmack/), which is itself a git repository. So git rev-parse --show-toplevel returns that directory, and basename() returns "thedotmack".

Verification

# From plugin directory:
cd ~/.claude/plugins/marketplaces/thedotmack && git rev-parse --show-toplevel | xargs basename
# Output: thedotmack

Environment

  • claude-mem version: 7.1.14
  • OS: Fedora Linux 43 (also likely affects all platforms)
  • Claude Code version: Latest
  • Worker status: Running and healthy (port 37777)
  • Database: Exists at ~/.claude-mem/claude-mem.db

Workaround

Explicitly pass the project parameter to all MCP search calls:

mcp__plugin_claude-mem_claude-mem-search__search(
    query="your search",
    project="YourProjectName"  # Must be explicit
)

Suggested Fix

The MCP server needs to receive the Claude Code session's working directory context. Possible approaches:

  1. Pass cwd via MCP protocol: If Claude Code can pass the session's cwd to MCP servers, use that instead of process.cwd()
  2. Environment variable: Set an env var like CLAUDE_CODE_CWD that the MCP server can read
  3. Hooks approach: The hooks already have correct cwd access - perhaps cache the project name from hook calls and use it as fallback in MCP tools

Additional Context

  • The hooks (context-hook.ts, new-hook.ts, user-message-hook.ts) correctly use path.basename(cwd) where cwd comes from the Claude Code context
  • Only the MCP server-side tools are affected because they run in a separate process</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Fix MCP search tools default project name Fix MCP search tools defaulting to plugin directory instead of user project Dec 14, 2025
Copilot AI requested a review from thedotmack December 14, 2025 19:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] MCP search tools default to wrong project name (plugin directory instead of user project)

2 participants