Self-Documenting Zero-Knowledge MCP Server
This MCP server autonomously introspects SQLite databases to auto-generate CRUD tools and join prompts, while enforcing zero-knowledge security through pre-validated SQL templates.
README
Self-Documenting Zero-Knowledge MCP Server
A Model Context Protocol (MCP) server that autonomously scans an undocumented legacy database, generates CRUD tools for every table, creates prompts explaining how to join tables, and enforces Zero-Knowledge security by restricting the LLM to pre-validated SQL templates only.
Architecture

Why MCP — and What the Real Engineering Is
MCP (Model Context Protocol) is the transport and interface layer here — it handles how the LLM calls tools, passes parameters, and receives results. It is a deliberate choice, not the achievement.
The actual engineering in this project is the schema-introspection and security pipeline that sits underneath:
Database → PRAGMA Introspection → Schema Registry → Template Engine → Security Validator → MCP Tools
Each stage has zero knowledge of the next. The introspector knows nothing about MCP. The template engine knows nothing about security. The CRUD generator knows nothing about SQL — it only works with template IDs. This strict separation means you could swap the MCP transport for a REST API or a gRPC service without touching a single line of the security layer.
MCP was chosen over direct OpenAI function-calling because MCP is transport-agnostic (stdio for local use, SSE for network), supports resources and prompts beyond raw tool calls, and is the open standard being adopted across the LLM tooling ecosystem. But the security layer — pre-validated templates, defense-in-depth sanitization, immutable template registry — works identically regardless of what protocol sits in front of it.
Features
- Autonomous Schema Discovery — Scans any SQLite database using PRAGMA introspection with zero prior knowledge
- Dynamic CRUD Tools — Auto-generates Create, Read, Update, Delete, List, and Search tools for every discovered table
- Join Prompts — Analyzes foreign key relationships and generates prompts explaining how to join tables
- Zero-Knowledge Security — All SQL execution is restricted to pre-validated parameterized templates
- Audit Logging — Every database operation is logged with timestamp, template ID, and parameters
- Schema Resources — MCP resources expose the discovered schema for LLM reference
Quick Start
Prerequisites
- Python 3.10+
- pip
Installation
# Clone the repository
git clone https://github.com/shubhtiwari65/Self-Documenting-Zero-Knowledge-MCP-Server.git
cd "MCP SERVER"
# Install dependencies
pip install -r requirements.txt
# Or install in editable mode with dev tools (recommended)
pip install -e ".[dev]"
Seed the Demo Database
# Create a sample e-commerce legacy database
python server.py --seed
This creates legacy_store.db with 6 tables: categories, customers, orders, order_items, products, reviews — complete with foreign key relationships and sample data.
Run the Server
# Run with stdio transport (default — for Claude Desktop)
python server.py
# Run with SSE transport (for network access)
python server.py --transport sse --port 8080
# Use a custom database
python server.py --db /path/to/your/database.db
Connect with Claude Desktop
Add to your Claude Desktop config (claude_desktop_config.json):
{
"mcpServers": {
"zk-database": {
"command": "python",
"args": ["C:/path/to/MCP SERVER/server.py", "--db", "C:/path/to/legacy_store.db"]
}
}
}
Test with MCP Inspector
mcp dev server.py
What Gets Generated
When the server starts, it introspects the database and auto-generates:
Tools (per table)
| Tool | Description |
|---|---|
create_{table} |
Insert a new row with auto-generated parameter docs |
read_{table} |
Read a row by primary key |
update_{table} |
Update a row by primary key |
delete_{table} |
Delete a row by primary key |
list_{table} |
Paginated listing with limit/offset |
search_{table} |
Full-text search across text columns |
Prompts
| Prompt | Description |
|---|---|
join_{table_a}_and_{table_b} |
Explains how to join two related tables |
explore_database |
Complete database exploration guide |
show_schema |
Full auto-discovered schema display |
Resources
| Resource URI | Description |
|---|---|
schema://tables |
Full schema overview |
schema://tables/{name} |
Per-table schema details |
security://audit-log |
Recent query audit log |
security://report |
Security summary report |
security://templates |
All registered SQL templates |
Security Model
The Zero-Knowledge security model ensures the LLM never constructs or sees raw SQL:
- Template-Only Execution — Only SQL from the pre-generated template registry can be executed. No raw SQL endpoint exists.
- Parameter Validation — All parameters are type-checked against the introspected schema before execution.
- Input Sanitization — Defense-in-depth blocklist catches SQL injection patterns in parameter values (even though parameterized queries already prevent injection).
- Audit Trail — Every operation is logged with timestamp, template ID, parameters, success/failure status.
- No Schema Manipulation — Only SELECT, INSERT, UPDATE, DELETE on existing tables. No DDL operations are possible.
See SECURITY.md for the full security model, including known scope boundaries (transport-layer auth).
Why SQLite — and What Changes at Scale
SQLite was chosen deliberately for this demo for three reasons:
- Zero configuration — no separate server, credentials, or network config; the DB is a single file
- Native PRAGMA introspection —
PRAGMA table_info(),PRAGMA foreign_key_list()are the exact tools the zero-knowledge discovery depends on - stdlib only — no ORM dependency;
import sqlite3ships with Python
What would change in production:
| Concern | Current (SQLite) | Production path |
|---|---|---|
| Concurrency | Single-writer | PostgreSQL + asyncpg + connection pool |
| Introspection | PRAGMA statements | information_schema (standard SQL, DB-agnostic) |
| Audit log | In-memory list | Append-only DB table or structured JSON logs |
| DB path config | CLI flag | DATABASE_URL env var (12-factor) |
| Migrations | Re-seed | alembic migration scripts |
The architecture is database-agnostic by design — only src/introspector.py contains SQLite-specific code (~80 lines). Swapping the backing database means replacing that single file; the security layer, CRUD generator, and MCP registration are untouched.
See docs/DECISIONS.md for all architectural decision records.
Running Tests
# Run all tests
python -m pytest
# Run with coverage report
python -m pytest --cov=src --cov-report=term-missing
# Run specific test files
python -m pytest tests/test_security.py -v
python -m pytest tests/test_introspector.py -v
Project Structure
MCP SERVER/
├── .github/workflows/ci.yml # CI pipeline (pytest + ruff + coverage)
├── .gitignore # Git ignore rules
├── .env.example # Environment variable template
├── CHANGELOG.md # Version history
├── CONTRIBUTING.md # Dev setup and contribution guide
├── Makefile # Developer convenience commands
├── README.md # Project documentation
├── SECURITY.md # Security model + transport scope boundary
├── server.py # Main MCP server entry point
├── requirements.txt # Python dependencies
├── pyproject.toml # Project metadata, ruff + pytest + coverage config
├── src/
│ ├── __init__.py
│ ├── introspector.py # PRAGMA-based schema discovery
│ ├── schema_registry.py # In-memory schema registry
│ ├── sql_templates.py # Pre-validated SQL template engine
│ ├── security.py # Zero-Knowledge security validator
│ ├── crud_generator.py # Dynamic MCP tool generator
│ └── join_analyzer.py # FK analysis & prompt generator
├── sample_data/
│ └── seed_legacy_db.py # Demo legacy database seeder
├── tests/
│ ├── conftest.py # Shared pytest fixtures
│ ├── demo_client.py # Standalone verification demo
│ ├── test_introspector.py # Schema discovery tests
│ ├── test_crud.py # CRUD operation tests
│ ├── test_security.py # Security validation tests
│ └── test_joins.py # Join analysis tests
└── docs/
├── APPROACH.md # Full technical approach write-up
├── DECISIONS.md # Architectural Decision Records (ADRs)
└── MCP_architecture.png # Architecture diagram
License
MIT
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。