Skip to content

mcp: Cursor startup can select unsafe root project #80

@justrach

Description

@justrach

Problem

When Cursor enables the codedb MCP server, the active/default project can resolve to / (or other denied roots) instead of the workspace path. This causes confusing behavior in project-scoped MCP calls and can retain stale denied roots in local project cache listings.

Failing Test

test "issue-78: mcp sanitizeProjectsCache removes denied cached roots" {
    var tmp = testing.tmpDir(.{});
    defer tmp.cleanup();

    var projects_buf: [std.fs.max_path_bytes]u8 = undefined;
    const projects_dir = try tmp.dir.realpath(".", &projects_buf);

    try tmp.dir.makePath("badroot");
    try tmp.dir.makePath("good");

    {
        const file = try tmp.dir.createFile("badroot/project.txt", .{});
        defer file.close();
        try file.writeAll("/\n");
    }
    {
        const file = try tmp.dir.createFile("good/project.txt", .{});
        defer file.close();
        try file.writeAll("/Users/example/workspace\n");
    }

    const removed = try mcp_mod.sanitizeProjectsCache(testing.allocator, projects_dir);
    try testing.expectEqual(@as(u32, 1), removed);

    try testing.expectError(error.FileNotFound, tmp.dir.access("badroot/project.txt", .{}));
    try tmp.dir.access("good/project.txt", .{});
}

Expected

Denied roots (like /, /tmp, /private/tmp, /var/tmp) are never selected as active/default projects and are removed from cached local project entries.

Fix

Apply root policy validation in MCP project resolution and proactively sanitize cached project entries before listing/using them.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpriority:p2Medium priority

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions