Analytical reports with an AI agentData from a database, sheets and documents through MCP
How to build an analytical report with an AI agent: connect a read-only database through MCP, delegate queries and the summary, check one number by hand and set permissions per source.
A report by hand is an export from a database, a table, a chart and text, and every step waits for a person. An agent with access to the sources goes through the chain itself, while a person checks the numbers and decides what to do next. Below: how it looks, which permissions to give per source, how to connect the database and verify the result. The basics are in the MCP for an AI agent article.
How a report gets built
Takeaway
In this exampleBy hand, a person moves data between the database, table, chart and text. With an agent they get a ready draft and check the numbers.
In generalThe sources connect to the agent through MCP. Every step of the chain repeats and gives a clear result, so it can go to an agent. What the numbers mean is a human decision.
What to doList the steps of your latest report and mark which of them are copying.
Sources and permissions
Systems, data and documents outside the conversation. Permissions are set separately for each source.
Takeaway
In this exampleJira, documents and the database are open for reading, the sheet for writing with confirmation, and only the stand can be broken.
In generalThe agent sees exactly what is connected and does exactly what is allowed.
What to doFor each source write one word: read, write or stand only.
How to connect the database
Tell the agent
Connect the analytics database as read-only. Show the schema of the orders table and calculate this month’s revenue. Show the query you used.
claude mcp add --transport stdio db -- npx -y @bytebase/dbhub \
--dsn "postgresql://readonly:pass@prod.db.com:5432/analytics"
Create the user as read-only so the agent’s queries cannot change anything. Example prompts from the docs: “What’s our total revenue this month?”, “Show me the schema for the orders table”.
Takeaway
In this exampleThe agent connects the database, looks at the schema, calculates revenue and shows the query.
In generalRead-only rights keep queries safe: the agent cannot change data.
What to doCreate a read-only database user and connect it first.
How to check the report
Takeaway
In this exampleThe agent shows the query and result, a person recomputes one number another way.
In generalThe model calculates with a query, and a query can be reread. A matching number raises trust in the rest.
What to doCheck one number from the report by hand before sending the report on.
Where to start
Takeaway
In this exampleThree steps: a read-only database, one report, checking one number.
In generalStart with a report whose numbers you already know: that shows where the agent went wrong.
What to doToday create a read-only user and ask the agent to calculate a familiar figure.