The Legion Database MCP Server is a powerful tool designed to facilitate access and querying of databases using the Legion Query Runner. It integrates with the Model Context Protocol (MCP) Python SDK, enabling AI assistants to interact with databases seamlessly. This server exposes database operations as MCP resources, tools, and prompts, providing a flexible and efficient way to manage database interactions.
The Model Context Protocol (MCP) is a specification for maintaining context in AI applications. The Legion Database MCP Server uses the MCP Python SDK to:
When using uv
, no specific installation is needed. Use uvx
to directly run database-mcp.
Alternatively, install database-mcp
via pip:
pip install database-mcp
{
"mcpServers": {
"database-mcp": {
"command": "uvx",
"args": [\
"database-mcp"\
],
"env": {
"DB_TYPE": "pg",
"DB_CONFIG": "{\"host\":\"localhost\",\"port\":5432,\"user\":\"user\",\"password\":\"pw\",\"dbname\":\"dbname\"}"
},
"disabled": true,
"autoApprove": []
}
}
}
{
"mcpServers": {
"database": {
"command": "python",
"args": [\
"-m", "database_mcp", \
"--repository", "path/to/git/repo"\
],
"env": {
"DB_TYPE": "pg",
"DB_CONFIG": "{\"host\":\"localhost\",\"port\":5432,\"user\":\"user\",\"password\":\"pw\",\"dbname\":\"dbname\"}"
},
}
}
To run the server in development mode:
mcp dev mcp_server.py
For production mode:
python mcp_server.py
Run tests with:
uv pip install -e ".[dev]"
pytest
rm -rf dist/ build/ *.egg-info/ && python -m build
python -m build
python -m twine upload dist/*
Configure the database connection using environment variables:
export DB_TYPE="pg" # or mysql, postgresql, etc.
export DB_CONFIG='{"host":"localhost","port":5432,"user":"username","password":"password","dbname":"database_name"}'
mcp dev mcp_server.py
For direct execution, use command line arguments:
python mcp_server.py --db-type pg --db-config '{"host":"localhost","port":5432,"user":"username","password":"password","dbname":"database_name"}'
or
uv mcp_server.py --db-type pg --db-config '{"host":"localhost","port":5432,"user":"username","password":"password","dbname":"database_name"}'
schema://all
- Get the complete database schemaexecute_query
- Execute a SQL query and return results as a markdown tableexecute_query_json
- Execute a SQL query and return results as JSONget_table_columns
- Get column names for a specific tableget_table_types
- Get column types for a specific tableget_query_history
- Get the recent query historysql_query
- Create an SQL query against the databaseexplain_query
- Explain what a SQL query doesoptimize_query
- Optimize a SQL query for better performanceRun tests:
pytest
This repository is licensed under GPL.
No description, website, or topics provided.
No packages published