Skip to main content
Glama
Software Literature MCP

Software Literature MCP

by rcarubbi
README.md
# Software Literature MCP

Local MCP server for indexing and searching technical books (PDF/EPUB) with hybrid semantic and full-text search. Source documents and index remain on your machine; text sent for embeddings goes to your configured embedding provider.

## Requirements

- Python 3.11+
- An embeddings API with an OpenAI-compatible `POST /embeddings` endpoint
- Provider API key (or OpenCode Console credentials)

## Install

```bash
git clone https://github.com/rcarubbi/software-literature-mcp.git
cd software-literature-mcp
python -m venv .venv
```

Activate the virtual environment, then:

```bash
python -m pip install -r requirements.txt
```

Put PDF/EPUB files under `~/Books` (or configure `BOOKS_DIRECTORY`). Set `EMBEDDING_API_KEY`, `EMBEDDING_BASE_URL`, and `EMBEDDING_MODEL` for your provider. Defaults target OpenCode Console and `text-embedding-3-small`.

For OpenCode Console users, the server can read the `opencode` key from OpenCode's `auth.json` on Windows or macOS/Linux. Alternatively, set `OPENCODE_API_KEY`. For other providers, use `EMBEDDING_API_KEY`; optionally set `OPENCODE_AUTH_PROVIDER` and `OPENCODE_AUTH_FILE` if using a compatible OpenCode auth entry.

Example PowerShell:

```powershell
$env:BOOKS_DIRECTORY = "$HOME\Books"
$env:EMBEDDING_BASE_URL = "https://opencode.ai/inference/openai/v1"
$env:EMBEDDING_MODEL = "text-embedding-3-small"
$env:EMBEDDING_API_KEY = "your-provider-key"
```

Do not commit API keys. Any text submitted for indexing or search is sent to the configured provider for embedding; review that provider's privacy and pricing terms.

## OpenCode MCP configuration

Add a server entry to your OpenCode config (`opencode.json`), adjusting paths and environment variables:

```json
{
  "mcp": {
    "software-literature": {
      "type": "local",
      "command": ["C:\\path\\to\\software-literature-mcp\\.venv\\Scripts\\python.exe", "C:\\path\\to\\software-literature-mcp\\server.py"],
      "environment": {
        "BOOKS_DIRECTORY": "C:\\Users\\you\\Books",
        "EMBEDDING_BASE_URL": "https://opencode.ai/inference/openai/v1",
        "EMBEDDING_MODEL": "text-embedding-3-small"
      }
    }
  }
}
```

On macOS/Linux, set `command` to the venv Python executable and server path, and use your books directory. Keep secrets in the process environment rather than this config file.

## Tools

- `index_books(action="estimate")`: extract books locally and estimate token count/cost; does not call the embedding API.
- `index_books(action="status")`: show indexed books.
- `index_books(action="execute", confirm_cost=true, max_cost_usd=...)`: index only if the estimate is within the explicitly supplied ceiling.
- `search_books(query, top_k=8, book=...)`: hybrid semantic/full-text search with book, source path, page/chapter, and excerpts.

Cost estimate uses `EMBEDDING_PRICE_PER_MILLION_TOKENS` (default `$0.02`, OpenCode Console `text-embedding-3-small`). Set it to your provider's price; set to `0` for a free/local endpoint. The ceiling is a guard, not a guarantee of provider billing.

Index database defaults to the OS user data directory. Override with `LITERATURE_DATA_DIRECTORY`. An index is tied to its embedding base URL and model; use a separate data directory when changing either.

## Test

```bash
python -m unittest discover -s tests -v
```

## License

MIT. See [LICENSE](LICENSE).