Debugging Databases & SQL
Prompt Copilot to run the next-step skill and move to the ai-training-debugging-4 branch.
Then ask Copilot to set up the codebase fresh so we can seed the database and install a new dependency.
MCP Server + Database
To query and inspect the database directly, we use an MCP (Model Context Protocol) server. For this workshop, we're using dbhub — an open-source database MCP server that supports Postgres, MySQL, SQL Server, MariaDB, and SQLite.
Once the MCP server is started from the tools panel, two tools become available to Copilot:
execute_sql: Run any SQL query against the databasesearch_objects: Search the database schema for tables, columns, and other objects
With these tools, Copilot can write and execute SQL in plain English — you describe what you want, and Copilot writes the query and runs it.
Security note: Unrestricted database access is risky in production environments. Use a read-only database user, limit permissions to only the schemas Copilot needs, or place a sanitizing proxy in front of the database. The Data Explorer agent covered later in this section demonstrates one safe pattern for scoping what Copilot is allowed to do.
✏️ Exercise: Run a SQL Command
Start the “Databaseˮ MCP Server a. Open
.vscode/mcp.json
Prompt Copilot
#execute_sql Tell me how many users are in the database#execute_sql Insert a new customer in the database named John Smith with random information
✏️ Exercise: Visualization
Ask Copilot
/visualize-database
Runs the skill and outputs an ASCII diagram of the database schema.
✏️ Exercise: "Data Explorer" Custom Agent
Open the "Data Explorer" agent mode
Ask it some general questions about the data a.
Which support agent is most swawmped?Which customer is the most problematicWhat case is the most important to solve right now?
✏️ Exercise: Fix Data Bugs
Look for data bugs in the app
Ask Copilot to diagnose and fix them