dir2mcp

module
v0.11.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 18, 2026 License: MIT

README

dir2mcp logo

CI golangci-lint Go Reference

dir2mcp

Point it at a folder. Ask questions about what is inside, and get answers that cite the exact file and lines, or the exact seconds of a recording.

dir2mcp indexes a directory (code, Markdown, PDFs and office documents, audio and video) and serves it over MCP, the protocol Claude, Cursor and other AI clients use to reach tools and data. It is one Go binary with its state in .dir2mcp/ next to your files. It runs fully local if you want: embeddings and answers can come from Ollama or any OpenAI-compatible server, and dir2mcp doctor verifies that nothing leaves the machine.

This is a real run against an Ollama server (nomic-embed-text and qwen2.5:7b-instruct-q4_K_M), with no cloud account. make demo records it again from assets/demo/demo.tape.

Try it in two minutes

brew tap dirstral/tap
brew install dirstral/tap/dir2mcp   # the full name trusts only this formula
cd ~/notes                      # any folder you want to ask about

On Windows, get the zip from Releases instead; see Windows for what works there and what does not.

Fully local, no account (with Ollama):

ollama pull nomic-embed-text && ollama pull qwen2.5:7b
dir2mcp up        # the first run asks how to run the models: pick "Locally with Ollama"

The setup finds Ollama, lists its models and writes .dir2mcp.yaml. To script it (no terminal), write the same file yourself:

cat > .dir2mcp.yaml <<'EOF'
providers:
  local:
    kind: openai
    base_url: http://127.0.0.1:11434/v1
    embed_text_model: nomic-embed-text
    embed_code_model: nomic-embed-text
    chat_model: qwen2.5:7b
model:
  embed: {provider: local}
  chat: {provider: local}
EOF
dir2mcp up

Or with one cloud key (Mistral is the default; OpenAI and Gemini work too):

export MISTRAL_API_KEY=...
dir2mcp up

Then ask from the terminal, or hand the folder to Claude Code, Cursor or Claude Desktop:

$ dir2mcp ask "When is the budget meeting?"
The quarterly budget meeting is on Thursday. [notes.md:L1-L3]

  Citations
  [1] notes.md  chunk=2 span=L1-L3

$ dir2mcp install claude-code   # Claude Code: start a new session, then ask about the folder
$ dir2mcp install cursor        # Cursor: the server shows in Settings > MCP
$ dir2mcp install claude        # Claude Desktop: restart it, then ask about the folder

dir2mcp status shows what was indexed, and names every file it skipped with the reason. dir2mcp down stops the server; up resumes incrementally.

What makes it different

  • Answers cite spans, not files. A citation names a line range for text and code, a page for PDFs, and a time range for audio and video. open_file returns exactly the cited span.

  • Coverage is honest. A file it could not read, a passage in a language the speech model does not cover, or a window of broken transcription is recorded with its reason. dir2mcp status and dir2mcp doctor name it; nothing is dropped silently.

  • Any provider, one capability at a time. Embedding, extraction, speech, answers and reranking bind independently, so you can mix providers:

    Capability Providers
    Embedding Mistral, OpenAI, Gemini, any OpenAI-compatible endpoint, self-hosted
    Extraction / OCR docling (local), docling-serve (HTTP), pandoc, Mistral OCR
    Transcription Voxtral, Whisper (self-hosted or OpenAI-compatible)
    Answers Mistral, OpenAI, Anthropic, Gemini, OpenRouter, any OpenAI-compatible endpoint
    Reranking Cohere, ColBERT, self-hosted

    A provider turns on when its credential is present. There is no separate enable flag.

  • Fully local if you want. docling for extraction, and Ollama, vLLM, llama.cpp, LM Studio or TEI for embeddings and answers. dir2mcp doctor reports whether any configured provider is a third-party host.

  • Media and video. Transcripts and recognized on-screen events become time-anchored, filterable annotations, so an answer can cite a moment and a client can play exactly that moment.

Connect a client

Run these in the folder that dir2mcp up serves:

Client Command Then
Claude Code dir2mcp install claude-code Start a new session
Cursor dir2mcp install cursor The server shows in Settings > MCP
Claude Desktop dir2mcp install claude Restart Claude Desktop

Each install replaces only its own entry and keeps your other servers. dir2mcp doctor <client> checks the entry, and dir2mcp uninstall <client> removes it. Details: connect an MCP client.

Install

Platform How
macOS, Linux (Homebrew) brew tap dirstral/tap && brew install dirstral/tap/dir2mcp
With bundled docling brew install dirstral/tap/dir2mcp-full (about 6.3 GB)
Docker docker run --rm -p 127.0.0.1:8080:8080 -v "$PWD:/corpus:ro" -v dir2mcp-state:/state ghcr.io/dirstral/dir2mcp
Nix nix run github:dirstral/dir2mcp -- version
Windows zip from Releases; read the Windows limits
From source git clone --recurse-submodules https://github.com/dirstral/dir2mcp && cd dir2mcp && make build (Go 1.26.9+)

docs/install.md has the lean and full tracks, the Nix service modules and the Windows details.

MCP tools

Tool What it does
dir2mcp_search Semantic search over the indexed content
dir2mcp_ask Answer a question, with citations
dir2mcp_ask_audio Answer with a spoken (TTS) response
dir2mcp_transcribe Transcribe an audio file from the corpus
dir2mcp_annotate Structured annotation of a document
dir2mcp_transcribe_and_ask Transcribe, then answer over the result
dir2mcp_open_file Read a file, or exactly the cited span
dir2mcp_open_media_clip Cut the audio or video clip for a time span
dir2mcp_related Find chunks related to a chunk you already have
dir2mcp_list_files List the indexed files with metadata
dir2mcp_stats Corpus statistics and the engines in use

What a citation carries lists the fields of a time span.

Configure

The first dir2mcp up in a terminal runs a setup wizard and writes .dir2mcp.yaml. dir2mcp config init runs it again, and dir2mcp config print shows the settings in force. Keys go in the environment, in .env.local, or in the OS keychain (dir2mcp config set-secret), never in the YAML file.

docs/configuration.md is the full reference. It includes a fully local, no-egress setup, self-hosted endpoints, document extraction, reranking, and which files are indexed.

Common commands

Command What it does
dir2mcp up / down Start the server and index the folder; stop it
dir2mcp status What was indexed, and every skipped file with its reason
dir2mcp ask "<question>" Ask from the terminal
dir2mcp doctor Check the config, the providers and the egress
dir2mcp reindex Index everything again

All commands: docs/cli.md.

Benchmark

An end-to-end benchmark runs the real binary on a public corpus (120 questions from SQuAD 2.0, CC BY-SA 4.0) with local models only (nomic-embed-text and qwen2.5:7b). On the published run, 75% of the answers contain the gold answer, 98.7% of the inline citations name the correct file, and dir2mcp declines 25% of the questions that the corpus cannot answer. With rag.verify_faithfulness: true it declines 75%, and 67.5% of the answers contain the gold answer. Method, raw results and how to run it again: bench/README.md.

Security

  • The server listens on 127.0.0.1 by default, with a bearer token.
  • --public requires auth unless you also pass --force-insecure.
  • The server does not index its own config or .env files.
  • dir2mcp support-bundle always removes credentials, so you can attach it to a public issue.

docs/security.md has the full defaults. To report a vulnerability, read SECURITY.md.

Documentation

Guides in this repo:

The normative specification lives in the dirstral-spec submodule: SPEC, VISION, ECOSYSTEM, and the compatibility matrix. dirstral-conformance is a black-box conformance suite for any server that claims the spec, and dirstral-cli is a terminal client.

Development

make check        # the full local gate (never rewrites the tree)
make build        # build the dir2mcp binary
make bench-e2e    # run the end-to-end benchmark
make demo         # record assets/demo.gif again

Read CONTRIBUTING.md before you open a pull request. Contributor and agent guides: AGENTS.md, CLAUDE.md.

License

MIT. See LICENSE.

Directories

Path Synopsis
cmd
dir2mcp command
internal
anthropic
Package anthropic provides a direct-HTTP adapter for the Anthropic Messages API (POST {base}/v1/messages).
Package anthropic provides a direct-HTTP adapter for the Anthropic Messages API (POST {base}/v1/messages).
avutil
Package avutil isolates audio/video media handling behind a small surface so the rest of the codebase does not depend on the ffmpeg/ffprobe binaries directly.
Package avutil isolates audio/video media handling behind a small surface so the rest of the codebase does not depend on the ffmpeg/ffprobe binaries directly.
cli
cohere
Package cohere provides a minimal direct-HTTP adapter for the Cohere v2 API: Rerank (POST /v2/rerank), Embed (POST /v2/embed), and Chat (POST /v2/chat).
Package cohere provides a minimal direct-HTTP adapter for the Cohere v2 API: Rerank (POST /v2/rerank), Embed (POST /v2/embed), and Chat (POST /v2/chat).
colbertrerank
Package colbertrerank is a pure-Go client for a self-hosted late-interaction / multi-vector (ColBERT-style) reranking endpoint (dir2mcp#337).
Package colbertrerank is a pure-Go client for a self-hosted late-interaction / multi-vector (ColBERT-style) reranking endpoint (dir2mcp#337).
corpusfs
Package corpusfs abstracts corpus discovery and media reads behind a small interface so callers (ingest scanning, multimodal embedding) work the same against a local filesystem (an NFS mount is just a local path) or a remote object store such as S3, without knowing which.
Package corpusfs abstracts corpus discovery and media reads behind a small interface so callers (ingest scanning, multimodal embedding) work the same against a local filesystem (an NFS mount is just a local path) or a remote object store such as S3, without knowing which.
embedqueue
Package embedqueue implements the optional distributed-embedding job queue (SPEC §8.7): a coordinator enqueues embedding jobs for pending chunks and one or more stateless embed-workers lease those jobs, read the referenced corpus bytes directly via CorpusFS (§7.10), embed via the configured provider, and write the resulting vectors + chunk status back to a shared store.
Package embedqueue implements the optional distributed-embedding job queue (SPEC §8.7): a coordinator enqueues embedding jobs for pending chunks and one or more stateless embed-workers lease those jobs, read the referenced corpus bytes directly via CorpusFS (§7.10), embed via the configured provider, and write the resulting vectors + chunk status back to a shared store.
gemini
Package gemini provides a direct-HTTP adapter for Google Gemini.
Package gemini provides a direct-HTTP adapter for Google Gemini.
identity
Package identity derives a stable, unique server name for a dir2mcp instance from the absolute path of the directory it indexes.
Package identity derives a stable, unique server name for a dir2mcp instance from the absolute path of the directory it indexes.
index/diskindex
Package diskindex implements the Tier-B on-disk vector backend (issue #246).
Package diskindex implements the Tier-B on-disk vector backend (issue #246).
index/pgvectorindex
Package pgvectorindex implements the pluggable model.Index contract (issue #269) on top of PostgreSQL + the pgvector extension.
Package pgvectorindex implements the pluggable model.Index contract (issue #269) on top of PostgreSQL + the pgvector extension.
index/qdrantindex
Package qdrantindex implements the pluggable model.Index (issue #247) contract on top of a Qdrant collection (issue #268, epic #250).
Package qdrantindex implements the pluggable model.Index (issue #247) contract on top of a Qdrant collection (issue #268, epic #250).
index/topk
Package topk provides a bounded top-k selection heap shared by the local vector backends (internal/index.HNSWIndex and internal/index/diskindex).
Package topk provides a bounded top-k selection heap shared by the local vector backends (internal/index.HNSWIndex and internal/index/diskindex).
ingest/docling
Package docling parses the structured DoclingDocument JSON emitted by `docling --to json` and linearizes it into an ordered sequence of blocks that preserve reading order, the section-heading hierarchy, and per-element provenance (page + bounding box).
Package docling parses the structured DoclingDocument JSON emitted by `docling --to json` and linearizes it into an ordered sequence of blocks that preserve reading order, the section-heading hierarchy, and per-element provenance (page + bounding box).
langdetect
Package langdetect provides a pure-Go, deterministic best-effort language detector used to record a representation's language (SPEC §8.8).
Package langdetect provides a pure-Go, deterministic best-effort language detector used to record a representation's language (SPEC §8.8).
latechunk
Package latechunk implements the opt-in "late chunking" embedding path (issue #332, Jina's technique).
Package latechunk implements the opt-in "late chunking" embedding path (issue #332, Jina's technique).
mcp
netutil
Package netutil holds small, dependency-free networking helpers shared across packages that cannot import one another (e.g.
Package netutil holds small, dependency-free networking helpers shared across packages that cannot import one another (e.g.
omniembed
Package omniembed is a pure-Go client for a self-hosted, unified multimodal embedding endpoint — the off-API multimodal path (dir2mcp#334), extending the self-hosted-endpoint capability (#240) and the GPU-VPS / dual-machine epic (#250) to multimodal embedding.
Package omniembed is a pure-Go client for a self-hosted, unified multimodal embedding endpoint — the off-API multimodal path (dir2mcp#334), extending the self-hosted-endpoint capability (#240) and the GPU-VPS / dual-machine epic (#250) to multimodal embedding.
openai
Package openai provides a direct-HTTP adapter for the OpenAI-compatible API surface (POST {base}/embeddings, POST {base}/chat/completions).
Package openai provides a direct-HTTP adapter for the OpenAI-compatible API surface (POST {base}/embeddings, POST {base}/chat/completions).
pdfutil
Package pdfutil provides minimal, dependency-isolated PDF helpers for multimodal embedding (SPEC 8.1.7): counting pages and extracting a single page as its own PDF, so each page can be embedded directly with a precise page citation.
Package pdfutil provides minimal, dependency-isolated PDF helpers for multimodal embedding (SPEC 8.1.7): counting pages and extracting a single page as its own PDF, so each page can be embedded directly with a precise page citation.
promptfence
Package promptfence fences untrusted corpus text inside a model prompt.
Package promptfence fences untrusted corpus text inside a model prompt.
promptrules
Package promptrules holds the shipped RAG prompt rules whose exact text a server behaviour keys on, and the `${rag.*}` references that let an operator's rag.system_prompt point at a rule instead of copying it (#965).
Package promptrules holds the shipped RAG prompt rules whose exact text a server behaviour keys on, and the `${rag.*}` references that let an operator's rag.system_prompt point at a rule instead of copying it (#965).
provider
Package provider implements the spec 0.7.0 provider model: the normative capability matrix (SPEC 8.1.2), per-capability provider selection (8.1.3), and the embeddings corpus-lifetime identity (8.1.4).
Package provider implements the spec 0.7.0 provider model: the normative capability matrix (SPEC 8.1.2), per-capability provider selection (8.1.3), and the embeddings corpus-lifetime identity (8.1.4).
providerfactory
Package providerfactory constructs concrete model.* adapters from a resolved provider.Profile (SPEC 0.7.0 / Design 0001).
Package providerfactory constructs concrete model.* adapters from a resolved provider.Profile (SPEC 0.7.0 / Design 0001).
providerhttp
Package providerhttp holds the one hardened HTTP path that every provider adapter uses.
Package providerhttp holds the one hardened HTTP path that every provider adapter uses.
quality
Package quality provides reusable, content-only gates that detect degenerate or hallucinated STT/OCR/translation output before it is chunked and embedded.
Package quality provides reusable, content-only gates that detect degenerate or hallucinated STT/OCR/translation output before it is chunked and embedded.
relpath
Package relpath is the one rule for what a corpus-relative path may be.
Package relpath is the one rule for what a corpus-relative path may be.
scancache
Package scancache provides an optional, sqlite-backed directory-discovery cache for the corpusfs LocalFS walker (issue #267 item 5).
Package scancache provides an optional, sqlite-backed directory-discovery cache for the corpusfs LocalFS walker (issue #267 item 5).
secrets
Package secrets provides an OS keychain backend for provider credentials (SPEC §16.1.1: env → keychain → file → session).
Package secrets provides an OS keychain backend for provider credentials (SPEC §16.1.1: env → keychain → file → session).
setupwizard
Package setupwizard holds the provider-credential and corpus-profile logic behind `dir2mcp config init` and the `dir2mcp up` first-run flow (SPEC §§ config init / charmbracelet/huh).
Package setupwizard holds the provider-credential and corpus-profile logic behind `dir2mcp config init` and the `dir2mcp up` first-run flow (SPEC §§ config init / charmbracelet/huh).
statefs
Package statefs creates and repairs the local state hierarchy with owner-only permissions.
Package statefs creates and repairs the local state hierarchy with owner-only permissions.
subexport
Package subexport renders a stored transcript as a subtitle document.
Package subexport renders a stored transcript as a subtitle document.
subtitle
Package subtitle renders WebVTT and SubRip (SRT) subtitle documents from a document's stored transcript chunks.
Package subtitle renders WebVTT and SubRip (SRT) subtitle documents from a document's stored transcript chunks.
tei
Package tei is a pure-Go client for a self-hosted Hugging Face Text Embeddings Inference (TEI) server addressed on its NATIVE surface (SPEC 8.1.1 `kind: tei`, dir2mcp#565).
Package tei is a pure-Go client for a self-hosted Hugging Face Text Embeddings Inference (TEI) server addressed on its NATIVE surface (SPEC 8.1.1 `kind: tei`, dir2mcp#565).
usage
Package usage provides per-query cost and latency observability primitives for dir2mcp (issue #327).
Package usage provides per-query cost and latency observability primitives for dir2mcp (issue #327).
whisperapi
Package whisperapi is a pure-Go client for a self-hosted, OpenAI-compatible speech-to-text endpoint — the GPU-VPS path (dir2mcp#240, epic #250).
Package whisperapi is a pure-Go client for a self-hosted, OpenAI-compatible speech-to-text endpoint — the GPU-VPS path (dir2mcp#240, epic #250).
tests
cli
eval
Package tests holds the offline retrieval-quality eval + ablation harness (issue #322).
Package tests holds the offline retrieval-quality eval + ablation harness (issue #322).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL