Skip to main content

VirtuDoc

CI codecov PyPI Python versions License: MIT

virtudoc demo

The problem it solves. Coding agents re-download the same documentation every session, work only with public APIs, and invent your internal interfaces because your private docs were never reachable. VirtuDoc fixes the context side: your documentation is indexed once, locally, and served to any MCP client — verified fragments, not model guesses.

VirtuDoc is a local documentation server for AI agents. It indexes documentation from local directories into SQLite with FTS5 full-text search and serves relevant fragments to an agent through MCP tools. Fully offline: no network access happens in any mode.

Private and internal docs never leave your computer: there are no API keys, request limits, or cloud dependencies.

Installation

pip install virtudoc

Requires Python 3.11+. The only runtime dependencies are markdown-it-py (Markdown parsing) and the mcp SDK.

Quick start

# Register a documentation directory and index it
virtudoc add /path/to/docs --name mylib --version 2.1.0

# Index statistics
virtudoc list

# Search from the terminal (same results an agent will get via MCP)
virtudoc search "how to handle authentication errors"

# Incremental reindexing after the docs changed
virtudoc update              # all libraries
virtudoc update --name mylib

# Full rebuild of one library (applies changed chunk.* settings)
virtudoc reindex mylib

# Remove a library
virtudoc remove mylib

# Attach a team convention note to a library (agents receive it with docs)
virtudoc note add mylib --text "Use the retry helper for all outbound calls."

# Warn when the indexed docs version diverges from the project dependency
virtudoc link mylib --project /path/to/consuming/project
virtudoc doctor   # config, sources, index integrity, version drift summary

# Zero-config onboarding: scan the project's manifests and match libraries
virtudoc init .              # report only; add --link to create the links

# Pull public documentation from a git URL or archive (the only networked command)
virtudoc fetch --repo https://github.com/org/docs --name theirlib

# Move your whole setup to another machine (see docs/installation.md)
virtudoc export            # dump the library list to ~/.virtudoc/libraries.toml
virtudoc import            # register and index everything from the file

Connect your agent

Run the MCP server and register it in your agent's config. The server speaks stdio by default and refreshes a library incrementally when an agent first requests it, so the agent always sees current documentation. Agents spawn the server with a default environment, so the data directory is ~/.virtudoc — set VIRTUDOC_HOME in the server env block if you need a custom location.

Claude Code — add to .mcp.json in your project (or run claude mcp add virtudoc --scope user -- virtudoc serve):

{
  "mcpServers": {
    "virtudoc": {
      "command": "virtudoc",
      "args": ["serve"]
    }
  }
}

Cursor — add to .cursor/mcp.json:

{
  "mcpServers": {
    "virtudoc": {
      "command": "virtudoc",
      "args": ["serve"]
    }
  }
}

OpenCode — add to opencode.json (project root or ~/.config/opencode/opencode.json):

{
  "$schema": "https://opencode.ai/config.json",
  "mcp": {
    "virtudoc": {
      "type": "local",
      "command": ["virtudoc", "serve"],
      "enabled": true
    }
  }
}

MCP tools

  • find-library(libraryName, query) — find the local/<name> id of a library by its name and your question. Call it first.
  • get-library-docs(libraryId, query, tokens=5000, language, page, mode, section) — Markdown fragments with heading paths and source file paths, assembled under the token budget. total_matches and has_more describe pagination; page=N+1 continues the ranking. section restricts the answer to a heading branch and takes a path, e.g. "Guide → Authentication" or a top-level branch name ("Guide") — a bare leaf name alone does not match. Relevant project notes are included before the fragments. Empty results return the library's top-level sections to help rephrase the query.

Optionally expose the server over streamable HTTP on 127.0.0.1 for clients without stdio support: virtudoc serve --http [port] (default port 8765).

Why not Context7 or a RAG index?

  • Hosted doc servers (Context7 and similar) serve public documentation from the network. VirtuDoc indexes the docs you actually work with: private repos, internal specs, vendored doc trees. Nothing leaves your machine — no API keys and no rate limits.
  • Embedding-based RAG needs an embedding model, a vector store and re-embedding on every doc change. VirtuDoc is SQLite FTS5 with BM25: one pip install, incremental indexing by content hash, and deterministic results — the same query returns the same fragments.
  • Documentation structure fits BM25 better than similarity search: chunks are cut along headings, results carry their section path, and the token budget is respected exactly — so an agent gets a predictable, bounded context.

If you only consume public docs and prefer hosted infrastructure, Context7 is a good fit. If your documentation is private, internal or must stay offline, that is the gap VirtuDoc closes.

Supported formats: Markdown (.md, .mdx), reStructuredText (.rst), plain text (.txt), HTML (.html, .htm, best-effort text extraction). Hidden files and directories are always skipped; a .virtudocignore file at the source root (.gitignore-compatible syntax: globs, **, ! negation, directory patterns) excludes generated or vendor trees from indexing.

How it works

  • The chunker splits documents along H2/H3 headings (target chunk size 600 tokens, hard limit 1200, 60-token overlap); code blocks are never split.
  • Search is SQLite FTS5 with BM25 ranking; fragment scores are BM25 values, not positions. Queries cascade: exact AND → prefix AND with Russian ending / English suffix stemming → OR, so Russian inflections (пакетная finds пакетной) and fuzzy phrasing both resolve.
  • Results are assembled under a token budget (default 5000) with a topic boost for chunks whose heading path matches the query on token boundaries.
  • Indexing is incremental: unchanged files are skipped by content hash.
  • All data lives in ~/.virtudoc/ (WAL-mode index.db, config, log). Deleting the directory removes the system completely.

Configuration

~/.virtudoc/config.toml (all keys optional):

[chunk]
target_tokens = 600
max_tokens = 1200
overlap_tokens = 60

[search]
default_tokens = 5000
max_results = 20

[log]
level = "INFO"

Changing chunk.* only affects new indexing; the existing index is not rebuilt automatically.

Documentation

  • docs/ — full documentation: installation, getting started, CLI reference, MCP integration, configuration, indexing and search internals, project notes, version drift warnings
  • ARCHITECTURE.md — components, data flows, storage schema

Development

pip install -e '.[dev]'
pytest
ruff check virtudoc tests
ruff format virtudoc tests

Status

Milestones M1 (core: indexing, chunking, FTS5 search, CLI) and M2 (MCP server over stdio/HTTP, project notes, outline mode, .virtudocignore) are done, plus link/doctor version drift warnings and the fetch command. Published on PyPI.

License

MIT, see LICENSE.

Metadata

Release files for virtudoc 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for virtudoc 0.2.0
File Size Uploaded Provenance Actions
virtudoc-0.2.0.tar.gz 76.7 kB Without provenance Details for virtudoc-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for virtudoc 0.2.0
File Interpreter ABI Platform Actions
virtudoc-0.2.0-py3-none-any.whl Python 3 none any Details for virtudoc-0.2.0-py3-none-any.whl

Total release size: 125.2 kB

Release files / virtudoc-0.2.0.tar.gz

Download URL virtudoc-0.2.0.tar.gz
Size 76.7 kB
Tags Source
SHA-256 checksum
How to use checksums
8009a270ef5039da97112517d25c3a2cb48e1b4c82ad5b5fd4ba9264f9d2b5ee
BLAKE2b-256 checksum
How to use checksums
d7fd53998f430c4f55c8dc0a2ea0226e1784dc6d9ea2fbff3dac172d4f3c9ec0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / virtudoc-0.2.0-py3-none-any.whl

Download URL virtudoc-0.2.0-py3-none-any.whl
Size 48.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
095d5def3c8af9485935e3bd86193262586e15f3530c8604b32a2da131acb196
BLAKE2b-256 checksum
How to use checksums
4a9b1cb2e396254e7c72f15ba1869a4e14f2a8f8cb5886654a8037cfef574456
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Security for virtudoc 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page