Skip to main content

MCP server providing semantic knowledge base with LanceDB storage and configurable embeddings

Project description

lancedb-mcp

MCP knowledge base server for OpenCode with LanceDB storage and OpenAI-compatible embeddings (llama.cpp, Ollama, etc.).

What it does

Provides a semantic knowledge base that your OpenCode agent can use to remember and recall facts, rules, conventions and decisions across sessions. The agent autonomously decides when to store and search — no manual tool invocation needed.

Agent: discovers that "deploy is via make deploy-prod on Wednesdays"
       → calls kb_add("Deploy on Wednesdays via make deploy-prod", source="ops")

Agent: (next session, user asks about deployment)
       → calls kb_search("how to deploy to production")
       → gets: "Deploy on Wednesdays via make deploy-prod" (score: 0.92)
       → answers user correctly

Architecture

OpenCode ──MCP stdio──> lancedb-mcp (Python)
                            ├── LanceDB (on-disk vector storage)
                            └── OpenAI-compat endpoint (llama.cpp, Ollama, etc.)

Quick start

1. Install

cd lancedb-mcp
uv venv
uv sync

2. Start an embedding backend

The server requires an OpenAI-compatible embedding endpoint. Any of these work:

# llama.cpp
llama-server -m model.gguf --embeddings --host 127.0.0.1 --port 8080

# Ollama
ollama serve

3. Configure OpenCode

Add to opencode.json:

{
  "mcp": {
    "knowledge-base": {
      "type": "local",
      "command": ["uv", "run", "lancedb-mcp"],
      "environment": {
        "EMBED_API_BASE": "http://localhost:8080/v1",
        "KB_STORAGE_PATH": ".kb_data"
      },
      "enabled": true
    }
  }
}

Restart OpenCode for changes to take effect.

Tools available to the agent

Tool Description Parameters
kb_add Add text to the knowledge base text (required), source (default: "agent")
kb_search Semantic search, returns JSON [{text, source, score}] query (required), limit (default: 5), source (optional filter)
kb_list List stored documents limit (default: 20)
kb_delete Delete a document by ID doc_id (required)
kb_stats Document count, returns JSON {total_documents: N}

Configuration

Embedding settings (EMBED_*)

Variable Default Description
EMBED_API_BASE Required. URL of your OpenAI-compatible embedding endpoint
EMBED_MODEL "" Model name sent to the endpoint (ignored by llama.cpp)
EMBED_API_KEY "" API key (ignored by llama.cpp, required for cloud endpoints)

Storage settings (KB_*)

Variable Default Description
KB_STORAGE_PATH .lancedb_data Directory for LanceDB files
KB_TABLE_NAME knowledge Table name inside LanceDB

CLI flags

lancedb-mcp --help
  --transport {stdio,sse,streamable-http}  # MCP transport (default: stdio)
  --host 127.0.0.1                          # Host for SSE/HTTP modes
  --port 8001                               # Port for SSE/HTTP modes
  --top-k 5                                 # Max search results

Storage

Data is stored as LanceDB tables on disk. Each table:

Column Type Description
id string Auto-generated document ID
vector float32[n] Embedding vector
text string Original document text
source string Origin tag (agent, user, ops, dev, ...)

Use the source field to organize facts by domain and filter via kb_search(source="ops").

Running tests

Unit tests

uv run pytest tests/ -v -k "not integration"

46 tests, ~1.5s. Use a deterministic local embedder — no external dependencies needed.

Integration tests

Require a running OpenAI-compatible embedding endpoint (e.g. llama.cpp on localhost:8080):

uv run pytest tests/test_integration.py -v

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

lancedb_mcp-0.1.0.tar.gz (25.1 kB view details)

Uploaded Source

Built Distribution

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

lancedb_mcp-0.1.0-py3-none-any.whl (23.1 kB view details)

Uploaded Python 3

File details

Details for the file lancedb_mcp-0.1.0.tar.gz.

File metadata

  • Download URL: lancedb_mcp-0.1.0.tar.gz
  • Upload date:
  • Size: 25.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"NixOS","version":"26.05","id":"yarara","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for lancedb_mcp-0.1.0.tar.gz
Algorithm Hash digest
SHA256 53cb44bfbb03857494a9fcfd244e424f0990b3b1d5071890741a5d3c662b5aa2
MD5 b1c2d722336417c973a6aa437bff268c
BLAKE2b-256 efdbdb0cd46fb38efcdadf710f343d5cb0871226bb3adacf69058af83efdd21d

See more details on using hashes here.

File details

Details for the file lancedb_mcp-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: lancedb_mcp-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 23.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"NixOS","version":"26.05","id":"yarara","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for lancedb_mcp-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ec62649ace7a840badd15685e0bc8e65cab78cad6f9da4b11e400e67876cc3c7
MD5 fc579358176a9e8de4d2a3b370670d27
BLAKE2b-256 6c6131d22970c626f18c8b31fc5d407e67e36d266ec2052545e37aede4093fb1

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