Generic SQL MCP Server

Generic SQL MCP Server

A configurable, database-agnostic MCP server that enables LLMs to safely interact with SQL databases through read-only operations and schema inspection.

Category
访问服务器

README

Generic SQL MCP Server

A configurable, database-agnostic Model Context Protocol (MCP) server that enables Large Language Models (LLMs) to safely interact with SQL databases.


Overview

This project is a Proof of Concept (POC) that demonstrates how a Model Context Protocol (MCP) server can securely expose SQL database capabilities to AI assistants while maintaining a clean and configurable architecture.

Rather than connecting directly to a production database, this project uses a local demonstration database to validate the overall architecture. The design allows the same MCP server to connect to different SQL databases simply by changing configuration files, without modifying application code.

The project serves as a foundation for future integration with enterprise databases such as ERP systems.


Objectives

The primary objectives of this project are:

  • Demonstrate how an MCP server communicates with SQL databases.
  • Support multiple SQL database engines through configuration.
  • Keep the implementation database-agnostic.
  • Expose generic database capabilities to LLMs.
  • Allow only safe, read-only SQL operations.
  • Build a modular and extensible architecture.

Features

  • Configurable database connections
  • SQLite, MySQL and PostgreSQL support
  • Generic SQL database tools
  • Read-only SQL execution
  • SQL validation layer
  • Modular architecture
  • Configuration-driven design
  • Logging and error handling
  • MCP-compliant implementation

Project Architecture

                 User

                   │

                   ▼

            MCP Client
      (Claude Desktop, etc.)

                   │

                   ▼

              MCP Server

                   │

             MCP Tools

                   │

          Database Service

                   │

         Database Adapter

                   │

             SQLAlchemy

                   │

              SQL Database

Project Structure

sql-mcp-server/

├── CLAUDE.md
├── README.md
├── requirements.md
├── architecture.md
├── tasks.md
│
├── app/
│   ├── server.py
│   ├── config.py
│   ├── database/
│   ├── tools/
│   ├── security/
│   └── utils/
│
├── configs/
│   ├── sqlite.yaml
│   ├── mysql.yaml
│   └── postgres.yaml
│
├── demo_db/
│   ├── schema.sql
│   ├── seed.sql
│   └── school.db
│
├── tests/
│
├── requirements.txt
│
└── .env.example

Supported Databases

Database Status
SQLite ✅ Supported
MySQL ✅ Supported
PostgreSQL ✅ Supported

SQLite is used as the primary demonstration database.


Supported MCP Capabilities

The MCP server provides generic database functionality rather than business-specific operations.

Examples include:

  • List available tables
  • Inspect table schemas
  • Execute read-only SQL queries
  • Retrieve database metadata

This allows the server to work with virtually any SQL database.


Security

The server operates in read-only mode.

Allowed SQL:

  • SELECT

Blocked SQL:

  • INSERT
  • UPDATE
  • DELETE
  • DROP
  • ALTER
  • CREATE
  • TRUNCATE

Every SQL statement is validated before execution.


Technology Stack

Language

  • Python 3.12+

Core Libraries

  • Official Python MCP SDK
  • SQLAlchemy
  • Pydantic
  • PyYAML
  • python-dotenv

Database Drivers

  • SQLite
  • PyMySQL
  • psycopg2-binary

Getting Started

1. Clone the Repository

git clone <repository-url>
cd sql-mcp-server

2. Create a Virtual Environment

python -m venv .venv

Activate it.

Windows

.venv\Scripts\activate

Linux / macOS

source .venv/bin/activate

3. Install Dependencies

pip install -r requirements.txt

4. Configure the Database

Choose one configuration from the configs/ directory.

Example:

database:
  type: sqlite
  database: demo_db/school.db

5. Start the MCP Server

python app/server.py

6. Connect an MCP Client

Connect the server using any MCP-compatible client such as:

  • Claude Desktop
  • Claude Code
  • MCP Inspector
  • Other MCP-compatible clients

Demonstration

Example interactions:

List all tables.

Describe the students table.

Show all records from teachers.

Find students older than 15.

Show the schema of attendance.

Future Improvements

Possible future enhancements include:

  • Authentication
  • Role-based authorization
  • Query auditing
  • Connection pooling
  • Dynamic tool generation
  • Enterprise ERP integration
  • Production deployment
  • Multi-database connections
  • Advanced SQL validation

Documentation

Additional project documentation:

  • CLAUDE.md — Instructions and development guidelines for Claude Code
  • requirements.md — Functional requirements
  • architecture.md — Technical architecture
  • tasks.md — Development roadmap

Project Status

Current Status

🚧 Proof of Concept (POC)

The project is under active development and is intended to validate the feasibility of using MCP as a secure interface between LLMs and SQL databases.


License

This project is intended for internal evaluation and demonstration purposes.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选
mcp-server-qdrant

mcp-server-qdrant

这个仓库展示了如何为向量搜索引擎 Qdrant 创建一个 MCP (Managed Control Plane) 服务器的示例。

官方
精选