SD

souhar-dya/mcp-db-server

数据库管理

本页由 AI 翻译,技术细节请以原文为准。 查看原文

19 stars 14 forks 质量 69 趋势 30NOASSERTION

MCP Database Server with natural language SQL queries

概览

An MCP (Model Context Protocol) server that exposes relational databases (PostgreSQL/MySQL) to AI agents with natural language query support. Transform natural language questions into SQL queries and get structured results. - : Works with PostgreSQL and MySQL - : Convert plain English queries to SQL using HuggingFace transformers - : Clean FastAPI-based endpoints for database operations - : Read-only operations with query validation and result limits - : Complete containerization with Docker Compose - : Health checks, logging, and error handling - : Designed specifically for AI agent integration - Added mandatory X-API-Key authentication for all database HTTP endpoints; /health remains public for health checks. - Removed unrestricted credentialed CORS and made allowed origins explicitly configurable. - Changed the default HTTP bind address to 127.0.0.1. - Added table-name validation against existing database tables to block SQL injection through table routes.

README

以下为原文 README 节选,完整内容请查看原文。

mcp-db-server

An MCP (Model Context Protocol) server that exposes relational databases (PostgreSQL/MySQL) to AI agents with natural language query support. Transform natural language questions into SQL queries and get structured results.

Features

  • Multi-Database Support: Works with PostgreSQL and MySQL
  • Natural Language to SQL: Convert plain English queries to SQL using HuggingFace transformers
  • RESTful API: Clean FastAPI-based endpoints for database operations
  • Safety First: Read-only operations with query validation and result limits
  • Docker Ready: Complete containerization with Docker Compose
  • Production Ready: Health checks, logging, and error handling
  • AI Agent Friendly: Designed specifically for AI agent integration

Version 1.4.0 Changes

  • Added mandatory X-API-Key authentication for all database HTTP endpoints; /health remains public for health checks.
  • Removed unrestricted credentialed CORS and made allowed origins explicitly configurable.
  • Changed the default HTTP bind address to 127.0.0.1.
  • Added table-name validation against existing database tables to block SQL injection through table routes.
  • Added PostgreSQL sslmode=require compatibility for asyncpg connections.
  • Updated Docker Compose, environment examples, and documentation for secure API-key configuration.
  • Published Docker images:
    • souhardyak/mcp-db-server:1.4.0
    • souhardyak/mcp-db-server:latest
  • Added GitHub Container Registry publishing for:
    • ghcr.io/souhar-dya/mcp-db-server:1.4.0
    • ghcr.io/souhar-dya/mcp-db-server:latest

API Endpoints

Endpoint Method Description
/health GET Health check and service status
/mcp/list_tables GET List all available tables with column counts
/mcp/describe/{table_name} GET Get detailed schema for a specific table
/mcp/query POST Execute natural language queries
/mcp/tables/{table_name}/sample GET Get sample data from a table

Quick Start

  1. Clone and start the services:

    git clone https://github.com/Souhar-dya/mcp-db-server.git
    cd mcp-db-server
    export MCP_API_KEY="$(openssl rand -hex 32)"
    docker-compose up --build
    
  2. Test the endpoints:

在 GitHub 查看完整 README

安装

docker run --rm -i -e DATABASE_URL=sqlite+aiosqlite:////data/default.db souhardyak/mcp-db-server:1.3.1
新手?先看 mcpskill.org 教程 →