chicks2014/mcp-sql-server
3.2
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.
šŗ Watch the Tutorial
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
.env
file)
Installation
-
Clone the repository.
-
Navigate to the project directory:
cd mcp-sql-server
-
Install dependencies using uv:
uv sync
-
Create a
.env
file 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.py
file defines an MCP server with aquery_data
tool to execute SQL queries. - The
mcp_client.py
file uses the Anthropic Claude 3 Sonnet model to generate SQL queries from natural language input. - The
chinook.db
file 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.