MCP Multi-Endpoint Architecture
Overview
This issue documents the implementation of multiple dedicated MCP endpoints in ProxySQL, where each endpoint serves a specific purpose with its own tool handler. This architecture allows for:
- Specialized tools per endpoint (config, query, admin, cache, observe)
- Isolated resources (separate handlers can have separate connection pools)
- Independent authentication (per-endpoint Bearer tokens)
- Clear separation of concerns (each endpoint has a well-defined purpose)
Architecture Diagram
┌─────────────────────────────────────────────────────────────────────────────┐
│ ProxySQL Process │
│ │
│ ┌──────────────────────────────────────────────────────────────────────┐ │
│ │ MCP_Threads_Handler │ │
│ │ - Configuration variables (mcp-*) │ │
│ │ - Manages 5 dedicated tool handlers │ │
│ └──────────────────────────────────────────────────────────────────────┘ │
│ │ │
│ ▼ │
│ ┌──────────────────────────────────────────────────────────────────────┐ │
│ │ ProxySQL_MCP_Server │ │
│ │ (Single HTTPS Server) │ │
│ │ │ │
│ │ Port: mcp-port (default 6071) │ │
│ │ SSL: Uses ProxySQL's certificates │ │
│ └──────────────────────────────────────────────────────────────────────┘ │
│ │ │
│ ┌──────────────┬──────────────┼──────────────┬──────────────┬─────────┐ │
│ ▼ ▼ ▼ ▼ ▼ ▼ │
│ ┌────┐ ┌────┐ ┌────┐ ┌────┐ ┌────┐ ┌───┐│
│ │conf│ │obs │ │qry │ │adm │ │cach│ │cat│││
│ │TH │ │TH │ │TH │ │TH │ │TH │ │log│││
│ └─┬──┘ └─┬──┘ └─┬──┘ └─┬──┘ └─┬──┘ └─┬─┘│
│ │ │ │ │ │ │ │
│ │ │ │ │ │ │ │
│ Tools: Tools: Tools: Tools: Tools: │ │
│ - get_config - list_ - list_ - admin_ - get_ │ │
│ - set_config stats schemas - set_ cache │ │
│ - reload - show_ - list_ - reload - set_ │ │
│ - list_vars metrics tables - invalidate│ │
│ - get_status - clear │ │
│ - query - show - warm │ │
│ - explain processes - entries │ │
│ - sample │ │
│ - catalog_* - kill │ │
│ - flush │ │
└─────────────────────────────────────────────────────────────────────────────┘
TH = Tool Handler
Endpoint Specifications
/mcp/config - Configuration Endpoint
Purpose: Runtime configuration and management of ProxySQL
Authentication:mcp-config_endpoint_auth (Bearer token)
Tools:
| Tool | Description | Status |
|---|
get_config | Get current configuration values | ✅ Implemented |
set_config | Modify configuration values | ✅ Implemented |
reload_config | Reload configuration from disk/memory/runtime | ⚠️ Stub |
list_variables | List all available variables | ✅ Implemented |
get_status | Get server status information | ✅ Implemented |
/mcp/observe - Observability Endpoint
Purpose: Real-time metrics, statistics, and monitoring data
Authentication:mcp-observe_endpoint_auth (Bearer token)
Tools:
| Tool | Description | Status |
|---|
list_stats | List available statistics | ❌ Stub |
get_stats | Get specific statistics | ❌ Stub |
show_connections | Show active connections | ❌ Stub |
show_queries | Show query statistics | ❌ Stub |
get_health | Get health check information | ❌ Stub |
show_metrics | Show performance metrics | ❌ Stub |
/mcp/query - Query Endpoint
Purpose: Safe database exploration and query execution
Authentication:mcp-query_endpoint_auth (Bearer token)
Tools:
| Tool | Description | Status |
|---|
list_schemas | List databases | ✅ Implemented |
list_tables | List tables in schema | ✅ Implemented |
describe_table | Get table structure | ✅ Implemented |
get_constraints | Get foreign keys and constraints | ✅ Implemented |
table_profile | Get table statistics | ✅ Implemented |
column_profile | Get column statistics | ✅ Implemented |
sample_rows | Get sample data | ✅ Implemented |
sample_distinct | Sample distinct values | ✅ Implemented |
run_sql_readonly | Execute read-only SQL | ✅ Implemented |
explain_sql | Explain query execution plan | ✅ Implemented |
suggest_joins | Suggest table joins | ✅ Implemented |
find_reference_candidates | Find foreign key references | ✅ Implemented |
catalog_upsert | Store data in catalog | ✅ Implemented |
catalog_get | Retrieve from catalog | ✅ Implemented |
catalog_search | Search catalog | ✅ Implemented |
catalog_list | List catalog entries | ✅ Implemented |
catalog_merge | Merge catalog entries | ✅ Implemented |
catalog_delete | Delete from catalog | ✅ Implemented |
/mcp/admin - Administration Endpoint
Purpose: Administrative operations
Authentication:mcp-admin_endpoint_auth (Bearer token, most restrictive)
Tools:
| Tool | Description | Status |
|---|
admin_list_users | List MySQL users | ❌ Stub |
admin_show_processes | Show running processes | ❌ Stub |
admin_kill_query | Kill a running query | ❌ Stub |
admin_flush_cache | Flush various caches | ❌ Stub |
admin_reload | Reload users/servers configuration | ❌ Stub |
/mcp/cache - Cache Endpoint
Purpose: Query cache management
Authentication:mcp-cache_endpoint_auth (Bearer token)
Tools:
| Tool | Description | Status |
|---|
get_cache_stats | Get cache statistics | ❌ Stub |
invalidate_cache | Invalidate cache entries | ❌ Stub |
set_cache_ttl | Set cache TTL | ❌ Stub |
clear_cache | Clear all cache | ❌ Stub |
warm_cache | Warm up cache with queries | ❌ Stub |
get_cache_entries | List cached queries | ❌ Stub |
File Structure
include/
├── MCP_Tool_Handler.h # Base class for all tool handlers
├── Config_Tool_Handler.h # /mcp/config endpoint handler
├── Query_Tool_Handler.h # /mcp/query endpoint handler
├── Admin_Tool_Handler.h # /mcp/admin endpoint handler
├── Cache_Tool_Handler.h # /mcp/cache endpoint handler
├── Observe_Tool_Handler.h # /mcp/observe endpoint handler
├── MySQL_Tool_Handler.h # Legacy (wrapped by Query_Tool_Handler)
├── MCP_Thread.h # MCP_Threads_Handler (manages all handlers)
├── MCP_Endpoint.h # MCP_JSONRPC_Resource (HTTP endpoint)
└── ProxySQL_MCP_Server.hpp # HTTPS server
lib/
├── Config_Tool_Handler.cpp
├── Query_Tool_Handler.cpp
├── Admin_Tool_Handler.cpp
├── Cache_Tool_Handler.cpp
├── Observe_Tool_Handler.cpp
├── MySQL_Tool_Handler.cpp
├── MCP_Thread.cpp
├── MCP_Endpoint.cpp
└── ProxySQL_MCP_Server.cpp
doc/MCP/
├── Architecture.md # Detailed architecture documentation
├── VARIABLES.md # Configuration variables reference
└── README.md # Module overview
TODO List
Phase 1: Complete Core Implementation ✅
Phase 2: Implement Per-Endpoint Authentication
Phase 3: Implement Admin Tool Handler
Phase 4: Implement Cache Tool Handler
Phase 5: Implement Observe Tool Handler
Phase 6: Complete Config Tool Handler
Phase 7: Testing & Validation
Phase 8: Documentation
Phase 9: Optional Enhancements
Testing Commands
# Test each endpoint's tools
curl -k -X POST https://127.0.0.1:6071/mcp/config \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"tools/list","id":1}'
curl -k -X POST https://127.0.0.1:6071/mcp/query \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"tools/list","id":1}'# Call a tool
curl -k -X POST https://127.0.0.1:6071/mcp/config \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"tools/call","params":{"name":"get_status","arguments":{}},"id":1}'Related Files
- Implementation:
include/MCP_*.h, lib/MCP_*.cpp - Documentation:
doc/MCP/Architecture.md - Variables:
doc/MCP/VARIABLES.md - Test Script:
scripts/mcp/test_mcp_tools.sh - Configuration Script:
scripts/mcp/configure_mcp.sh
Reference
MCP Multi-Endpoint Architecture
Overview
This issue documents the implementation of multiple dedicated MCP endpoints in ProxySQL, where each endpoint serves a specific purpose with its own tool handler. This architecture allows for:
Architecture Diagram
Endpoint Specifications
/mcp/config- Configuration EndpointPurpose: Runtime configuration and management of ProxySQL
Authentication:
mcp-config_endpoint_auth(Bearer token)Tools:
get_configset_configreload_configlist_variablesget_status/mcp/observe- Observability EndpointPurpose: Real-time metrics, statistics, and monitoring data
Authentication:
mcp-observe_endpoint_auth(Bearer token)Tools:
list_statsget_statsshow_connectionsshow_queriesget_healthshow_metrics/mcp/query- Query EndpointPurpose: Safe database exploration and query execution
Authentication:
mcp-query_endpoint_auth(Bearer token)Tools:
list_schemaslist_tablesdescribe_tableget_constraintstable_profilecolumn_profilesample_rowssample_distinctrun_sql_readonlyexplain_sqlsuggest_joinsfind_reference_candidatescatalog_upsertcatalog_getcatalog_searchcatalog_listcatalog_mergecatalog_delete/mcp/admin- Administration EndpointPurpose: Administrative operations
Authentication:
mcp-admin_endpoint_auth(Bearer token, most restrictive)Tools:
admin_list_usersadmin_show_processesadmin_kill_queryadmin_flush_cacheadmin_reload/mcp/cache- Cache EndpointPurpose: Query cache management
Authentication:
mcp-cache_endpoint_auth(Bearer token)Tools:
get_cache_statsinvalidate_cacheset_cache_ttlclear_cachewarm_cacheget_cache_entriesFile Structure
TODO List
Phase 1: Complete Core Implementation ✅
Phase 2: Implement Per-Endpoint Authentication
authenticate_request()in MCP_Endpoint.cppmcp-{endpoint}_endpoint_authvariables for validationPhase 3: Implement Admin Tool Handler
admin_list_users- Querymysql_userstableadmin_show_processes- Querystats_mysql_connection_poolor similaradmin_kill_query- Implement KILL QUERY functionalityadmin_flush_cache- Implement cache flush commandsadmin_reload- Implement LOAD USERS/SERVERS TO RUNTIMEPhase 4: Implement Cache Tool Handler
get_cache_stats- Query cache statistics fromstats_mysql_query_cacheinvalidate_cache- Implement cache invalidationset_cache_ttl- Configure cache TTL settingsclear_cache- Clear all cache entrieswarm_cache- Execute queries to warm up cacheget_cache_entries- List cached queriesPhase 5: Implement Observe Tool Handler
list_stats- List all available ProxySQL statisticsget_stats- Get specific statistic valuesshow_connections- Query connection pool statisticsshow_queries- Query query statistics fromstats_mysql_queries_digestget_health- Aggregate health check (backend status, etc.)show_metrics- Query Prometheus metricsPhase 6: Complete Config Tool Handler
reload_config- Implement proper Admin_FlushVariables integrationPhase 7: Testing & Validation
tools/listtools/callPhase 8: Documentation
Phase 9: Optional Enhancements
describe_view)Testing Commands
Related Files
include/MCP_*.h,lib/MCP_*.cppdoc/MCP/Architecture.mddoc/MCP/VARIABLES.mdscripts/mcp/test_mcp_tools.shscripts/mcp/configure_mcp.shReference