AI Automation, RAG & MCP
5 min read
By UnlockLive IT engineering team
Diagram of an AI assistant querying curated database views on a read replica through an MCP server with row limits and query logging

Most companies have one or two people who can answer questions from the database. Everyone else waits. A sales director wants last quarter's revenue by region. An operations lead wants late orders by warehouse. Each request joins a queue, and simple questions take days.

The cost is slower decisions and a quiet habit of guessing. People stop asking because the answer arrives too late to matter. Meanwhile the analyst spends their week on small queries instead of the deeper work they were hired for.

What this does

MCP (Model Context Protocol) is an open standard introduced by Anthropic. It lets AI assistants such as Claude, and other clients that support it, connect to tools and data through small programs called MCP servers. Support varies by AI client, so check each client's current documentation before you plan a rollout.

A database MCP server lets a manager ask a question in plain English. The answer comes from Postgres, MySQL, SQL Server or a similar database. The assistant chooses a tool, the server runs a safe query, and the result comes back with the query shown for checking. Typical questions include:

  • "What was revenue by region last quarter, compared with the quarter before?"
  • "Which products had more returns than usual this month?"
  • "How many orders shipped late from each warehouse last week?"

The key word is safe. The design below keeps the assistant read-only, away from personal data and unable to slow down production.

Predefined tools versus free-form SQL

There are two ways to let an assistant reach your data. Each suits a different audience.

Predefined tools

Each tool runs a fixed, reviewed query with a few parameters, such as a date range and a region. Answers are fast and consistent. The model cannot write a bad join, because it never writes SQL at all. This suits managers and most staff.

Guarded free-form SQL

The model writes a query, and the server checks it before running it. It must be a single SELECT against approved views, with a row limit added. This handles unexpected questions, but answers need more checking. It suits analysts who can read the query and spot mistakes.

Most teams start with predefined tools for the top questions. They add guarded SQL later, for a small group, if demand is there.

How it works, step by step

  1. Use a read replica. Queries run against a copy of the database, not the primary. A heavy query cannot affect customers.
  2. Create curated views. We build views with plain names, such as sales_by_region_monthly, instead of exposing raw tables. Views hide joins and internal columns.
  3. Leave out personal data. By default, views exclude names, emails, phone numbers and similar fields. Aggregates answer most business questions anyway.
  4. Create a read-only user. The server connects with a database user that can only select from the curated views.
  5. Offer two kinds of tools. Predefined tools answer common questions with fixed queries. A guarded SQL tool, if you want one, accepts only single SELECT statements against approved views.
  6. Enforce limits. Every query has a row limit and a timeout. Results are summarised before they return to the assistant.
  7. Log every query. We record the user, the question, the SQL that ran, the time taken and the row count.
  8. Test with known answers. Before rollout, we check the assistant against questions where the correct answer is already known.

Tools we use

  • MCP SDKs for Python or TypeScript.
  • Python with FastAPI and standard database drivers for Postgres, MySQL and SQL Server.
  • A SQL parser to check that guarded queries are single, read-only statements against allowed views.
  • Your existing database and its native read replica or replication features.
  • Structured logging to your existing log platform, so queries are searchable and auditable.

Database and AI client features change. Check your database vendor's and client's current documentation for replica, permission and MCP support.

What you need to get started

  • A database administrator who can create a read replica, views and a restricted user.
  • Twenty or so real questions people ask today, with known answers for testing.
  • A short data dictionary, even an informal one, explaining what key tables and columns mean.
  • A decision on which data is sensitive and must stay out of every view.
  • An agreed AI client that supports MCP for your users.

Typical scope and timeline

As an estimate, a first read-only version typically takes one to three weeks. That covers a handful of curated views and predefined tools. The range depends on how tidy your schema is and whether a read replica already exists. Messy schemas take longer because the views do the cleaning. A guarded free-form SQL tool, if needed, usually follows once the curated views prove reliable.

Risks and how we handle them

Confident wrong answers

An assistant can misread a column and give a plausible but wrong number. Curated views with clear names reduce this. The assistant shows the query it ran, and we test against known answers before launch.

Exposing personal or sensitive data

The restricted database user can only read approved views. Personal fields are excluded at the view level, so no prompt can reach them.

Slow or expensive queries

The replica, row limits and timeouts protect production. We watch the query log for patterns that need a new view or an index.

Prompt injection and SQL injection

Text stored in the database can contain instructions aimed at the assistant. The server only runs validated read-only statements, and tool outputs are treated as data. See our MCP server security checklist for the full list.

When not to build this

If your BI tool already offers a natural-language feature that covers your questions and permissions, use it. If the same five numbers are needed every Monday, a scheduled report is cheaper and more predictable. Our guide to automated KPI reports in Slack and Telegram covers that route. And if your data needs heavy cleaning before anyone can trust it, fix that first. An assistant makes bad data easier to reach, not more correct.

If your questions live in documents rather than tables, a retrieval system is a better fit. See an internal knowledge assistant for Slack and Teams. If you also need answers from APIs and older business systems, read MCP for internal APIs and ERP systems.

How UnlockLive can help

UnlockLive IT is a Toronto-headquartered software agency with its own engineering team. We build these integrations for companies in the US, Canada, the UK and Australia. Our MCP server development service covers scoping, the threat model, the build, deployment and ongoing maintenance. Because database access is sensitive, our cybersecurity team can review the permissions, logging and threat model before rollout.

If you want a second opinion on scope or risk, book a free 30-minute call. Bring one or two questions your team asks every week, and we will tell you honestly whether an MCP server is the right tool.

Frequently asked questions

Can Claude query a Postgres or SQL Server database?

Yes, through an MCP server that connects the assistant to the database. Support depends on the AI client, so check its current documentation. For business use, the server should use a read-only account on a read replica and expose curated views rather than raw tables.

Is it safe to let an AI write SQL against our database?

Only with strict limits. Use a read-only database user, a read replica, curated views, row limits, query timeouts and logging. Many teams prefer predefined query tools for common questions and allow free-form SQL only for trusted analysts.

How do we keep personal data out of AI answers?

Expose views that leave out or mask personal fields such as names, emails and phone numbers. Grant the MCP server's database user access to those views only. Personal data then never reaches the assistant, regardless of what is asked.

Do we need a data warehouse before doing this?

Not necessarily. A read replica with a few well-designed views is often enough to start. A warehouse helps when you need to combine many sources or run heavy historical analysis.

How accurate are plain-language database answers?

Accuracy depends mostly on how clear the data model is. Curated views with plain column names and short descriptions help a lot. We test with a set of known questions and answers before rollout, and the assistant shows the query it ran so results can be checked.

How do you connect an MCP server to a database?

Give the MCP server its own read-only database user, pointed at a read replica rather than the live database, with access only to curated views. Its tools either run predefined queries or run checked SQL with row limits and timeouts. The server is then registered with the AI client, and every query is logged so you can review what was asked.

How we can help

  • MCP Server Development ServicesCustom Model Context Protocol (MCP) servers that expose your APIs, databases, and internal tools to Claude, Cursor, ChatGPT, and any MCP-compatible AI.
  • Python & FastAPI DevelopmentHigh-performance Python backends and FastAPI microservices for SaaS, AI inference APIs, ETL pipelines, and event-driven systems.
  • Cybersecurity & AI Security ServicesPenetration testing, SOC monitoring, SOC 2 / ISO 27001 / PCI DSS / HIPAA readiness, and emerging-area work in LLM red teaming and AI agent security.

Talk to an engineer about your project

Tell us what you are building. We reply within one business day with a candid view on scope, approach and effort.

Book a free strategy call

Written by the UnlockLive IT engineering team. UnlockLive IT Limited works with clients through its Toronto headquarters and delivers engineering from its Dhaka delivery centre. About us

Related articles

AI Automation, RAG & MCPn8n AI Agents That Take Actions Safely: MCP Tools and Human ApprovalAI Automation, RAG & MCPAI Build vs Buy: An Honest Framework for Choosing Off-the-Shelf or CustomAI Automation, RAG & MCPStop Retyping Forms and PDFs: AI Document Extraction into Your ERP or CRM

Contact Us

Fill out the form below and our team will get back to you shortly to assist with your inquiry.