Skip to content

Single MCP server instance should work across multiple projects #63

@PatrickSys

Description

@PatrickSys

The problem

The server resolves one project root at startup (CODEBASE_ROOT env var to the cwd) and then every tool call runs against that root for the rest of the process lifetime.

If you work on more than one project, you need a separate MCP server entry per project in your config, each with a hardcoded path. It works, but it's annoying to maintain and doesn't scale.

It gets worse in editors like Codex Desktop where cwd doesn't reliably point to the project root . @aolin480 ran into this and explored walk-up detection (looking for .codebase-context/, .git, nx.json etc. as markers), but it touched too much of the internals to land cleanly. See the discussion in #2.

What needs to change

The root path can't be a process-level singleton. ROOT_PATH is resolved once in resolveRootPath() and baked into PATHS and indexState - these need to become per-project instead of global.

Whatever the approach ends up being (per-tool parameter, walk-up detection, or something else), the main thing to get right is the caching layer: loading and managing indexes for multiple roots without re-parsing everything on every call, and without leaking memory if someone points it at 20 different repos over a long session.

Credit to @aolin480 for surfacing this in #2.

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