Updated: January 15, 2026 (v2.2)
test_mcp_client.py tests the SQL Safety Checker MCP server via the MCP protocol using FastMCP's Client API.
Supported Databases: MySQL, SQLite (v2.2+)
SCHEMA_TOOLS_ENABLED = os.getenv("ENABLE_SCHEMA_TOOLS", "1") == "1"
TABLE_SUMMARY_ENABLED = os.getenv("ENABLE_TABLE_SUMMARY", "0") == "1"
TEST_SAMPLE_LIMIT = 3 # Sample data row limit| Feature | test_mcp_functions.py | test_mcp_client.py |
|---|---|---|
| Test Method | Direct function calls | FastMCP Client via MCP protocol |
| Server Startup | Not required | Automatically managed by FastMCP |
| Data Serialization | Manual serialization | Automatic via FastMCP |
| Purpose | Validate business logic | Validate protocol communication |
-
Install dependencies:
pip install -r requirements.txt
-
Configure environment variables (
.envfile):For MySQL:
DB_TYPE=mysql DB_USER=your_db_user DB_PASSWORD=your_db_password DB_HOST=your_db_host DB_NAME=your_db_name ENABLE_SCHEMA_TOOLS=1
For SQLite:
DB_TYPE=sqlite SQLITE_DATABASE_PATH=./my_database.db # or :memory: for in-memory database ENABLE_SCHEMA_TOOLS=1
python test_mcp_client.py======================================================================
MCP CLIENT TEST - SQL Safety Checker MCP Server
======================================================================
Server script: /path/to/start_server.py
Schema tools enabled: True
Table summary enabled: False
✓ Successfully connected to MCP server
Available tools: ['query', 'check_connection', 'list_tables', 'describe_table', 'get_full_schema', 'sample']
----------------------------------------------------------------------
TEST 1: check_connection
----------------------------------------------------------------------
{
"connected": true,
"message": "Database connection successful",
"db_type": "mysql"
}
----------------------------------------------------------------------
TEST 2: list_tables
----------------------------------------------------------------------
{
"success": true,
"db_type": "mysql",
"database_name": "mydb",
"returned_table_count": 2,
"total_tables": 2,
"tables": [
{"table_name": "test_users", "row_count": 2},
{"table_name": "products", "row_count": 100}
],
"row_count_approximate": true,
"truncated": false,
"truncation_note": null
}
✓ All new fields present: returned_table_count=2, total_tables=2, db_type=mysql
----------------------------------------------------------------------
TEST 3: query (Primary Tool)
----------------------------------------------------------------------
Query 1: SELECT 1 as test
{
"success": true,
"db_type": "mysql",
"data": [{"test": 1}],
"row_count": 1,
"query": "SELECT 1 as test"
}
📝 Verify: 'data' field is [{'test': 1}] not [[1]]
The script tests the following tools:
- ✅
check_connection- Database connectivity test (includesdb_typefield) - ✅
list_tables- Database overview with new fields (returned_table_count,total_tables,truncated,db_type) - ✅
query- SQL execution (Primary Tool):- Simple SELECT query
- COUNT query
- Unsafe query rejection
- ✅
describe_table- Table structure with row count estimate andis_largehint - ✅
get_full_schema- Complete database schema in one call - ✅
get_table_summary- Table statistics with optional exact count (requiresENABLE_TABLE_SUMMARY=1) - ✅
sample- Sample data retrieval (requiresENABLE_SCHEMA_TOOLS=1)
Note: All tool responses include db_type field ("mysql" or "sqlite") since v2.2.
Note: SQL validation tests are also covered in test_mcp_functions.py.
- ❌ Incorrect:
"data": [[1]](2D array) - ✅ Correct:
"data": [{"test": 1}](array of objects)
{
"success": false,
"error": "Only SELECT queries are allowed",
"query": "DELETE FROM users"
}pip install fastmcpEnsure start_server.py is in the same directory.
If sample is not available:
# Set in .env file
ENABLE_SCHEMA_TOOLS=1After modifying MCP tools:
-
Run direct tests:
python test_mcp_functions.py
-
Run protocol tests:
python test_mcp_client.py
-
Compare output with README documentation
- README.md - Complete project documentation
- MCP Protocol Documentation - Official protocol specification