Most AI workflows that need to read or write data from a database require custom code for each use case. You write a tool, hardcode the schema, handle the query, return the result. It works, but it does not scale. Every new request means a new function. And if the schema changes, you update the code.
The deeper problem is that the AI model has no way to explore the data itself. It only knows what you hardcode into the system prompt or the tool definition. Ask it a question that touches a table you did not think to describe and the answer falls apart.
What I wanted was a protocol layer. Define the tools once at the database level, not at the question level. Let Claude figure out what to call, in what order, to answer whatever the user asks.
MCP (Model Context Protocol) is the right abstraction here. It is an open protocol for giving AI models structured, permissioned access to tools and data. You define tools as TypeScript functions with a name, a description, and a Zod schema for the inputs. Claude reads the tool list, decides which ones to call, calls them, reads the result, and continues. The model orchestrates the tools, not the developer.
The design decision that made this genuinely useful was schema discovery. Instead of hardcoding the database structure anywhere, I wrote two PostgreSQL functions that expose live table names and column types through Supabase's RPC layer. Claude can call them at the start of any session and understand the full database structure from scratch without any prior knowledge of it.
That changes the dynamic. You do not tell Claude about your database and then ask it questions. You connect the server, Claude looks around, and then you have a conversation about your actual data.
The test session ran against a real Supabase database. I connected the server, opened Claude Desktop, and asked: "What tables are available and what does the orders table look like?" Claude called list_tables, got 23 results, then called get_table_columns for orders and returned a structured view of 35 columns with their types. I had not told it anything about the database.
Then I asked for the products. It called filter_table with no column filter, returned all rows formatted as a clean table with names, categories, prices, and stock levels. Then I asked it to add a test product and confirm the insert. It used two tools in sequence, insert_row and then query_table, and returned the new row including the UUID and timestamp that Postgres generated.
This is the pattern I now use when building AI agents that need to work with a client's live data. Define the tools at the database level rather than the question level, expose them through MCP, and Claude handles the orchestration. The schema discovery means the server works against any Postgres database without modification.
The source is on GitHub. The architecture works the same way whether the database has 5 tables or 50.
Book a free 30-minute call. I will map your current data and show you exactly what is possible with MCP.
Book a call View on GitHub →