Skip to content

Conversation

rocknroll17
Copy link
Contributor

This PR was made from #10

Overview

This PR introduces essential query performance analysis capabilities to the MariaDB MCP Server by adding explain_query and explain_query_extended tools.

Features Added

🔍 explain_query Tool

  • Executes EXPLAIN statements to analyze SQL query execution plans
  • Provides insights into table access methods, index usage, and join strategies
  • Returns structured execution plan data for performance optimization

🔍 explain_query_extended Tool

  • Executes EXPLAIN EXTENDED for comprehensive query analysis
  • Includes additional performance metrics like filtered row percentages
  • Enables deep performance analysis for complex optimization scenarios

Why This Matters

Database queries can vary dramatically in performance - a single line change can transform a millisecond query into one that runs indefinitely. In complex, large-scale databases, query optimization tools are not just helpful but essential for:

  • Preventing System Overload: Analyze potentially expensive queries before execution
  • Optimizing Performance: Transform inefficient queries through subquery restructuring and join optimization
  • Resource Management: Understand query resource consumption patterns
  • Development Efficiency: Enable developers to write performant queries from the start

Implementation Details

Security & Safety

  • ✅ Supports parameterized queries with proper SQL injection protection
  • ✅ Respects read-only mode restrictions
  • ✅ Comprehensive error handling and logging
  • ✅ Input validation for database and query parameters

API Design

# Basic query analysis
async def explain_query(
    sql_query: str, 
    database_name: str, 
    parameters: Optional[List[Any]] = None
) -> List[Dict[str, Any]]

# Extended query analysis  
async def explain_query_extended(
    sql_query: str,
    database_name: str, 
    parameters: Optional[List[Any]] = None
) -> List[Dict[str, Any]]

Integration

🔗 Seamlessly integrates with existing MCP tool ecosystem
🔗 Follows established patterns from execute_sql implementation
🔗 Consistent error handling and logging approach
🔗 Compatible with current FastMCP framework structure

Impact

This enhancement transforms the MariaDB MCP Server from a basic query execution tool into a comprehensive database performance management platform. These tools are fundamental requirements for any serious database administration and development workflow.

Future Enhancements

  • Query optimization suggestions based on execution plans
  • Performance benchmarking capabilities
  • Integration with query caching strategies
  • Automated index recommendation system

Note: These tools are considered essential infrastructure for database performance management and represent a critical gap that needed to be filled in the current MCP server implementation.

rocknroll17 and others added 3 commits July 1, 2025 22:32
- Allow running without EMBEDDING_PROVIDER configuration
- Disable embedding tools when no provider is set
- Update README with optional embedding examples
- Add integration docs for pre-running servers

Fixes runtime errors for database-only usage
feat: make embedding services optional
@rocknroll17
Copy link
Contributor Author

Please merge this PR with squash merge. Cause I did a rebase and it became commit log kinda messy.
Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant