Skip to content

Multi-Agent Database Discovery System using Claude Code#12

Merged
renecannao merged 6 commits intov3.1-MCP1_discoveryfrom
v3.1-MCP1_discovery_cc1
Jan 16, 2026
Merged

Multi-Agent Database Discovery System using Claude Code#12
renecannao merged 6 commits intov3.1-MCP1_discoveryfrom
v3.1-MCP1_discovery_cc1

Conversation

@renecannao
Copy link
Copy Markdown

Multi-Agent Database Discovery System

Overview

This PR implements a multi-agent database discovery system using Claude Code's autonomous agent capabilities. The system uses 4 specialized subagents that collaborate via the MCP (Model Context Protocol) catalog to perform comprehensive database analysis.

The Four Discovery Agents

Agent Mission Catalog Entries
Structural Map tables, relationships, indexes, constraints 11 entries
Statistical Profile data distributions, patterns, anomalies 16 entries
Semantic Infer business domain and entity types 8 entries
Query Analyze access patterns and optimization 5 entries

Key Features

  • Parallel Execution: All 4 agents run simultaneously
  • Catalog-Based Collaboration: Agents share findings via MCP catalog
  • 4-Round Discovery Process: Blind → Pattern → Hypothesis → Synthesis
  • Comprehensive Output: 40+ catalog entries + executive summary

Files Added

  • doc/multi_agent_database_discovery.md - Complete system documentation
  • simple_discovery.py - Simplified demo of multi-agent pattern

Example Discovery Output

Database: testdb (E-commerce Order Management)

Critical Findings

  • Data Quality: 5/100 (Catastrophic) - 67% data triplication
  • Missing Index: orders.order_date (P0 critical)
  • Missing Constraints: No UNIQUE or FK constraints
  • Business Domain: E-commerce order management system

True Statistics (After Deduplication)

Metric Current Actual
Customers 15 5
Products 15 5
Orders 15 5
Order Items 27 9
Revenue $10,886.67 $3,628.85

Related Work

  • Issue: Using Claude Code as database discovery agent
  • Base branch: v3.1-MCP1_discovery

Future Commits

This is the first commit on this branch. Additional commits will follow to:

  • Add automated remediation scripts
  • Implement continuous monitoring mode
  • Add web-based dashboard
  • Integration with CI/CD pipelines

Note: This PR demonstrates Claude Code's capability to use autonomous subagents for complex database analysis tasks. All findings are stored in the MCP catalog for cross-agent collaboration.

The catalog_search() and catalog_list() methods in MySQL_Catalog.cpp
were manually building JSON strings by concatenating raw TEXT from
SQLite without proper escaping. This caused parse errors when stored
JSON contained quotes, backslashes, or newlines.

Changes:
- MySQL_Catalog.cpp: Use nlohmann::json to build proper nested JSON
  in search() and list() methods instead of manual concatenation
- MySQL_Tool_Handler.cpp: Add try-catch for JSON parsing in catalog_get()
- test_catalog.sh: Fix MCP URL path, add jq extraction for MCP protocol
  responses, add 3 special character tests (CAT013-CAT015)

Test Results: All 15 catalog tests pass, including new tests that
verify special characters (quotes, backslashes) are preserved.
Implements a 4-agent collaborative system using Claude Code's
Task tool and MCP catalog for comprehensive database analysis:

- Structural Agent: Maps tables, relationships, indexes, constraints
- Statistical Agent: Profiles data distributions, patterns, anomalies
- Semantic Agent: Infers business domain and entity types
- Query Agent: Analyzes access patterns and optimization

Agents collaborate via MCP catalog across 4 rounds:
1. Blind exploration → 2. Pattern recognition →
3. Hypothesis testing → 4. Final synthesis

Includes simple_discovery.py demo and comprehensive documentation.
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Jan 14, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.


Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello @renecannao, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a powerful multi-agent system designed to perform in-depth database discovery and analysis. By orchestrating specialized AI agents that communicate and share findings via a Model Context Protocol (MCP) catalog, the system can identify structural details, statistical patterns, semantic meaning, and query optimization opportunities within a database. The changes also include improvements to the underlying MCP catalog's JSON handling capabilities and provide clear documentation and a practical demonstration of the new architecture.

Highlights

  • Multi-Agent Database Discovery System: Introduction of a new system utilizing Claude Code's autonomous agent capabilities for comprehensive database analysis.
  • Specialized Subagents: The system employs four distinct subagents (Structural, Statistical, Semantic, Query) that collaborate through an MCP catalog to perform their specific analysis missions.
  • Iterative Discovery Process: A structured 4-round discovery process (Blind Exploration, Pattern Recognition, Hypothesis Testing, Final Synthesis) is implemented for thorough and collaborative analysis.
  • Enhanced JSON Handling in MCP Catalog: The MySQL_Catalog and MySQL_Tool_Handler C++ components now use the nlohmann::json library for more robust parsing and serialization of JSON documents within the MCP catalog, particularly for handling special characters and complex structures.
  • New Documentation and Demo: A detailed documentation file (doc/multi_agent_database_discovery.md) and a simplified Python demo script (simple_discovery.py) have been added to explain and illustrate the multi-agent pattern.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a multi-agent database discovery system, including comprehensive documentation and a Python demo. The C++ changes are a significant improvement, replacing manual JSON string construction with the robust nlohmann/json library, which greatly improves correctness and safety, especially when handling special characters. The addition of corresponding test cases in test_catalog.sh is also excellent.

My review includes a few suggestions:

  • In the C++ code, I've suggested a minor refactoring to use modern range-based for loops for better readability.
  • In the new Python demo script, there's a potential IndexError that should be addressed.
  • The architecture diagram in the documentation could be clarified to avoid confusion about the catalog component.

Overall, this is a solid contribution that adds a powerful new capability and improves the existing codebase.


print("📊 SYNTHESIZED FINDINGS:")
print("-" * 60)
print(f"Table: {structure[0]['document']['table']}")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Directly accessing structure[0] here is unsafe and will raise an IndexError if the catalog.get_kind('structure') call returned an empty list. You should add a check to ensure structure and data are not empty before proceeding to access their elements.

Comment on lines +9 to +32
```
┌─────────────────────────────────────────────────────────────────────┐
│ Main Agent (Orchestrator) │
│ - Launches 4 specialized subagents in parallel │
│ - Coordinates via MCP catalog │
│ - Synthesizes final report │
└────────────────┬────────────────────────────────────────────────────┘
┌────────────┼────────────┬────────────┬────────────┐
│ │ │ │ │
▼ ▼ ▼ ▼ ▼
┌────────┐ ┌────────┐ ┌────────┐ ┌────────┐ ┌────────┐
│Struct. │ │Statist.│ │Semantic│ │Query │ │ MCP │
│ Agent │ │ Agent │ │ Agent │ │ Agent │ │Catalog │
└────────┘ └────────┘ └────────┘ └────────┘ └────────┘
│ │ │ │ │
└────────────┴────────────┴────────────┴────────────┘
▼ ▼
┌─────────┐ ┌─────────────┐
│ Database│ │ Catalog │
│ (testdb)│ │ (Shared Mem)│
└─────────┘ └─────────────┘
```
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The architecture diagram is a bit confusing regarding the catalog. It shows an 'MCP Catalog' box at the same level as the agents, and also a 'Catalog (Shared Mem)' box at the bottom that the agents interact with. This suggests there might be two different catalogs. Could you clarify if these are the same entity and perhaps simplify the diagram to show a single, shared catalog that all agents communicate with via MCP?

Comment on lines 228 to 229
for (std::vector<SQLite3_row*>::iterator it = resultset->rows.begin();
it != resultset->rows.end(); ++it) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For improved readability and to use a more modern C++ idiom, you could replace the traditional iterator-based for loop with a range-based for loop.

for (SQLite3_row* row : resultset->rows) {

Comment on lines 301 to 302
for (std::vector<SQLite3_row*>::iterator it = resultset->rows.begin();
it != resultset->rows.end(); ++it) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Similar to the search method, this traditional for loop can be simplified by using a more modern C++ range-based for loop. This enhances code readability and maintainability.

for (SQLite3_row* row : resultset->rows) {

Implement scripts for running Claude Code in non-interactive mode
to perform comprehensive database discovery on any database.

Files added:
- headless_db_discovery.sh: Bash script implementation
- headless_db_discovery.py: Python script implementation (recommended)
- HEADLESS_DISCOVERY_README.md: Comprehensive documentation

Features:
- Works with any database accessible via MCP
- Database-agnostic discovery prompt
- Comprehensive analysis: structure, data, semantics, performance
- Markdown report output with ERD, data quality score, recommendations
- CI/CD integration ready
- Supports custom MCP server configuration
- Configurable timeout, output, verbosity

Usage:
  python scripts/headless_db_discovery.py --database mydb
Move headless database discovery scripts from scripts/ to
scripts/mcp/DiscoveryAgent/ClaudeCode_Headless/ for better organization.

Also update README to:
- Focus only on ProxySQL Query MCP (remove generic database examples)
- Use relative paths (./) instead of absolute paths
- Simplify configuration documentation

Files moved:
- scripts/HEADLESS_DISCOVERY_README.md
- scripts/headless_db_discovery.py
- scripts/headless_db_discovery.sh
…covery

- Add DATABASE_DISCOVERY_REPORT.md: Complete multi-agent database discovery
  findings covering structure, statistics, business domain, and query analysis
- Add DATABASE_QUESTION_CAPABILITIES.md: Showcase of 14 question categories
  answerable via the discovery system with examples
- Enhance headless_db_discovery.py: Improve JSON parsing and error handling
- Enhance headless_db_discovery.sh: Add better argument handling and validation
Relocate DATABASE_DISCOVERY_REPORT.md and DATABASE_QUESTION_CAPABILITIES.md
to scripts/mcp/DiscoveryAgent/ClaudeCode_Headless/examples/ for better organization.
@renecannao renecannao merged commit 7665b3b into v3.1-MCP1_discovery Jan 16, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant