Universal Database MCP
A small MCP server that lets an LLM query PostgreSQL, MySQL, MariaDB, SQL Server, or SQLite databases safely — read-only, role-restricted, and with sensitive data blacked out.
README
Anvaya Labs — Universal Database MCP (Simple Version)
A small MCP server that lets an LLM query PostgreSQL, MySQL, MariaDB, SQL Server, or SQLite databases safely — read-only, role-restricted, and with sensitive data blacked out.
Files (4 files, ~650 lines total, no classes/decorators/async)
config.py— plain dictionaries: who can see what, which columns get masked. Edit this file to change any rule.security.py— 4 plain functions: check it's read-only, check the role is allowed, add tenant filtering, mask sensitive values.db_engine.py— 3 plain functions: get schema, run query, explain query. Talks to the actual database.server.py— the 4 tools the LLM can call, each just a try/except around the functions above, with a log line either way.
Keeping database passwords out of chat
db_uri no longer has to be a raw connection string typed into the
conversation. Instead:
- Copy
.env.exampleto.envand fill in real connection strings there. - In chat, refer to a database by its short name — e.g. "query the
proddatabase" — and passdb_uri="prod". The server looks upANVAYA_DB_PRODin the environment and uses that. - Leaving
db_uriempty ("") usesANVAYA_DEFAULT_DB_URIinstead.
A full connection string (containing ://) still works directly if you
pass one — useful for quick local testing — but the recommended pattern
is to never type a real password into the chat at all.
Authentication (for remote/multi-team deployments)
Since other people connect to this server, role can no longer be
trusted as something the LLM just tells the server — anyone could type
role="admin". Instead:
- Generate a secret once and put it in
.env:python -c "import secrets; print(secrets.token_hex(32))"ANVAYA_JWT_SECRET=<paste it here> ANVAYA_MCP_TRANSPORT=http - Whenever someone needs access, mint them a signed token:
uv run python issue_token.py --name alice --role analyst --tenant acme - Give that token to them. Their MCP client connects with it as a
Bearer token. The server verifies the signature on every call and
uses the role/tenant from the token — any
role/tenant_idthey try to pass as arguments is ignored.
If ANVAYA_JWT_SECRET isn't set, the server runs with no auth at all
(fine for local stdio testing on your own machine, not for anything
reachable by other people).
Transport: this uses Streamable HTTP (transport="http"), the current
MCP standard for remote servers — SSE is deprecated as of the 2025-11-25
MCP spec revision.
Deploying for free (Render) so claude.ai (web) can reach it
claude.ai connects to remote MCP servers from Anthropic's cloud, not
from your browser — so this needs a real public HTTPS URL. Local
network / VPN-only hosting won't work for the web client (Claude
Desktop's local stdio config is different and stays working as-is).
Render gives you that for free, with auto-deploy
on every git push.
1. Push this project to a GitHub repo
git init
git add .
git commit -m "Anvaya Universal Database MCP"
git remote add origin https://github.com/YOUR_USERNAME/anvaya-labs-mcp.git
git push -u origin main
2. Create the Render service
- Go to render.com → sign up (no credit card needed for the free tier) → New → Web Service
- Connect your GitHub repo
- Settings:
- Runtime: Python 3
- Build Command:
pip install -r requirements.txt - Start Command:
python server.py - Instance Type: Free
3. Add environment variables (Render dashboard → Environment)
ANVAYA_JWT_SECRET=<your generated secret>
ANVAYA_MCP_TRANSPORT=http
ANVAYA_DEFAULT_DB_URI=sqlite:///test.db
(test.db is committed in this repo as a small demo database — Render's
free tier has no persistent disk, so a database that's part of the
codebase is what survives redeploys. For real data, point
ANVAYA_DEFAULT_DB_URI at an externally hosted database instead —
e.g. a free Postgres from Neon — rather than SQLite.)
4. Deploy
Render builds and deploys automatically. You'll get a URL like
https://anvaya-labs-mcp.onrender.com. Every future git push to
this repo redeploys automatically — no extra steps needed.
Two honest limitations of the free tier:
- The service sleeps after 15 minutes of no traffic, and the first request after that takes 30-50 seconds to wake up — the very first tool call after idling may feel slow or briefly time out.
- No persistent disk, as noted above — anything written to disk at runtime disappears on the next restart or deploy.
5. Issue a token and add the connector in claude.ai
uv run python issue_token.py --name alice --role analyst --tenant acme
Then in claude.ai: Settings → Connectors → Add custom connector
- URL:
https://anvaya-labs-mcp.onrender.com/mcp - Open Request headers (this is a beta feature — if you don't see it, it may not be rolled out to your account yet)
- Header name:
authorization - Header value:
Bearer <the token you issued>
Setup
uv sync
uv run anvaya-mcp
The 4 tools
get_database_schema(db_uri, role)execute_safe_query(db_uri, sql_query, role, tenant_id)explain_sql_query(db_uri, sql_query)export_results_format(db_uri, sql_query, role, format_type, tenant_id)
Roles
Defined in config.py under ROLE_PERMISSIONS: admin, analyst,
support, readonly_guest. Edit that dictionary to add roles, change
which tables/columns they can see, or turn tenant filtering on/off.
What got simplified from the first version
- Sync database calls instead of async (easier to read top-to-bottom)
- No decorators, dataclasses, or Enums — just dicts and functions
- Row-level tenant filtering only supports a single
tenant_idcolumn (not multiple candidate column names) - Masking is column-name-based only (no scanning cell contents for patterns like card numbers)
Connections and schema are cached (see db_engine.py — ENGINE_CACHE
and SCHEMA_CACHE, two plain dictionaries), so repeated calls reuse the
same connection instead of opening a new one every time, and don't
re-fetch the schema on every call. The schema cache refreshes itself
every 5 minutes, or immediately if you pass force_refresh=True.
Everything from your original feature list is still here — schema discovery, relationship mapping, read-only enforcement, EXPLAIN, table/column RBAC, row-level filtering, data masking, CSV/Excel/JSON export, and audit logging — just written as plainly as possible.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。