Let Your AI Know How to Work With Your Database (Safely, Without Raw Credentials)
π‘ Support Open Source: If you find Ivory useful for your workflow, please consider starring the repository on GitHub β. Every star helps keep the project active and visible to other engineers! Every developer and DBA u
π‘ Support Open Source: If you find Ivory useful for your workflow, please consider starring the repository on GitHub β. Every star helps keep the project active and visible to other engineers!
Every developer and DBA using AI coding assistants like Claude Code, Cursor, VS Code, or Codex eventually runs into the same limitation.
Your AI assistant is great at writing complex SQL queries, debugging application logic, and refactoring schemas in isolation. However, the moment you ask it a question about your actual running database infrastructure, it has zero visibility.
To work around this, engineers often resort to risky habits:
- Copy-pasting production schemas and config files into chat prompts.
- Handing an AI agent raw database connection strings or SSH keys.
- Maintaining fragile, single-purpose scripts just to let an LLM query one database.
There is a much cleaner architectural pattern: give your AI structured operational context instead of raw keys.
Here is how Ivory solves this out of the box, and how you can teach your AI agent to inspect, query, and manage your database clusters safely.
Why Raw Database Access Is the Wrong Way to Connect AI
When developers search for how to connect AI to PostgreSQL or how to let an AI agent manage a database, most tutorials suggest creating a database role and passing the connection string directly into a local MCP (Model Context Protocol) server.
In production or multi-service environments, that approach has major flaws:
- No Infrastructure Context: A raw SQL connection doesn't tell the AI which node is the primary, which nodes are replicas, whether Patroni is orchestrating failover, or if high CPU on the host VM is causing query latency.
- Credential Exposure: Connection strings, passwords, and SSH keys end up sitting inside local config files or LLM context windows.
- All-or-Nothing Blast Radius: Managing granular permissions across multiple database engines (PostgreSQL, Redis, MongoDB, ClickHouse, etcd, ZooKeeper) quickly becomes unmanageable.
- Tool Sprawl: You shouldn't have to configure seven different MCP servers just to monitor your data layer.
Enter Ivory: A Unified Context Layer for Your AI Agent
Ivory is an open-source, self-hosted web UI and cluster management system that runs in a single Docker container with no agents required on your database hosts. It supports:
- PostgreSQL (High-availability with Patroni & standard primary/standby)
- Redis (Master/replica replication)
- MongoDB (Replica sets)
- ClickHouse (Replicated clusters)
- etcd & ZooKeeper
Because Ivory already communicates with your clusters and underlying VMs over SSH and native database protocols, it acts as a unified gateway for AI agents via its built-in Model Context Protocol (MCP) server.
Instead of teaching your AI how to interact with seven different database engines and Linux hosts from scratch, you point your AI client to Ivoryβs /api/mcp endpoint.
What Your AI Learns Automatically:
- Cluster Topology: Node roles (leader/primary vs. replica/secondary), cluster states, and keeper configurations.
- Real-Time Health & Lag: Replication lag measured in engine-native units (bytes for Postgres, seconds for Redis/MongoDB, Raft entries for etcd), pending restarts, and active warnings.
- Host Machine Telemetry: CPU, memory, network stats, running processes, and container or host logs.
- Saved Diagnostics: Built-in, engine-specific diagnostic queries (such as table bloat or lock inspection) ready to execute on demand.
How to Connect Claude, Cursor, or Codex in 3 Steps
You don't need to deploy sidecars or open extra firewall ports. If you are running Ivory, the MCP server is already active.
1. Launch Ivory (Skip if Already Running)
docker run -p 80:80 --restart always veegres/ivory
Open http://localhost, complete the initial setup wizard, and register your existing clusters (or deploy a new one from a built-in template).
2. Generate a Scoped MCP Token
In the Ivory UI, navigate to Settings β Integrations β MCP Server.
Select a token lifetime (1 hour, 6 hours, 1 day, 15 days, or 30 days) and generate your bearer token.
3. Add the Config to Your AI Client
Ivory provides one-click configurations for Claude Code, Cursor, VS Code, Codex, Claude Desktop, IntelliJ IDEA, and Antigravity.
For Claude Code, run a single command:
claude mcp add --transport http ivory http://localhost/api/mcp \
--header "Authorization: Bearer $TOKEN"
Once connected, your AI assistant immediately understands your database topology.
Practical Ways to Use AI With Your Databases
When engineers ask "How can AI help manage my databases?", the goal isn't letting an LLM blindly alter production data. It is eliminating context switching during development, performance tuning, and maintenance.
Here are real workflows you can run directly from your IDE:
1. Schema & Bloat Optimization
"Check the saved diagnostic queries for our analytics Postgres cluster, run the table bloat check, and tell me which tables need maintenance."
Your AI discovers Ivoryβs diagnostic query library, runs the check safely, and summarizes the top offenders.
2. Multi-Engine Health Audits
"Give me a status report across all my clustersβPostgres, Redis, and ClickHouse. Are there any replication delays or engine warnings?"
Instead of jumping between three different CLI tools or dashboards, the AI queries Ivoryβs unified API and returns a single cross-database summary.
3. Root-Cause Correlation (Database vs. Host OS)
"Query latency just spiked on
db-replica-02. Check if it's a database lock, replication lag, or another process eating CPU on the host VM."
Because Ivory tracks both database metrics and underlying host telemetry, the AI correlates SQL behavior with OS-level resource usage in one step.
4. Guided, Safe Cluster Maintenance
"Verify that
patroni-node-3is healthy and caught up on replication. If it is, explain the steps to perform a switchover and wait for my confirmation."
Ivory supports lifecycle actions like switchover, reload, and restartβincluding scheduling Patroni switchovers for off-peak maintenance windows.
5. Ephemeral Test Environments
"Deploy a single-host test Redis cluster on
10.0.0.12using our saved SSH and password vaults."
The AI uses Ivoryβs deployment templates and encrypted vault references to provision test clusters without ever seeing a plaintext password.
Security Architecture: Keeping Guardrails on Your AI
Giving an AI agent visibility into database infrastructure requires strict access control. Ivory enforces security at the platform level rather than relying on prompt rules:
| Security Layer | How Ivory Enforces It |
|---|---|
| RBAC Permission Mirroring | The AI inherits the exact permissions of the Ivory user who generated the token. A read-only user (view.*) cannot even see destructive tools like switchover or restart. |
| Vaulted Credentials | SSH keys, certificates, and DB passwords never leave Ivory's encrypted vault. The AI references secrets by ID and never sees raw credentials. |
| Hard-Coded Boundaries | Endpoints for erasing data, exporting backups, or managing users/permissions/vaults are completely excluded from the MCP server. |
| Destructive Tool Labels | State-changing tools are marked as destructive so MCP clients (Claude, Cursor, etc.) require explicit human confirmation before execution. |
Wrapping Up
AI coding assistants become dramatically more useful when they understand the real infrastructure behind your code. By placing Ivory between your AI agent and your database clusters, you give your assistant complete awareness of your topology, telemetry, and diagnostic toolsβwhile keeping credentials vaulted and permissions strictly enforced.
Useful Links
- β GitHub Repository: github.com/veegres/ivory (Leave a star to support the project!)
- π Official Website: ivory.veegres.com
- π€ MCP Server Docs: ivory.veegres.com/docs/mcp-server
- π Getting Started Guide: ivory.veegres.com/docs/getting-started
Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes β full credit and traffic to the original publisher.