Discuss your project

Guide

SQL Server MCP: what lives inside the procedures

A SQL Server MCP connection puts your tables in front of your assistant, read-only. The trap: logic hidden in stored procedures.

By · Updated · 5 min read

The SQL Server connection I set up gives an assistant read-only access to the tables of one database. The tables are honest. The procedures may not be, because a procedure can encode a rule that nobody wrote down anywhere else.

I am Benoit Pecqueur. I connect business systems to AI assistants for owners in Phoenix and Scottsdale. SQL Server often sits in businesses that have run on Microsoft software for a decade or more, and the logic inside the procedures can be older than most of the people who read the reports.

The stored procedure is the business model

In many databases the schema carries the model. In many SQL Server estates a large part of the model lives inside stored procedures, in T-SQL that someone wrote years ago and something has run every morning since.

A procedure takes a raw order row and turns it into the number on the daily report. It applies a discount rule, excludes a customer class, shifts dates onto a fiscal calendar. Each of those steps is a business decision. Once the decision is inside the procedure it stops being visible. The report shows the result. The rule itself is buried.

That is why a connection that reads only tables and views can produce a different number than the official report. Both sides are right against their own inputs. The difference is the logic in the middle.

What the SQL Server connector exposes

The SQL Server connection I set up is read-only. It sees:

  • The tables in the database I configure
  • Column schemas for any table it is asked about
  • Results of SELECT queries it builds from your questions

Stored procedure text is not on that list. I get it from the DBA or from a script of the database, and I read it with the owner. The connection runs SELECT queries only: no data changes, no DDL and no procedure execution. I would also not let the assistant run a procedure that writes, even by accident.

The question that needs a second read

Which report is wrong when a procedure encodes a rule nobody documented.

A concrete case. The monthly report says revenue is down. The tables say orders are up. The difference is a procedure that reclassified 2 customer types 5 years ago during an acquisition, and nobody alive remembers why.

The cross question here is not which system to join. It is which version of the truth to audit. To answer it the assistant needs the tables, the procedure text and the report output, and then the owner has to rule on what the number should have been. The third system is a person.

Time breaks first

SQL Server datetime columns carry no timezone, so the convention lives in someone's habits. A date stored as UTC, a date stored as server local time, a date stored as whatever the old import job assumed. A monthly report assembled from all 3 drifts by hours, which becomes days at month boundaries.

Close behind is the definition of a customer, which in a system this old usually has at least 3 tables: accounts, contacts and a legacy table nobody dares drop. Every report picks one, and no 2 reports pick the same one.

Where a SQL Server connection does not fit

3 cases.

A server that cannot give a read-only login. If the DBA cannot or will not create a role with SELECT only, the connection should not happen. If the only login that exists can also write, the answer is a read replica, a snapshot, or nothing.

Procedures nobody can read. Some environments restrict access to procedure definitions, and the connection does not read them. If the assistant can see the report number but not the logic that produced it, it will learn to reproduce the report without understanding it. That is worse than no connection, because it looks authoritative.

An owner who believes the official report is the truth. If the goal is to make the existing number faster, the connection will do that. If the goal is to find out whether the number is right, someone has to be willing to see it change.

How I would run the first report

One report rebuilt from the tables, compared to the procedure output.

  1. Get the read-only login working and confirm it can see the tables the report uses.
  2. Pick the one report the owner trusts most, and get its procedure text from the DBA.
  3. Rebuild the report in plain SQL against the tables, without the procedure. Write down every rule the procedure applies as you find it.
  4. Run both for the same period. Compare line by line and list every difference.
  5. For each difference ask the owner which side is correct. That list of decisions is the real deliverable, not a number.

Most differences turn out to be decisions that were made once and never reviewed. Making them visible again is the point of the connection, and it is why I put the read-only boundary in writing before the first query in read-only AI access. The setup is part of the broader playbook in connect business tools to AI. If your data lives in an open source database instead, PostgreSQL MCP covers the same work on a different surface.

Questions owners ask

No. The connection I set up is read-only and runs SELECT queries only, so it cannot execute a procedure. The procedure text reaches me from your DBA, not through the connection.

Because the report runs through a procedure that applies rules the raw tables do not show. The difference between the 2 numbers is the list of those rules, and that list is usually the first thing worth reading.

Yes, for one task: creating a read-only login with SELECT on the tables the question needs. Everything after that I can work through with the owner.

I check the timezone story on day 1, because a monthly report assembled from mixed datetime conventions drifts in ways that only show at month boundaries. The fix is usually one explicit convention, written down.

Not necessarily wrong, but the difference has to be explained. Every difference is a rule somebody applied. If nobody can explain a rule, that rule is now a decision on your desk.

Start with the process that costs you the most time

Tell me which process you want to improve. A name, an email, and a short description of the process are enough to start a useful conversation.

Discuss your project