SuperAPI AI Directory

querywise-mcp

Query SQLite, PostgreSQL, BigQuery and Databricks in natural language through a business semantic layer: glossary, metrics and a data dictionary.

Open website

About this tool

QueryWise MCP is an MCP server (which also provides a CLI) that lets large language models query databases in natural language through a business semantic layer. The semantic layer includes a glossary, metric definitions, a data dictionary, a knowledge base, and example queries, and is grounded in the real schema. It is a refactored version of QueryWise (a full-stack text-to-SQL application), turned into a headless tool: there is no web UI, and Postgres is not required. The metadata store is an embedded SQLite + sqlite-vec database, so the server can run from a single file.

Two ways to use it

As an MCP server: Claude (or any MCP client) calls the tools. The recommended loop is: get_semantic_context(connection, question) → the model writes a read-only SELECT → run_sql(connection, sql). The client's own model handles the reasoning; the server provides grounded context and safe execution.

As a CLI: querywise ask <connection> "<question>" runs the full server-side NL→SQL pipeline (compose → validate → execute → interpret). This path requires an LLM provider key (or local Ollama).

The semantic layer, connectors, and execution are shared by both modes.

Configuration

Configure via environment variables / .env (see .env.example). Zero configuration works for keyword-only operation; add a key (or Ollama) to unlock embeddings and the ask pipeline.

Quick start (zero external infrastructure)

Run as an MCP server.

Register with Claude: first make sure the store the server will read has been initialized (and optionally seeded with data). Use absolute command paths. MCP clients start the server with a minimal PATH, so a bare querywise-mcp usually cannot be resolved. Point to the entry point inside the venv, for example /path/to/.venv/bin/querywise-mcp. The server does not read your repository .env. It runs from the client's working directory, so pass in everything it needs in the env block below (DATABASE_URL, providerkey, model).

Claude Desktop — edit ~/Library/Application Support/Claude/claude_desktop_config.json (macOS), then fully quit and reopen Claude Desktop.

Claude Code — one command.

Note the four slashes in the SQLite URL — sqlite+aiosqlite:// (scheme) plus the absolute path /Users/me/....

Why is DEFAULT_LLM_PROVIDER needed? It is a server setting, not your chat model. Claude is the client LLM — it calls fine-grained tools and writes the answer, so it does not need provider configuration. The server uses a provider for only two things: embeddings (semantic search over metadata — optional; without it, it falls back to keyword-only) and the all-in-one ask / generate_sql tools (which run their own LLM). Set it to ollama for keyless local embeddings, or to anthropic / openai (and provide the matching *_API_KEY in env) if you want to call the server-side ask tool. Omit it entirely to run keyword-only.

Tools (25)

list_connections, create_connection, test_connection, introspect_connection, delete_connection, list_tables, describe_table, get_semantic_context, run_sql, generate_sql, ask, query_history, glossary/metric/dictionary/sample-query/knowledge management (list_* / add_* / delete_*, and add_knowledge_url).

Query path — the four tools people easily confuse:

Resource: querywise://{connection}/schema — the text form of the cached schema. Prompt: text_to_sql(connection, question) — build the ground→write→run loop.

connection accepts a connection name or id everywhere.

All execution is read-only: a static SQL blacklist (DDL/DML/administrative/injection) plus connector-level read-only enforcement.

How the semantic layer works

For each question, the context builder selects the minimal relevant context through a mix of: (1) vector similarity on embeddings, (2) keyword matching, (3) foreign-key expansion, then resolves glossary terms, metrics, dictionary value mappings, knowledge excerpts, and example queries into structured prompt blocks. Embeddings are stored as float32 BLOBs and searched using sqlite-vec's vec_distance_cosine; if the extension cannot be loaded, the search transparently falls back to in-process cosine. Without an embedding provider, it degrades to keyword matching only.

Building the semantic layer

Glossary terms, metrics, value dictionaries, example queries, and knowledge documents are populated through MCP management tools — so you can build them conversationally from an MCP client such as Claude, with no CLI required. Asking Claude to "add a glossary term active customer defined as ... using SQL ..." invokes add_glossary_term; likewise add_metric, add_dictionary_entry, add_sample_query, and add_knowledge / add_knowledge_url (along with the matching list_* / delete_* tools for viewing or deleting them). For a ready-made example, querywise seed-sample loads the bundled IFRS 9 banking layer.

The metadata schema is created at startup (db/init.py) — there is no migration tool. Switching the embedding provider/dimension automatically clears vectors that are no longer compatible.