mcp-sql-server: A SQL MCP Server
Overview
A Model Context Protocol (MCP) server for interacting with SQL databases. This server provides tools to query and retrieve schema information from a SQL database via Large Language Models (LLMs). It's designed to be used with LLM-powered tools and applications that need to access and understand SQL data.
Please note that mcp-sql-server is currently in early development. The functionality and available tools are subject to change and expansion as we continue to develop and improve the server.
Tools
-
read_query- Description: Executes a
SELECTquery on the SQL database. - Input:
query(string): A validSELECTSQL query to execute.
- Returns: The results of the query as a list of dictionaries, where each dictionary represents a row and the keys are the column names.
- Restrictions: Only
SELECTqueries are allowed. Other SQL commands (e.g.,INSERT,UPDATE,DELETE) are not supported.
- Description: Executes a
-
get_schema- Description: Retrieves the schema information for the database.
- Input: None.
- Returns: A JSON string representing the database schema. The schema includes table names, column names, data types, and other column properties.
Installation
Using uv (recommended)
When using uv no specific installation is needed. We will
use uvx to directly run mcp-sql-server.
Using PIP
Alternatively, you can install mcp-sql-server via pip:
pip install mcp-sql-server
After installation, you can run it as a script using:
python -m mcp_sql_server --db-host <your_db_host> --db-user <your_db_user> --db-password <your_db_password> --db-database <your_db_name>
*Note: Replace <your_db_host>, <your_db_user>, <your_db_password>, and <your_db_name> with your actual database credentials.
Configuration
Usage with Claude Desktop
Add this to your claude_desktop_config.json:
"mcpServers": {
"sql": {
"command": "uvx",
"args": ["mcp-sql-server", "--db-host", "<your_db_host>", "--db-user", "<your_db_user>", "--db-password", "<your_db_password>", "--db-database", "<your_db_name>"]
}
}
- Note: replace '/Users/username' with the a path that you want to be accessible by this tool
"mcpServers": {
"sql": {
"command": "docker",
"args": ["run", "--rm", "-i", "--mount", "type=bind,src=/Users/username,dst=/Users/username", "mcp/sql", "--db-host", "<your_db_host>", "--db-user", "<your_db_user>", "--db-password", "<your_db_password>", "--db-database", "<your_db_name>"]
}
}
"mcpServers": {
"sql": {
"command": "python",
"args": ["-m", "mcp_sql_server", "--db-host", "<your_db_host>", "--db-user", "<your_db_user>", "--db-password", "<your_db_password>", "--db-database", "<your_db_name>"]
}
}
*Note: Replace <your_db_host>, <your_db_user>, <your_db_password>, and <your_db_name> with your actual database credentials.
Usage with Zed
Add to your Zed settings.json:
"context_servers": {
"mcp-sql-server": {
"command": {
"path": "uvx",
"args": ["mcp-sql-server", "--db-host", "<your_db_host>", "--db-user", "<your_db_user>", "--db-password", "<your_db_password>", "--db-database", "<your_db_name>"]
}
}
}
"context_servers": {
"mcp-sql-server": {
"command": {
"path": "python",
"args": ["-m", "mcp_sql_server", "--db-host", "<your_db_host>", "--db-user", "<your_db_user>", "--db-password", "<your_db_password>", "--db-database", "<your_db_name>"]
}
}
}
*Note: Replace <your_db_host>, <your_db_user>, <your_db_password>, and <your_db_name> with your actual database credentials.
Debugging
You can use the MCP inspector to debug the server. For uvx installations:
npx @modelcontextprotocol/inspector uvx mcp-sql-server --db-host <your_db_host> --db-user <your_db_user> --db-password <your_db_password> --db-database <your_db_name>
Or if you've installed the package in a specific directory or are developing on it:
cd path/to/project
npx @modelcontextprotocol/inspector uv run mcp-sql-server --db-host <your_db_host> --db-user <your_db_user> --db-password <your_db_password> --db-database <your_db_name>
Running tail -n 20 -f ~/Library/Logs/Claude/mcp*.log will show the logs from the server and may help you debug any issues.
Development
If you are doing local development, there are two ways to test your changes:
Run the MCP inspector to test your changes. See Debugging for run instructions.
Test using the Claude desktop app. Add the following to your claude_desktop_config.json:
Docker
{
"mcpServers": {
"sql": {
"command": "docker",
"args": [
"run",
"--rm",
"-i",
"--mount", "type=bind,src=/Users/username/Desktop,dst=/projects/Desktop",
"--mount", "type=bind,src=/path/to/other/allowed/dir,dst=/projects/other/allowed/dir,ro",
"--mount", "type=bind,src=/path/to/file.txt,dst=/projects/path/to/file.txt",
"mcp/sql",
"--db-host", "<your_db_host>",
"--db-user", "<your_db_user>",
"--db-password", "<your_db_password>",
"--db-database", "<your_db_name>"
]
}
}
}
UVX
{
"mcpServers": {
"sql": {
"command": "uv",
"args": [
"--directory",
"/<path to mcp-servers>/mcp-servers/src/sql",
"run",
"mcp-sql-server",
"--db-host", "<your_db_host>",
"--db-user", "<your_db_user>",
"--db-password", "<your_db_password>",
"--db-database", "<your_db_name>"
]
}
}
*Note: Replace <your_db_host>, <your_db_user>, <your_db_password>, and <your_db_name> with your actual database credentials.
Build
Docker build:
cd src/sql
docker build -t mcp/sql .
License
This MCP server is licensed under the MIT License. This means you are free to use, modify, and distribute the software, subject to the terms and conditions of the MIT License. For more details, please see the LICENSE file in the project repository.
Metadata
Release files for mcp-sql-server 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| mcp_sql_server-0.1.0.tar.gz | 7.3 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mcp_sql_server-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 15.3 kB
Release files / mcp_sql_server-0.1.0.tar.gz
| Download URL | mcp_sql_server-0.1.0.tar.gz |
|---|---|
| Size | 7.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
244a0acc872beee8b2fe82f2920c28f636941f5a2ac964f95d9992de742e2b79
|
|
BLAKE2b-256 checksum How to use checksums |
2a4cdfbe0f8a0571442c813658438fb29085a93a07c8f80fcd209c9389c5256b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.16
|
Release files / mcp_sql_server-0.1.0-py3-none-any.whl
| Download URL | mcp_sql_server-0.1.0-py3-none-any.whl |
|---|---|
| Size | 8.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
421b698ea090c54c487c3f4af336061fb02a6744e7ab5dfc38009f3e528c60b2
|
|
BLAKE2b-256 checksum How to use checksums |
6dafe4418f2fbe8a0d723fe15c705690084d89bd5e934a18266143564479bc7c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.16
|
Security for mcp-sql-server 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.