Skip to main content
Glama
README.md
# debtool-mcp

A local, read-only [MCP](https://modelcontextprotocol.io) server that lets an
LLM agent discover and use Debian packages by **intent**, not by guessing
command names. It answers questions like:

- "What can extract text from a PDF?" → `pdftotext`, already installed
- "How do I trim a video?" → a ranked list of installed and available tools
- "Which package provides `cowsay`?" → `cowsay`, plus the install command
- "Show me the two options I need and one example." → a compact card, not a
  3,000-line man page

The design goal is **low token cost**: results are short Markdown cards, sorted
by usefulness, with an explicit next step on every answer.

## What it is not

`debtool` never runs `sudo`, never installs anything, never starts apps or
services, and never executes the tools it describes. `deb_install_plan` only
simulates an install and prints the exact command for the user to run. The
only file it writes is its own SQLite index under `~/.cache/debtool/`.

## Install

Requirements: Debian/Ubuntu, Python ≥ 3.10, `dpkg`, `apt`, `man-db`.

```bash
# from this directory
uv tool install .
# or
pipx install .
```

Then build the index once:

```bash
debtool refresh          # ~10 s on a typical desktop
debtool status
```

`debtool refresh --scope installed` builds a much smaller, faster index that
contains only installed packages (available-package search is then disabled).

## MCP client configuration

The entry point is `debtool-mcp` and speaks MCP over stdio.

Generic JSON (Claude Desktop, most clients):

```json
{
  "mcpServers": {
    "debtool": {
      "command": "debtool-mcp",
      "args": []
    }
  }
}
```

OpenCode (`opencode.json`):

```json
{
  "mcp": {
    "debtool": {
      "type": "local",
      "command": ["debtool-mcp"],
      "enabled": true
    }
  }
}
```

If `debtool-mcp` is not on the client's `PATH`, use an absolute path or run it
through `uv`:

```json
{
  "mcpServers": {
    "debtool": {
      "command": "uv",
      "args": ["run", "--directory", "/home/yann/dev/MCP_Debian_tools", "debtool-mcp"]
    }
  }
}
```

For HTTP/SSE instead of stdio:

```bash
debtool serve --transport streamable-http --host 127.0.0.1 --port 8000
```

## Tools

| Tool | Purpose | Typical call |
| --- | --- | --- |
| `deb_search` | Find by intent across commands, apps, packages, services | `deb_search("extract text from pdf", installed="yes")` |
| `deb_card` | One compact card: package, binaries, options, examples | `deb_card("pdftotext")` |
| `deb_man` | Focused man-page excerpt | `deb_man("curl", mode="options", query="proxy")` |
| `deb_provides` | Package that provides a command, file or virtual package | `deb_provides("pdftotext")` |
| `deb_install_plan` | Simulated install + exact `sudo` command | `deb_install_plan("cowsay")` |
| `deb_compare` | Compare 2–6 candidates | `deb_compare(["pdftotext","qpdf"])` |
| `deb_status` | Index freshness, counts, optional helpers | `deb_status()` |
| `deb_refresh` | Rebuild the index when stale | `deb_refresh()` |

`deb_man` modes are `synopsis` (default), `examples`, `options`, `files`, and
`full`. Start with the first two; `full` is large by design.

Resources: `deb://status`, `deb://installed`.
Prompt: `find_debian_tool(task)` — a guided search → card → examples →
install-plan workflow.

## Example interaction

```text
user: I need to pull the text out of some PDFs.
agent -> deb_search("extract text from pdf")
        pdftotext (cmd, installed) poppler-utils — PDF to text converter (version 3.03)
        pdfimages (cmd, installed) poppler-utils — PDF image extractor
        hint: deb_card("pdftotext") for usage; deb_man("pdftotext", mode="examples")

agent -> deb_card("pdftotext")
        ## command: pdftotext
        package: poppler-utils (installed 25.03.0-5+deb13u4)
        Portable Document Format (PDF) to text converter (version 3.03)
        use: pdftotext [options] PDF-file [text-file]
        opts: -f number … first page, -l number … last page, -r number … resolution
        docs: man pdftotext
```

The agent now has enough to run `pdftotext -f 1 -l 5 in.pdf out.txt` without
reading the full manual.

## How the index is built

At refresh time, `debtool` reads local, already-trusted metadata:

- `/var/lib/dpkg/status` — installed packages
- `apt-cache dumpavail` — available packages (88 MB of stanzas, deduped by host
  architecture)
- `/var/lib/dpkg/info/*.list` — installed files, binaries and man pages
- `whatis` / man-db — one-line descriptions for commands
- `/usr/share/applications` — desktop entries
- `/usr/lib/systemd/system`, `/usr/share/dbus-1` — services

These are merged into one SQLite database with an FTS5 index. One query hits
packages, commands, desktop apps and services at once.

Search also expands a small built-in intent table (`pdf`, `ocr`, `video`,
`compress`, `disk`, `http`, `backup`, …) so "trim video" also considers
`ffmpeg`, `mpv` and friends even when those words never appear in a package
description.

## Token-efficiency choices

- Progressive disclosure: search → card → man excerpt → full page.
- Hard caps: 8 hits by default, 20 options, 12,000 characters per response
  (`DEBTOOL_MAX_OUTPUT`).
- One-line summaries are clipped on word boundaries.
- Install plans show the command, a simulation summary, and nothing else.
- Every result ends with a concrete next call.

## Configuration

| Variable | Default | Meaning |
| --- | --- | --- |
| `DEBTOOL_CACHE_DIR` | `$XDG_CACHE_HOME/debtool` | Cache directory |
| `DEBTOOL_DB` | `<cache>/index.sqlite` | Index path |
| `DEBTOOL_AUTO_REFRESH` | `1` | Rebuild when dpkg/apt metadata changes |
| `DEBTOOL_INDEX_TTL` | `0` | Max index age in seconds (0 = no age limit) |
| `DEBTOOL_MAX_OUTPUT` | `12000` | Max characters returned per tool call |

## Optional helpers

Installed file lists cover reverse lookup for installed packages. To also map
**not-installed** commands to packages, install the standard helpers:

```bash
sudo apt install command-not-found apt-file
sudo apt update && sudo apt-file update
```

`debtool` detects and uses them automatically; no configuration needed.
`apt-file` and `command-not-found` are only useful once their data is present:
`deb_status` reports "installed but its Contents index is empty" (or database)
and names the command that fixes it, and `deb_provides` skips the call until
then instead of waiting on an empty cache.
`appstreamcli`, `tldr` and `bwrap` are used opportunistically when present.

## Limitations

- Man pages are indexed only for installed packages; `deb_man` on an
  uninstalled package reaches man-db at call time and may find nothing.
- Available-package reverse lookup by command needs `apt-file` or
  `command-not-found`.
- The apt candidate is approximated by arch preference, not by full APT pinning
  policy; `deb_install_plan` always checks the real candidate with `apt-cache
  policy` before printing anything.
- Multiarch duplicates are collapsed to one record per package name.

## Development

```bash
uv venv
uv pip install -e ".[dev]"
pytest
ruff check src tests
debtool refresh
debtool search "disk usage"
```

Tests use an in-memory SQLite fixture and do not touch the real index.

## License

[The Unlicense](https://unlicense.org): this is free and unencumbered
software released into the public domain. See [LICENSE](LICENSE).

TDQS

A3.5/5.0

Scored across 8 tools

Disambiguation5/5

Each tool targets a distinct operation: search, provides, man, card, install_plan, compare, status, and refresh. There is little overlap, and the descriptions make the boundaries clear.

Naming Consistency4/5

All tools consistently use the deb_ prefix, which makes the server easy to identify. The suffixes mix noun and verb forms (deb_card, deb_search, deb_status, deb_refresh), but the pattern remains predictable and readable.

Tool Count5/5

Eight tools is well-scoped for a Debian package/command lookup and planning server. Each tool has a distinct role, and there is no obvious bloat.

Completeness4/5

The surface covers discovery, package ownership, man pages, comparisons, install planning, and index maintenance. Minor gaps exist, such as no uninstall/removal plan or dependency inspection, but core workflows are supported.