Skip to main content

Local MCP server for semantic code search

Project description

semantic-code-mcp

Local MCP server that provides semantic code search for Claude Code. Instead of iterative grep/glob, it indexes your codebase with embeddings and returns ranked results by meaning.

Python only for now — multi-language support (JS/TS, Rust, Go) is planned.

How It Works

Claude Code ──(MCP/STDIO)──▶ semantic-code-mcp server
                                    │
                    ┌───────────────┼───────────────┐
                    ▼               ▼               ▼
              AST Chunker      Embedder        LanceDB
             (tree-sitter)  (sentence-trans)  (vectors)
  1. Chunking — tree-sitter parses Python into functions, classes, and methods
  2. Embedding — sentence-transformers encodes each chunk (all-MiniLM-L6-v2, 384d)
  3. Storage — vectors stored in LanceDB (embedded, like SQLite)
  4. Search — hybrid semantic + keyword search with recency boosting

Indexing is incremental (mtime-based) and uses git ls-files for fast file discovery. The embedding model loads lazily on first query.

Installation

macOS / Windows

PyPI ships CPU-only torch on these platforms, so no extra flags are needed (~1.7GB install).

uvx semantic-code-mcp

Claude Code integration:

claude mcp add --scope user semantic-code -- uvx semantic-code-mcp

Linux

[!IMPORTANT] Without the --index flag, PyPI installs CUDA-bundled torch (~3.5GB). Unless you need GPU acceleration (you don't — embeddings run on CPU), use the command below to get the CPU-only build (~1.7GB).

uvx --index pytorch-cpu=https://download.pytorch.org/whl/cpu semantic-code-mcp

Claude Code integration:

claude mcp add --scope user semantic-code -- \
  uvx --index pytorch-cpu=https://download.pytorch.org/whl/cpu semantic-code-mcp
Claude Desktop / other MCP clients (JSON config)
{
  "mcpServers": {
    "semantic-code": {
      "command": "uvx",
      "args": ["--index", "pytorch-cpu=https://download.pytorch.org/whl/cpu", "semantic-code-mcp"]
    }
  }
}

On macOS/Windows you can omit the --index and pytorch-cpu args.

MCP Tools

search_code

Search code by meaning, not just text matching. Auto-indexes on first search.

Parameter Type Default Description
query str required Natural language description of what you're looking for
project_path str required Absolute path to the project root
limit int 10 Maximum number of results

Returns ranked results with file_path, line_start, line_end, name, chunk_type, content, and score.

index_codebase

Index a codebase for semantic search. Only processes new and changed files unless force=True.

Parameter Type Default Description
project_path str required Absolute path to the project root
force bool False Re-index all files regardless of changes

index_status

Check indexing status for a project.

Parameter Type Default Description
project_path str required Absolute path to the project root

Returns is_indexed, files_count, and chunks_count.

Configuration

All settings are environment variables with the SEMANTIC_CODE_MCP_ prefix (via pydantic-settings):

Variable Default Description
SEMANTIC_CODE_MCP_CACHE_DIR ~/.cache/semantic-code-mcp Where indexes are stored
SEMANTIC_CODE_MCP_LOCAL_INDEX false Store index in .semantic-code/ within each project
SEMANTIC_CODE_MCP_EMBEDDING_MODEL all-MiniLM-L6-v2 Sentence-transformers model
SEMANTIC_CODE_MCP_DEBUG false Enable debug logging
SEMANTIC_CODE_MCP_PROFILE false Enable pyinstrument profiling

Tech Stack

Component Choice Rationale
MCP Framework FastMCP Python decorators, STDIO transport
Embeddings sentence-transformers Local, no API costs, good quality
Vector Store LanceDB Embedded (like SQLite), no server needed
Chunking tree-sitter AST-based, respects code structure

Development

uv sync                            # Install dependencies
uv run python -m semantic_code_mcp # Run server
uv run pytest                      # Run tests
uv run ruff check src/             # Lint
uv run ruff format src/            # Format

Architecture decisions are documented in docs/decisions/. Project planning lives in TODO.md.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

semantic_code_mcp-0.1.1.tar.gz (113.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

semantic_code_mcp-0.1.1-py3-none-any.whl (30.4 kB view details)

Uploaded Python 3

File details

Details for the file semantic_code_mcp-0.1.1.tar.gz.

File metadata

  • Download URL: semantic_code_mcp-0.1.1.tar.gz
  • Upload date:
  • Size: 113.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.28 {"installer":{"name":"uv","version":"0.9.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for semantic_code_mcp-0.1.1.tar.gz
Algorithm Hash digest
SHA256 863bb254c8c19ded07d8a497423238ffa993b3811bb247b93938c0a1fcdf9380
MD5 0c5e6e6e1813fc0f58943c199b3b6cdc
BLAKE2b-256 c8e62d28d7f9b9d0ad4f2dc229ea3877d7cdc78a17290ead9d1e63ceeda6d8d8

See more details on using hashes here.

File details

Details for the file semantic_code_mcp-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: semantic_code_mcp-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 30.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.28 {"installer":{"name":"uv","version":"0.9.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for semantic_code_mcp-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8eb62117db49a55c7131893e0a040e88737e3b82e319d3853780ef8768bc1a86
MD5 840df479c35f401d0fa6984289e92473
BLAKE2b-256 bf7a09b2e253f3f43b8644902b69d9a52c05f0750aae714641df1fe2be1285dc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page