
This project provides a dynamic agent capable of connecting to multiple databases (PostgreSQL, MySQL, SQLite) and converting natural language text into SQL queries. It uses a configuration-driven approach to dynamically select and connect to the desired database.

- Dynamic Database Connectivity: Connect to different SQL databases on the fly based on configuration.
- Multi-DB Support: Out-of-the-box support for PostgreSQL, MySQL, and SQLite.
- Text-to-SQL: Leverages Google's Large Language Models to translate natural language questions into executable SQL queries.
- Configuration-driven: Easily configure database connections and tools via YAML and environment variables.
- Python 3.8+
- An active Google API Key with the necessary AI Platform APIs enabled.
- Google's MCP Toolbox
This guide walks you through installing and running the MCP Toolbox for Databases (an MCP server) on macOS and Windows, so you can connect your AI agents to enterprise data.
- A supported database (e.g., PostgreSQL, MYSQL, SQLite).
tools.yaml
configuration file defining your data sources and tools (This is generated on the fly within the app)curl
on macOS / Windows (via PowerShell) or Homebrew on macOS.
:contentReference[oaicite:0]{index=0}
export VERSION=0.11.0
export OS="darwin/amd64" # or "darwin/arm64"
curl -O https://storage.googleapis.com/genai-toolbox/v$VERSION/$OS/toolbox
chmod +x toolbox
OR
brew install mcp-toolbox
$env:VERSION="0.11.0"
$env:OS="windows/amd64"
Invoke-WebRequest "https://storage.googleapis.com/genai-toolbox/v$env:VERSION/$env:OS/toolbox.exe" -OutFile "toolbox.exe"
sources:
my-pg-source:
kind: postgres
host: 127.0.0.1
port: 5432
database: toolbox_db
user: toolbox_user
password: your-password
tools:
search-hotels-by-location:
kind: postgres-sql
source: my-pg-source
description: Finds hotels in a specific city.
parameters:
- name: location
type: string
description: City to search for hotels
statement: SELECT * FROM hotels WHERE location = $1;
./toolbox --tools-file "tools.yaml"
toolbox --tools-file "tools.yaml"
.\toolbox.exe --tools-file "tools.yaml"
-
Clone the repository:
git clone https://github.com/Squirry-AI/squirry-database-connector cd squirry-database-connector
-
Set up a virtual environment: It is highly recommended to create and activate a virtual environment.
python3 -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
-
Install dependencies:
pip install -r requirements.txt
(Note: A
requirements.txt
file should be present in the repository. If not, you will need to install the necessary packages likegoogle-generativeai
,psycopg2-binary
,mysql-connector-python
,PyYAML
,python-dotenv
etc.)
-
Environment Variables: Create a
.env
file by copying the example file:cp .env.example .env
Update the
.env
file with your specific configuration:GOOGLE_API_KEY
: (Required) Your Google API Key.TOOLS_YAML_PATH
: Path to your tools configuration file (default:./config.yaml
).DB_KEY
: The key fromconfig.yaml
to select the database configuration (e.g.,postgres_db
,mysql_db
,sqlite_db
).MCP_TOOLBOX_URL
: (Optional) URL for the MCP Toolbox service.CONNECTION_URL
: (Optional) A single database connection string. Can be used for a single-database setup.DB_PASSWORD
: (Optional) Database password if not included in the connection string or YAML config.
-
YAML Configuration (
config.yaml
) Theconfig.yaml
file defines the connection details for multiple databases. The agent uses theDB_KEY
from the.env
file to determine which database to connect to.
To run the agent, you would typically execute a main Python script. The exact command depends on the project's entry point (e.g., main.py
, app.py
).
Example Workflow:
-
Ensure your
.env
file is configured correctly. For instance, to use the PostgreSQL database defined inconfig.yaml
. the.env.example
contains all the environment variables you can -
Run the register_db.py with your configured DB parameters:
python utils/register_db.py
-
Run the toolbox server:
./toolbox --tools-file "tools.yaml"
toolbox --tools-file "tools.yaml"
.\toolbox.exe --tools-file "tools.yaml"
-
Run the MCP based agent to query in natural language:
python agent/mcp_toolbox_agent.py
The agent will then:
- Read the
DB_KEY
from the environment. - Load the corresponding database configuration from
config.yaml
. - Connect to the PostgreSQL database.
- Use the table schema and your question to generate a SQL query via the LLM.
- Execute the query and return the result.