Your Old SQL Reports Deserve a Second Life — as an Agent Tool

With AI, ‘context is everything’. To get the best results, you need to provide AI Expertise, the right MCP Server, Agent Memory, the best prompts in the world, and whatever else a context engineering expert will come up with next.

What if you could short cut most of that, and use the kit you’ve developed over the last few years, and just train your Agents on how to use them, vs asking them to generate code, or create SQL to answer your question?

OCI SQL reports allow that

The MCP Server we manage for Oracle AI Database includes the ability to deliver information via SQL Reports. So your agents and LLMs don’t need to study your schema to know how to generate the right SQL, they just have that SQL ready, at their fingertips, through MCP Tools.

Need refreshment? You can read more about:

  • Announcement: Our OCI MCP Server for Oracle AI Database
  • Deep Dive: SQL Reports, and how AI can use them through MCP

Cool, but now I have to create AND load a ton of reports. See you in 3 months.

WRONG! You may already be using these reports in your organization in a variety of formats. You can automate the transformation and load those reports! And that’s what I want to tell you now.

AI is good at many things, and generating code to do basic utility type things is definitely one of those things, especially if it’s not for a commercial grade enterprise application!

I asked my Agent to learn ‘create-sql-report-oracle-database‘ OCI command line utility docs, and also to read my coworker’s Terraform automation post for batch loading SQL reports.

I then asked him to take the EXISTING AWESOME REPORT, and refactor it for this use case. We wrote this report to help DBAs perform diagnostics on their databases. They look at things like expensive SQL, memory allocation/usage, and wait events.

So if I have a question about my system, and it falls into this bucket, my Agent can simply call a report to get that info, versus going back to creating (and executing) SQL to get that data.

That is, I am sure of it the answer will be ‘known’ and consistent. This would also save resources – my agent wouldn’t use tokens to ‘think’ and generate code.

Before I share the OCI script I use, let me talk about the instructions I share with my Agents

*Keep the SQL lean as per the question request, tell the agent exactly when to fetch this report (with real question examples), and name your parameters like you’re handing them off to a colleague, not a compiler.*

I also encouraged him Remember (consider) Our AI skills around SQL and performance tuning.

SQLcl makes loading our AI Skills for Oracle AI Database, as easy as ‘skill sync’

My agent can look at my old reports, saved as XML, and convert them to JSON files that have the structure expected by the OCI command.

Here is a before and after example –

The biggest difference is the documentation, the instructions included in the report. This report TEACHES MCP Clients how to call the report. The report even includes examples of questions that can be answered in the report!

JSON

Just loading reports in bulk, as is, may be fine, but I think it’s worth taking the time to validate reports so they still do what you think they do, AND add to their metadata so it’s clear to a person or agent when they can be applied to the question at hand.

Some reports have parameters, these parameters also need to be documented!

Instead of point-and-clicking 97x and copy-pasting another 36 times…I created a script to do it all for me in just a few seconds.

I have OCI SDK .profile set up on my machine. I can work from my machine to work with my OCI leases from vs code in my browser and console.

My bash script has some things specific to ‘me’, namely –

Party

I put my SQL Reports into a specific compartment, and I use a secondary OCI Profile (not DEFAULT), so I set it as default.

Otherwise, the script is pretty straightforward:

  • One JSON file per report, mapped directly to `oci dbtools sql-reports create-sql-reports-oracle-database` flag
  • A small bash loop that handles multiple profiles, test mode, and doesn’t stop on the first failure
  • Parses the resulting OCID for the new report object, exiting the asynchronous CLI response

How does it feel to run

I have 5 or 6 reports in one folder, and I just call my script.

This report cannot be used from our MCP Server yet.

I can pull a report in the Console, just to do a sanity check, make sure everything is working as expected.

I have to divide 1 report into 5

I have a Parent-Child report. However our OCI Tools service does not support this. Does not matter! I simply split 1 BIG report into several separate reports, with supporting descriptions and updated instructions to instruct Agents how to ‘run’ the report from the top level down.

Set it up so it can be called from my Agent

I need to add this new report to my MCP Server and new or existing MCP Devices. At that time I also set up the Role membership required to access the report.

Once I did this, they were available, IMMEDIATELY.

Manuscript

Hint: the actual command instructions start on line 105.

Party