ytyng/sql-agent-mcp-server
If you are the rightful owner of sql-agent-mcp-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.
The SQL Agent MCP Server is a versatile server designed to connect to MySQL and PostgreSQL databases, allowing for efficient query execution and database management.
sql_query
Execute SQL queries.
get_server_list
Get a list of registered servers.
get_table_list
Get a list of tables for the specified server.
get_table_schema
Get schema information for a table.
get_mysql_status
Get status information for MySQL servers.
get_mysql_variables
Get variable information for MySQL servers.
get_mysql_processlist
Get process list for MySQL servers.
get_mysql_databases
Get database list for MySQL servers.
get_mysql_table_status
Get table status for MySQL servers.
get_mysql_indexes
Get index information for MySQL servers.
analyze_mysql_table
Analyze table for MySQL servers.
optimize_mysql_table
Optimize table for MySQL servers.
check_mysql_table
Check table for MySQL servers.
repair_mysql_table
Repair table for MySQL servers.
SQL Agent MCP Server
An MCP server that connects to MySQL and PostgreSQL databases to execute queries.
Features
- Connection management for multiple database servers
- Support for both MySQL and PostgreSQL
- SSH tunnel connection support
- Retrieve table lists and schema information
- Execute SQL queries
- MySQL-specific administrative commands
Installation
# Install dependencies
uv sync
Configuration
Create a config.yaml
file to configure database server connection information.
mysql_servers:
- name: my-postgres
description: "PostgreSQL server"
engine: postgres
host: localhost
port: 5432
schema: mydb
user: postgres
password: password
- name: my-mysql
description: "MySQL server"
engine: mysql
host: localhost
port: 3306
schema: mydb
user: root
password: password
Connection via SSH Tunnel
You can securely connect to remote databases using SSH tunnels.
mysql_servers:
- name: remote-db
description: "Remote database via SSH tunnel"
engine: postgres
host: localhost # Use localhost for SSH tunnel connections
port: 5432
schema: remote_db
user: db_user
password: db_password
ssh_tunnel:
host: ssh.example.com
port: 22
user: ssh_user
# For password authentication
password: ssh_password
# Or for private key authentication
# private_key_path: ~/.ssh/id_rsa
# private_key_passphrase: key_passphrase # If passphrase is required
Usage
Starting the MCP Server
# Using startup script (recommended)
./launch-mcp-server.sh
# Or start directly
source .venv/bin/activate
python mcp_server.py
Available Tools
1. sql_query
Execute SQL queries.
Parameters:
- server_name: Server name
- sql: SQL query to execute
2. get_server_list
Get a list of registered servers.
3. get_table_list
Get a list of tables for the specified server.
Parameters:
- server_name: Server name
4. get_table_schema
Get schema information for a table.
Parameters:
- server_name: Server name
- table_name: Table name
MySQL-Specific Tools
Administrative tools that can only be used with MySQL servers.
get_mysql_status
: Get status informationget_mysql_variables
: Get variable informationget_mysql_processlist
: Get process listget_mysql_databases
: Get database listget_mysql_table_status
: Get table statusget_mysql_indexes
: Get index informationanalyze_mysql_table
: Analyze tableoptimize_mysql_table
: Optimize tablecheck_mysql_table
: Check tablerepair_mysql_table
: Repair table
Testing
The test-requests/
directory contains test scripts for the MCP server.
Test Library
test_mcp_lib.py
: Common library for communicating with MCP servertest_list_tools.py
: Test to get list of available toolstest_mangazenkan_dev.py
: Test for SQL execution against actual database
# Test to get tool list
python3 test-requests/test_list_tools.py
# SQL execution test
python3 test-requests/test_mangazenkan_dev.py
Logging
- Application logs are output to
/tmp/sql-agent-mcp-server.log
- Configured to prevent logs from being output to stdout for MCP communication
Security Considerations
config.yaml
contains database passwords, so manage it appropriately- When using SSH private keys, set appropriate file permissions
- Consider using environment variables or secret management tools in production environments
License
This project is licensed under the MIT License - see the file for details.
Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request