chicks2014/mcp-sql-server
3.1
If you are the rightful owner of mcp-sql-server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
This project involves building an AI SQL agent using Model Context Protocol (MCP) to interact with a SQLite database through natural language.
Tools
1
Resources
0
Prompts
0
Introduction to MCP with SQL Agent
Build an AI SQL agent using MCP to interact with a SQLite database through natural language.
Key Features
- Create an AI SQL agent using MCP.
- Interact with a SQLite database using natural language.
- Use Claude 3 Sonnet to generate SQL queries.
- Execute SQL queries safely.
- Learn how to use MCP to build AI tools.
Tech Stack
- Anthropic
- Loguru
- MCP
- Python-dotenv
- Rich
- SQLite
Getting Started
Prerequisites
- Python 3.12+
- uv
- An Anthropic API key (set in
.envfile)
Installation
-
Clone the repository.
-
Navigate to the project directory:
cd mcp-sql-server -
Install dependencies using uv:
uv sync -
Create a
.envfile with your Anthropic API key:ANTHROPIC_API_KEY=sk-ant-api03-YOUR_API_KEY
Usage
- Run the MCP client:
uv run mcp_client.py - Enter your SQL queries in natural language.
Note that you don't need to explicitly run the server, as the client automatically runs it.
Project Structure
mcp-sql-server/
├── README.md # Project documentation
├── mcp_client.py # MCP client script
├── mcp_server.py # MCP server script
├── database.db # SQLite database
├── pyproject.toml # Project dependencies
├── .env # Environment variables
├── .gitignore # Git ignore file
├── .python-version # Python version
├── layout.zellij # Zellij layout for development
├── code.zellij # Zellij layout for code editing
└── demo.zellij # Zellij layout for demo
Implementation Details
- The
mcp_server.pyfile defines an MCP server with aquery_datatool to execute SQL queries. - The
mcp_client.pyfile uses the Anthropic Claude 3 Sonnet model to generate SQL queries from natural language input. - The
chinook.dbfile is a SQLite database used for the demo. - Zellij layouts are provided for development and demo purposes.
Contributing
- Fork the repository.
- Create your feature branch.
- Submit a pull request.
License
MIT License - See file for details.