Skip to main content
Glama

mcp-code

MCP server chạy trên máy của bạn, cho phép Claude đọc và tìm kiếm code trong một thư mục được chỉ định. Server chỉ có quyền đọc, không ghi file và không chạy lệnh.

Tính năng

Tool

Mô tả

list_dir

Liệt kê file và thư mục

read_file

Đọc nội dung một file text

search_code

Tìm chuỗi trong code, trả về file:dòng: nội dung

Các thư mục .git, node_modules, __pycache__, .venv bị bỏ qua. Các file .env, id_rsa, id_ed25519 bị chặn không cho đọc.

Related MCP server: claude-projects-mcp-server

Yêu cầu

Cài đặt

git clone https://github.com/itgiup/mcp-code.git
cd mcp-code
uv sync

Dự án dùng mcp bản 1.x (mcp[cli]<2). Bản 2.x đã đổi API (FastMCP thành MCPServer) nên chưa tương thích.

Chạy thử

MCP_CODE_ROOT=/path/to/your/project uv run mcp-code

Server dùng giao thức stdio nên sẽ đứng im chờ input, không in gì ra. Đó là bình thường, nhấn Ctrl+C để thoát. Nếu có traceback thì là lỗi cài đặt.

Muốn thử các tool qua giao diện web:

uv run mcp dev src/mcp_code/__init__.py

Cấu hình Claude Desktop

Mở file cấu hình claude_desktop_config.json (trong Claude Desktop: Settings → Developer → Edit Config) và thêm:

{
  "mcpServers": {
    "mcp-code": {
      "command": "/path/to/uv",
      "args": [
        "--directory",
        "/path/to/mcp-code",
        "run",
        "mcp-code"
      ],
      "env": {
        "MCP_CODE_ROOT": "/path/to/your/project"
      }
    }
  }
}

Thay các đường dẫn cho đúng máy của bạn:

  • command: đường dẫn tuyệt đối tới uv, lấy bằng which uv.

  • --directory: thư mục chứa project mcp-code này. Bắt buộc, vì Claude Desktop không chạy lệnh trong thư mục project.

  • MCP_CODE_ROOT: thư mục Claude được phép đọc. Nếu bỏ trống, server dùng thư mục làm việc hiện tại của tiến trình, thường không phải thứ bạn muốn.

Nếu file đã có sẵn nội dung khác, chỉ thêm khối mcpServers và nhớ dấu phẩy để JSON hợp lệ. Sau đó thoát hẳn Claude Desktop rồi mở lại.

Kiểm tra bằng cách mở chat mới và hỏi, ví dụ: "Liệt kê file trong thư mục gốc rồi đọc README.md".

Bảo mật

  • Server chỉ đọc được bên trong MCP_CODE_ROOT. Mọi đường dẫn thoát ra ngoài (ví dụ ../) đều bị từ chối.

  • Hãy trỏ MCP_CODE_ROOT vào một dự án cụ thể, không trỏ vào cả thư mục home.

  • Nội dung các file Claude đọc sẽ được gửi tới Claude, nên đừng trỏ vào thư mục chứa bí mật.

  • Muốn chặn thêm file nhạy cảm, thêm tên file vào tập BLOCKED trong src/mcp_code/__init__.py.

Xử lý lỗi

Hiện tượng

Cách xử lý

Failed to spawn process: No such file or directory

Sai đường dẫn command. Dùng đường dẫn tuyệt đối từ which uv

No module named 'mcp.server.fastmcp'

Đang dùng mcp 2.x. Chạy uv add "mcp[cli]<2"

Server thoát ngay sau khi khởi động

Chạy tay uv run mcp-code để xem lỗi. Log của Claude Desktop nằm ở file mcp-server-mcp-code.log

Có tool nhưng không đọc được file

Kiểm tra MCP_CODE_ROOT có đúng và có quyền đọc không

Khi viết thêm code, không dùng print() ra stdout vì stdout dành cho giao thức MCP. Dùng print(..., file=sys.stderr) để debug.

Giấy phép

MIT

Available Tools

4 tools
list_dirC

Liệt kê file/thư mục.

Inputs: path. Returns: result

read_fileC

Đọc nội dung một file text.

Inputs: path (required), max_bytes. Returns: result

search_codeC

Tìm chuỗi trong code, trả về 'file:dòng: nội dung'.

Inputs: query (required), path, max_results. Returns: result

write_fileA

Tạo file text mới (tự tạo thư mục cha). Ghi đè file có sẵn chỉ khi overwrite=True.

Inputs: path (required), content (required), overwrite. Returns: result

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    B3.1/5.0

    Scored across 4 tools

    Disambiguation5/5

    Each tool maps to a distinct filesystem action: listing directories, reading a file, searching code, and writing a file. There is no plausible overlap between them, and the descriptions reinforce the boundaries (e.g. search_code returns file:line:content while read_file returns full contents).

    Naming Consistency5/5

    All four names follow a clean verb_noun snake_case pattern (list_dir, read_file, search_code, write_file). The verb choice is consistent and predictable, and there is no mixing of conventions.

    Tool Count4/5

    Four tools is on the lean side but every one earns its place for a code/filesystem agent. It is slightly under-scoped for the domain, since a typical code workflow also needs an edit/patch or delete operation, but nothing is redundant.

    Completeness4/5

    Read, list, search, and create/overwrite cover the core lifecycle for a text-file code server. Gaps exist for delete, rename/move, and surgical in-place edits (only full overwrite is available), but agents can work around these.

    Related MCP Connectors

    Related MCP Servers