---
docId: doc_d99afadb8591443bb4e717b55014ccec
title: 'Databases'
description: "Connect PostgreSQL or MySQL so agents can query data in read-only mode."
---

<script>
  import { Note, Ways } from '$lib/components';
</script>

# Databases

Connect a public **PostgreSQL** or **MySQL** database in read-only mode. Platica creates 4 tools: list tables, read columns, run `SELECT` queries, and paginate results. Connect the tools to the agents that need them.

## Quick example

<Ways tabs="api,sdk">
<Ways.Way name="api">

```bash
# 1. Connect the database (it is born enabled with its 4 tools in tools[])
curl -X POST https://api.platic.ai/v1/tools/databases \
  -H "Authorization: Bearer $PLATIC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "store",
    "engine": "postgres",
    "host": "db.example.com",
    "database": "store",
    "user": "readonly",
    "password": "your-db-password",
    "hiddenColumns": ["customers.phone"]
  }'

# 2. Test the connection
curl -X POST https://api.platic.ai/v1/tools/databases/$DB_ID/test \
  -H "Authorization: Bearer $PLATIC_API_KEY"
```

</Ways.Way>
<Ways.Way name="sdk">

```ts
// 1. Connect the database (the password is stored encrypted as a secret)
const db = await platic.tools.databases.create({
  name: 'store',
  description: 'Orders and customers of the online store.',
  connectionString: process.env.STORE_DATABASE_URL!,
  hiddenColumns: ['customers.phone']
});

// 2. Test the connection and connect the query tool to your agent
const test = await platic.tools.databases.test(db.id);
if (test.connected) {
  const queryTool = db.tools.find((t) => t.tool === 'query')!;
  await platic.agents.tools.connect(agentId, queryTool.id);
}
```

</Ways.Way>
</Ways>

## What you need to know

- **Read-only:** it runs one `SELECT` per query in a read-only transaction. Use a read-only database user too.
- **Hidden data:** `hiddenTables` and `hiddenColumns` hide the selected tables and columns. On a table with hidden columns, select the columns instead of using `SELECT *`.
- **Secure password:** it goes in `password`, `connectionString`, or `passwordSecretId` and is never returned. If you change the host, port, or SSL, it goes to `needs_authorization` and you must send it again.
- **Public hosts and Supabase:** local and private hosts are rejected. On Supabase use the **Session pooler** (the direct connection only uses IPv6).
- **Limits:** 20 connections per workspace, 1 to 200 rows per page (`50` by default), 1 to 30 s timeout (`5` s by default), 500 hidden tables/columns, and 10,000 characters per query.
- **Permissions:** requires **Integrations** (and write permission with OAuth to create, change, or query).

<Note type="warning">

Platica does not connect from a fixed IP yet; if your database filters by an IP allowlist, the connection will be rejected.

</Note>

## Endpoints

| Method | Endpoint | What it does |
|--------|----------|--------------|
| `GET` / `POST` | [`/v1/tools/databases`](/api-reference/databases/list) | List, or [connect](/api-reference/databases/connect), a database |
| `GET` / `PATCH` / `DELETE` | [`/v1/tools/databases/{databaseId}`](/api-reference/databases/get) | Get, [update](/api-reference/databases/update), or [delete](/api-reference/databases/delete) |
| `POST` | [`/v1/tools/databases/{databaseId}/test`](/api-reference/databases/test) | Test the connection |
| `GET` | [`/v1/tools/databases/{databaseId}/schema`](/api-reference/databases/schema) | See tables and columns |
| `POST` | [`/v1/tools/databases/{databaseId}/query`](/api-reference/databases/query) | Run a `SELECT` or ask for the next page |
| `POST` | [`/v1/tools/databases/{databaseId}/enable`](/api-reference/databases/activate) | Enable, or [pause](/api-reference/databases/pause), the connection |

Errors are in [Errors](/api-reference/errors) and AI tools in [Databases MCP](/mcp/tools#tools).
