Skip to content

SQL Connector

The SQL connector provides live access to relational databases with 8 tools for schema inspection, querying, and statistical analysis. It supports PostgreSQL and MySQL.

Authentication

Provide a standard database connection string:

PostgreSQL

json
{
  "name": "Production Postgres",
  "source_type": "sql",
  "config": {
    "connection_string": "postgresql://agentcy:password@db.example.com:5432/myapp",
    "database_type": "postgresql",
    "schema": "public",
    "read_only": true
  }
}

MySQL

json
{
  "name": "Analytics MySQL",
  "source_type": "sql",
  "config": {
    "connection_string": "mysql://agentcy:password@db.example.com:3306/analytics",
    "database_type": "mysql",
    "read_only": true
  }
}

WARNING

Always use a read-only database user for the SQL connector. The read_only flag adds a safety layer, but a least-privilege database user is the primary line of defense.

Creating a Read-Only User

PostgreSQL:

sql
CREATE USER agentcy WITH PASSWORD 'secure-password';
GRANT CONNECT ON DATABASE myapp TO agentcy;
GRANT USAGE ON SCHEMA public TO agentcy;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO agentcy;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO agentcy;

MySQL:

sql
CREATE USER 'agentcy'@'%' IDENTIFIED BY 'secure-password';
GRANT SELECT ON analytics.* TO 'agentcy'@'%';
FLUSH PRIVILEGES;

Live Tools (8)

ToolDescriptionArguments
sql_list_tablesList all tables in the database or schemaschema?
sql_describe_tableGet column names, types, nullability, defaults, and constraintstable, schema?
sql_queryExecute a read-only SQL query and return resultsquery, limit?
sql_list_indexesList indexes on a table with columns and uniquenesstable, schema?
sql_list_constraintsList constraints including foreign keys and their referencestable?, schema?
sql_table_statsGet row counts, table size, and column statisticstable, schema?
sql_list_viewsList views with their definitionsschema?
sql_explain_queryGet the execution plan for a queryquery

TIP

The sql_query tool enforces a read_only transaction mode. INSERT, UPDATE, DELETE, and DDL statements are rejected even if the database user has write permissions.

Example: Agent Using SQL Tools

User: "What's the schema of the users table and how many rows does it have?"

Agent: Let me check the users table.
→ Calls sql_describe_table(table: "users")
→ Calls sql_table_stats(table: "users")
→ Reports:
  "The users table has 12 columns:
   - id (uuid, PK)
   - email (varchar, unique, not null)
   - name (varchar)
   - created_at (timestamptz, not null)
   - ...
   Total rows: 45,231. Table size: 18 MB."

ETL Ingestion

Nodes Created

Node LabelPropertiesSource
Databasename, type (postgresql/mysql), host, portConnection
Tablename, schema, row_count, size_bytes, column_countInformation schema
Columnname, data_type, nullable, default_value, is_primary_keyInformation schema
Indexname, table_name, columns, is_unique, typeInformation schema
ForeignKeyname, from_table, from_columns, to_table, to_columnsInformation schema
Viewname, schema, definitionInformation schema

Relationships Created

RelationshipFromTo
CONTAINSDatabaseTable, View
HAS_COLUMNTableColumn
HAS_INDEXTableIndex
REFERENCESTableTable (via ForeignKey)
FOREIGN_KEYColumnColumn
DERIVED_FROMViewTable

Graph Queries

cypher
-- Find all tables referencing the users table
MATCH (t:Table)-[:REFERENCES]->(users:Table {name: "users"})
RETURN t.name, t.row_count

-- Find tables without indexes (potential performance issues)
MATCH (t:Table)
WHERE NOT (t)-[:HAS_INDEX]->()
AND t.row_count > 1000
RETURN t.name, t.row_count
ORDER BY t.row_count DESC

-- Map the full schema graph
MATCH (t:Table)-[:HAS_COLUMN]->(c:Column)
WHERE t.schema = "public"
RETURN t.name, collect({name: c.name, type: c.data_type}) AS columns

Configuration Reference

FieldTypeDefaultDescription
connection_stringstringrequiredDatabase connection URL
database_typestringauto-detectedpostgresql or mysql
schemastringpublic (PG)Schema to scope ingestion and tools to
read_onlybooltrueEnforce read-only queries
max_query_rowsint1000Maximum rows returned by sql_query
query_timeout_secsint30Query execution timeout
ssl_modestringpreferSSL mode: disable, prefer, require, verify-ca, verify-full
ssl_ca_certstring--CA certificate for SSL connections
sync_viewsbooltrueInclude views in ingestion
sync_indexesbooltrueInclude indexes in ingestion
exclude_tablesstring[][]Tables to exclude from ingestion

Connection String Formats

# PostgreSQL
postgresql://user:password@host:5432/database
postgresql://user:password@host:5432/database?sslmode=require

# MySQL
mysql://user:password@host:3306/database
mysql://user:password@host:3306/database?ssl-mode=REQUIRED

Troubleshooting

ErrorCauseFix
Connection refusedDatabase is unreachableVerify host, port, and network/firewall rules
Authentication failedInvalid credentialsCheck username and password
Database does not existWrong database name in connection stringVerify the database name
Permission denied for tableUser lacks SELECT on one or more tablesGrant SELECT permissions
SSL connection requiredServer requires SSL but client didn't use itAdd ?sslmode=require to connection string
Query timeoutQuery exceeded the configured timeoutIncrease query_timeout_secs or optimize the query

Built by AgentcyLabs. For in-house deployment or Agentcy Cloud (PaaS) access, visit agentcylabs.com.