Skip to main content
Glama
lavishshakya

Self-Documenting Zero-Knowledge MCP Server

by lavishshakya

自己文書化ゼロ知識MCPサーバー

CI Python FastMCP License Security

Model Context Protocol (MCP) サーバー。文書化されていないレガシーデータベースを自律的にスキャンし、すべてのテーブルに対してCRUDツールを生成し、テーブルの結合方法を説明するプロンプトを作成し、LLMを事前検証済みのSQLテンプレートのみに制限することでゼロ知識セキュリティを適用します。

アーキテクチャ

アーキテクチャ図

Related MCP server: sqlite-mcp

MCPを選ぶ理由 — そして実際のエンジニアリングとは何か

MCP(Model Context Protocol)は、ここでのトランスポートおよびインターフェース層です。LLMがツールを呼び出し、パラメータを渡し、結果を受け取る方法を処理します。これは意図的な選択であり、成果そのものではありません。

このプロジェクトの実際のエンジニアリングは、その下に位置するスキーマ内省およびセキュリティパイプラインです。

Database → PRAGMA Introspection → Schema Registry → Template Engine → Security Validator → MCP Tools

各段階は次の段階についてゼロ知識です。イントロスペクタはMCPについて何も知りません。テンプレートエンジンはセキュリティについて何も知りません。CRUDジェネレータはSQLについて何も知りません — テンプレートIDを扱うだけです。この厳格な分離により、セキュリティ層のコードを一行も変更することなく、MCPトランスポートをREST APIやgRPCサービスに置き換えることができます。

MCPは、直接のOpenAI関数呼び出しではなく、MCPがトランスポート非依存(ローカル使用にはstdio、ネットワークにはSSE)であり、生のツール呼び出しを超えたリソースとプロンプトをサポートし、LLMツールエコシステム全体で採用されているオープン標準であるため、選択されました。しかし、セキュリティ層 — 事前検証済みテンプレート、多層防御サニタイズ、不変テンプレートレジストリ — は、前面にどのプロトコルが置かれても同じように機能します。

機能

  • 自律的スキーマ発見 — 事前知識ゼロでPRAGMA内省を使用して任意のSQLiteデータベースをスキャン

  • 動的CRUDツール — 発見されたすべてのテーブルに対してCreate、Read、Update、Delete、List、Searchツールを自動生成

  • 結合プロンプト — 外部キー関係を分析し、テーブルの結合方法を説明するプロンプトを生成

  • ゼロ知識セキュリティ — すべてのSQL実行は事前検証済みのパラメータ化テンプレートに制限

  • 監査ログ — すべてのデータベース操作はタイムスタンプ、テンプレートID、パラメータとともに記録

  • スキーマリソース — MCPリソースが発見されたスキーマをLLM参照用に公開

クイックスタート

前提条件

  • Python 3.10以上

  • pip

インストール

# 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]"

デモデータベースのシード

# Create a sample e-commerce legacy database
python server.py --seed

これにより、legacy_store.db が6つのテーブル(categoriescustomersordersorder_itemsproductsreviews)で作成されます — 外部キー関係とサンプルデータ付きです。

サーバーの実行

# 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

Claude Desktopへの接続

Claude Desktopの設定(claude_desktop_config.json)に追加します:

{
  "mcpServers": {
    "zk-database": {
      "command": "python",
      "args": ["C:/path/to/MCP SERVER/server.py", "--db", "C:/path/to/legacy_store.db"]
    }
  }
}

MCP Inspectorでのテスト

mcp dev server.py

生成されるもの

サーバーが起動すると、データベースを内省し、以下を自動生成します:

ツール(テーブルごと)

ツール

説明

create_{table}

自動生成されたパラメータドキュメント付きで新しい行を挿入

read_{table}

主キーで行を読み取り

update_{table}

主キーで行を更新

delete_{table}

主キーで行を削除

list_{table}

limit/offset付きのページネーション一覧

search_{table}

テキスト列全体の全文検索

プロンプト

プロンプト

説明

join_{table_a}_and_{table_b}

2つの関連テーブルの結合方法を説明

explore_database

完全なデータベース探索ガイド

show_schema

自動発見された完全なスキーマ表示

リソース

リソースURI

説明

schema://tables

完全なスキーマ概要

schema://tables/{name}

テーブルごとのスキーマ詳細

security://audit-log

最近のクエリ監査ログ

security://report

セキュリティ概要レポート

security://templates

登録済みの全SQLテンプレート

セキュリティモデル

ゼロ知識セキュリティモデルにより、LLMが生のSQLを構築したり参照したりすることは決してありません:

  1. テンプレートのみの実行 — 事前生成されたテンプレートレジストリのSQLのみが実行可能。生のSQLエンドポイントは存在しません。

  2. パラメータ検証 — すべてのパラメータは実行前に内省されたスキーマに対して型チェックされます。

  3. 入力サニタイズ — 多層防御ブロックリストがパラメータ値のSQLインジェクションパターンを捕捉します(パラメータ化クエリがすでにインジェクションを防いでいるにもかかわらず)。

  4. 監査証跡 — すべての操作はタイムスタンプ、テンプレートID、パラメータ、成功/失敗ステータスとともに記録されます。

  5. スキーマ操作なし — 既存テーブルに対するSELECT、INSERT、UPDATE、DELETEのみ。DDL操作は一切不可能です。

完全なセキュリティモデル(既知のスコープ境界(トランスポート層認証)を含む)については、SECURITY.mdを参照してください。

SQLiteを選ぶ理由 — そしてスケール時の変更点

SQLiteはこのデモのために意図的に選択されました。理由は3つあります:

  1. ゼロ設定 — 別個のサーバー、認証情報、ネットワーク設定が不要。DBは単一ファイル

  2. ネイティブPRAGMA内省PRAGMA table_info()PRAGMA foreign_key_list() はゼロ知識発見が依存するまさにそのツール

  3. 標準ライブラリのみ — ORM依存なし。import sqlite3 はPythonに同梱

本番環境での変更点:

関心事

現在(SQLite)

本番パス

並行性

単一ライター

PostgreSQL + asyncpg + コネクションプール

内省

PRAGMAステートメント

information_schema(標準SQL、DB非依存)

監査ログ

インメモリリスト

追記専用DBテーブルまたは構造化JSONログ

DBパス設定

CLIフラグ

DATABASE_URL 環境変数(12ファクター)

マイグレーション

再シード

alembic マイグレーションスクリプト

アーキテクチャは設計上データベース非依存です — SQLite固有のコードを含むのは src/introspector.py のみです(約80行)。バッキングデータベースの交換はその単一ファイルの置き換えを意味します。セキュリティ層、CRUDジェネレータ、MCP登録は変更されません。

すべてのアーキテクチャ決定記録については、docs/DECISIONS.mdを参照してください。

テストの実行

# 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

プロジェクト構造

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

ライセンス

MIT

A
license - permissive license
Not graded
quality - not tested
B
maintenance

Maintenance

Maintainers
Response time
Release cycle
Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

  • F
    license
    Not graded
    quality
    D
    maintenance
    An MCP server that enables AI assistants to query and interact with SQLite databases through natural language. It includes built-in security guardrails such as PII redaction, SQL injection blocking, and query rate limiting.
  • A
    license
    Not graded
    quality
    C
    maintenance
    An MCP server that enables AI agents to interact with SQLite databases by querying schemas, executing SQL, and inspecting table metadata. It supports safe database access through configurable read-only modes, query timeouts, and dry-run execution plans.
    MIT
  • A
    license
    A
    quality
    D
    maintenance
    A zero-config MCP server that enables AI to access, analyze, and manage local SQLite databases with secure read-only querying and automatic schema discovery.
    8
    MIT
  • A
    license
    C
    quality
    A
    maintenance
    An MCP server for interacting with SQLite databases, enabling SQL query execution, schema inspection, and CRUD operations.
    7
    MIT

View all related MCP servers

Related MCP Connectors

  • MCP server for secureFlows: token-free URL builders and integration-linting tools for AI agents.

  • GibsonAI MCP server: manage your databases with natural language

  • Markdown-first MCP server for Notion API with 8 composite tools and 39 actions.

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/lavishshakya/Self-Documenting-Zero-Knowledge-MCP-Server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server