Debugging Databases & SQL

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 database

  • search_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

  1. Start the “Databaseˮ MCP Server a. Open .vscode/mcp.json

  1. Prompt Copilot

    1. #execute_sql Tell me how many users are in the database
    2. #execute_sql Insert a new customer in the database named John Smith with random information

✏️ Exercise: Visualization

  1. Ask Copilot

    1. /visualize-database

       

Runs the skill and outputs an ASCII diagram of the database schema.

✏️ Exercise: "Data Explorer" Custom Agent

  1. Open the "Data Explorer" agent mode

  2. Ask it some general questions about the data a.

    1. Which support agent is most swawmped?
    2. Which customer is the most problematic
    3. What case is the most important to solve right now?

✏️ Exercise: Fix Data Bugs

  1. Look for data bugs in the app

  1. Ask Copilot to diagnose and fix them

 

 


Next: Debugging With Copilot | Wrapping Up