MCP server for natural-language queries against SAP CAP db-layer entities via real CQN/SQL JOINs.
Copy the AI prompt to install this server into Claude Code, Cursor, or another agent β or use 1-click editor setup below.
π‘ Paste the JSON block into your client's configuration file under mcpServers, then restart the application.
MCP server for natural language queries against CDS db-layer entities (db/schema.cds).
Ask questions about your database in plain English. The server discovers your schema automatically, generates real SQL JOINs using CDS, and returns rows. No hardcoded queries, no SQL, no schema configuration. Bring your own LLM: Anthropic or OpenAI, or any OpenAI-compatible endpoint (Azure OpenAI, Groq, Ollama, local models, etc.).
Targets the
db/layer, not OData services. If your entities are exposed as OData services, use an MCP package that targets the service layer instead.
Read-only. This package only executes SELECT queries. No INSERT, UPDATE, or DELETE.
@sap/cds >= 71. Install in your CAP project
2. Create .mcp.json in your CAP project root (same folder as package.json)
Set cwd to the absolute path of your CAP project root, where db/schema.cds lives. See LLM provider for using OpenAI, Gemini, or another provider instead.
npx -y re-resolves the package on every server start (from npm's cache once
downloaded, not a fresh network fetch each time, but still an extra resolution
step). If you've run npm install @shahid.la/cds-db-nlquery-mcp already, you
can point "command" at the installed binary directly instead,
node_modules/.bin/cds-db-nlquery-mcp, for a slightly more predictable startup,
especially in production.
3. Open your project in Claude Code and ask a question
Example response: the server tells the client to render rows as a vertical field/value list, not a markdown table (real output, verified against a live deployment):
When you ask a question:
natural_language_query tool with your question.customer.BU_SORT1) generate real SQL JOINs, executed by your database, not by JavaScript. Scales to production data volumes.The LLM call in step 2 is a small, cheap planning step (translating your question into JSON). It does not need a large or expensive model. A fast/cheap tier model is recommended.
All configuration is via environment variables in the .mcp.json env block.
| Variable | Default | Description |
|---|---|---|
MCP_ALLOWED_ENTITIES | (all entities) | Comma-separated list of entity short names, the name after the last dot in the FQN (e.g. Customers, not my.app.Customers). Leave unset during development; always set for production. |
MCP_BLOCKED_COLUMNS | (none) | Comma-separated column names to exclude from all results. Stripped before the query runs. Useful for columns like EMBEDDING, PASSWORD, SSN. |
MCP_MAX_ROWS | 500 | Maximum rows per query. Enforced as a SQL LIMIT, not a post-fetch filter. |
MCP_MODEL_PATH | db | Path to your CDS model folder or file, relative to cwd. Change if your schema is at model/, srv/, etc. |
MCP_DB_USER / MCP_DB_PASSWORD | (consumer app's own DB user) | Connect with a different HANA user than your app's runtime user. Host/port/schema are reused, only credentials are overridden. See Security β Production for why this matters. |
A small LLM call translates your question into a query descriptor. Bring your own provider, set ONE of the following in the env block:
Anthropic (Claude):
OpenAI, or any OpenAI-compatible provider:
OPENAI_MODEL accepts any model name. Use whatever your provider expects. Set OPENAI_BASE_URL to point at a different OpenAI-compatible endpoint:
| Provider | OPENAI_BASE_URL | Example OPENAI_MODEL |
|---|---|---|
| OpenAI | (omit, uses default) | gpt-4o-mini |
| Google Gemini | https://generativelanguage.googleapis.com/v1beta/openai/ | gemini-2.0-flash |
| Groq | https://api.groq.com/openai/v1 | llama-3.1-8b-instant |
| Mistral | https://api.mistral.ai/v1 | mistral-small-latest |
| DeepSeek | https://api.deepseek.com | deepseek-chat |
| xAI (Grok) | https://api.x.ai/v1 | grok-2-latest |
| Azure OpenAI | your Azure endpoint | your deployment name |
| Ollama (local) | http://localhost:11434/v1 | llama3.1 (API key can be any non-empty string) |
| Variable | Description |
|---|---|
LLM_PROVIDER | "anthropic" or "openai". Auto-detected from whichever API key is set, only needed if both are set and you want to force one. |
ANTHROPIC_API_KEY / ANTHROPIC_MODEL | Anthropic native API |
OPENAI_API_KEY / OPENAI_MODEL / OPENAI_BASE_URL | OpenAI or any OpenAI-compatible endpoint |
This is a planning-only call (question to JSON descriptor). A fast/cheap tier model is sufficient and recommended.
The server uses your project's existing database connection, whatever CDS has configured in default-env.json or your service binding. No extra setup needed.
Important: this package queries the database directly via cds.run(). It does not go through the CAP service layer, so CAP @requires and @restrict annotations are not enforced. Access control is entirely your responsibility at the database and configuration level.
Step 1: Create a dedicated read-only database user
This user can only read. No write access. HANA itself enforces it, independently of this package.
Step 2: Point the server at it with MCP_DB_USER/MCP_DB_PASSWORD
The server connects with these credentials instead of inheriting your app's own database connection. Host, port, and schema are reused automatically, only the user/password are overridden:
If you keep these in a separate gitignored file instead of directly in .mcp.json,
that's fine too. The server just reads process.env, same as any other variable here.
Step 3: Set MCP_ALLOWED_ENTITIES
This is enforced on the entity you query directly and on any entity reached via
an association join in select/where. For example, if Customers isn't in the allowlist,
a query against Orders can't read Customers data through a customer.NAME join
path either. The database user restricts access at the HANA level;
MCP_ALLOWED_ENTITIES adds a second layer at the application level. Use both.
The server reads CDS associations from your schema. When the LLM references customer.BU_SORT1 in a query, CDS generates a real SQL JOIN, executed by the database.
Multiple associations in one query work:
"Show loans in the MINING sector with borrower name and current DTI"
Generates a single SQL statement joining Loans β BusinessPartners β BCA_DTI in one database round-trip.
One constraint: do not select the same column name from two different entities in the same query (e.g. LOAN_ID from both the main entity and a joined entity). The database rejects duplicate column names. Claude is instructed to avoid this, but worth being aware of.
Most filters compare a column to a fixed value (DTI_RATIO > 5). For questions like "which loans have collateral worth less than the loan amount", the comparison is between two columns instead. Use valCol in place of val:
No reviews yet β be the first to share how this listing worked for you.
Showcase your server listing on GitHub or your project documentation. Embed this dynamic SVG badge to highlight official listing status and live engagement.
[](https://allmcps.com/mcp/cds-db-nlquery-mcp)<a href="https://allmcps.com/mcp/cds-db-nlquery-mcp"><img src="https://allmcps.com/api/badge/cds-db-nlquery-mcp?style=directory" alt="Cds Db Nlquery MCP on AllMCPs" /></a>