mcp-data-server
Provides read-only, guarded access to business databases via MCP. Enables natural language querying with built-in security barriers like table allowlists, PII masking, and audit logging.
README
mcp-data-server
Sample project demonstrating production web-scraping / automation patterns.
An MCP server that gives Claude (or any MCP client) read-only access to a business database — with the guardrails that make connecting an LLM to real company data acceptable: read-only connection, table allowlist, PII masking, row caps, query timeout and a full audit log.
Ask "which countries order most, and how much did refunds cost us last quarter?" in Claude Desktop and get the answer from the actual database — with no way for the model to write, drop, attach or read a table it was not granted.
Why this exists
The blocker in most "connect AI to our data" projects is not the wiring, it is the first question from whoever owns the database: what stops it from reading or breaking something it shouldn't? This server answers that question in code.
Four independent barriers
| # | Barrier | What it stops |
|---|---|---|
| 1 | Connection opened mode=ro |
any write, even if every check above it is bypassed |
| 2 | Statement parsing | multiple statements, anything that is not SELECT / WITH |
| 3 | Keyword blocklist | ATTACH, PRAGMA, DDL, VACUUM, GRANT … |
| 4 | Allowlist + masking + caps | tables you did not grant, PII columns, oversized results, runaway queries |
Every executed statement is appended to the audit log with its row count and duration, so the data owner can see exactly what the model asked for.
2026-08-18T11:22:41 6 rows in 1ms SELECT country, COUNT(*) FROM customers GROUP BY 1 LIMIT 201
2026-08-18T11:22:44 error: rejected DELETE FROM customers
Tools exposed
| Tool | Purpose |
|---|---|
list_tables() |
readable tables + row counts |
describe_table(table) |
columns, types, which are masked, 3 sample rows |
run_sql(sql) |
one read-only SELECT, capped and audited |
search(table, column, term, limit) |
substring search without writing SQL |
summarize_column(table, column) |
nulls, distinct count, min/max, top 5 values |
Plus a schema://tables resource, so a client can load the whole schema
without spending a tool call.
Quick start
git clone https://github.com/dkautomation23/mcp-data-server.git
cd mcp-data-server
python -m venv .venv && . .venv/bin/activate # Windows: .venv\Scripts\activate
pip install -r requirements.txt
python -m mcp_data_server.seed # creates demo.db
cp .env.example .env # then point DATABASE_PATH at your file
python -m mcp_data_server # serves over stdio
Python 3.10+. The demo database has customers, orders, order_items and a
deliberately sensitive internal_notes table used below to show the allowlist
blocking access.
Connect it to Claude Desktop
Add to claude_desktop_config.json (full example in
examples/claude_desktop_config.json):
{
"mcpServers": {
"business-data": {
"command": "python",
"args": ["-m", "mcp_data_server"],
"cwd": "C:/path/to/mcp-data-server",
"env": {
"DATABASE_PATH": "C:/path/to/your.db",
"ALLOWED_TABLES": "customers,orders,order_items",
"MASKED_COLUMNS": "customers.email,customers.phone"
}
}
}
}
Connect it to Claude Code
claude mcp add business-data -- python -m mcp_data_server
What a session looks like
Real output from the running server (see
examples/demo_session.md for the full transcript):
// run_sql("SELECT status, COUNT(*) n, ROUND(SUM(total_eur)) revenue FROM orders GROUP BY 1 ORDER BY 3 DESC")
{
"sql": "SELECT status, COUNT(*) n, ROUND(SUM(total_eur)) revenue FROM orders GROUP BY 1 ORDER BY 3 DESC LIMIT 201",
"columns": ["status", "n", "revenue"],
"rows": [["paid", 92, 149914.0], ["pending", 39, 64596.0], ["refunded", 31, 45911.0]],
"row_count": 3, "truncated": false, "elapsed_ms": 0
}
// run_sql("DELETE FROM customers")
{ "error": "only SELECT (or WITH ... SELECT) statements are allowed" }
// run_sql("SELECT * FROM internal_notes")
{ "error": "table 'internal_notes' is not in the allowlist (allowed: customers, orders, order_items)" }
// run_sql("SELECT id, name, email FROM customers LIMIT 2")
{ "rows": [[1, "Customer 001", "***"], [2, "Customer 002", "***"]] }
Configuration
| Variable | Default | Purpose |
|---|---|---|
DATABASE_PATH |
demo.db |
SQLite file to expose (always opened read-only) |
ALLOWED_TABLES |
all | comma-separated allowlist; anything else is invisible |
MASKED_COLUMNS |
– | table.column list replaced with *** in every result |
MAX_ROWS |
200 |
hard cap per call; results above it are flagged truncated |
QUERY_TIMEOUT_SECONDS |
10 |
a longer query is cancelled |
AUDIT_LOG_PATH |
audit.log |
append-only log of every statement; empty disables it |
Tests
pytest -q
............................... [100%]
31 passed in 1.77s
Three layers: the SQL guardrails (injection, second statements, comment
smuggling, forbidden tables), the database layer against a real seeded file
(including a write attempt that SQLite itself rejects), and seven tests that
drive the server over the actual MCP protocol — the same handshake,
list_tools and call_tool flow a desktop client performs.
Adapting it to a client's stack
- Postgres / MySQL: replace the connection in
db.pywith a pooled driver and aSET TRANSACTION READ ONLYsession; the validation layer is unchanged. - Business-specific tools: add a function with
@mcp.tool()inserver.py— a well-namedtop_customers(period)beats making the model write SQL. - HTTP transport instead of stdio:
mcp.run(transport="streamable-http"), then put it behind your own auth.
License
MIT — see LICENSE.
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.
E2B
Using MCP to run code via e2b.