Issue Analysis: Zero Results from List Tables Command
Problem Statement
The hana_tables (and similar list commands) returns zero results when called through the MCP server.
Root Cause
The issue is not with the **CURRENT_SCHEMA** transformation logic, which works correctly. The actual problem is:
Missing database connection configuration
The hana-cli tools require a default-env.json file (or equivalent environment configuration) containing SAP HANA connection credentials. Without this configuration:
- The connection is created but with
undefinedoptions - Database queries execute but fail silently
- No results are returned, appearing as "zero results"
Technical Details
What Works ✓
- The
**CURRENT_SCHEMA**placeholder replacement logic (inutils/database/databaseInspect.js) - The default parameter handling in the MCP server
- The SQL query construction
- The command execution flow
What Was Missing ✗
- Clear error messaging when database connection is not configured
- Validation that connection credentials are present before executing queries
- Documentation about the connection setup requirement
Solution Implemented
1. Enhanced Error Handling
Added validation in utils/base.js to check for valid connection configuration:
// Validate that we have a proper connection configuration
if (!this.options || !this.options.hana || !this.options.hana.host) {
throw new Error('No valid database connection configuration found. Please create a default-env.json file or set up environment variables.')
}2. Schema Validation
Added check in utils/database/databaseInspect.js to ensure schema is not empty:
// Validate schema is not empty
if (!schema1 || schema1.trim() === '') {
throw new Error('Unable to determine current schema. Please check your database connection configuration.')
}3. Debug Logging
Enhanced the MCP server with debug logging to help diagnose issues:
if (args.debug) {
console.error('[DEBUG] hana_tables args:', JSON.stringify(args, null, 2));
console.error('[DEBUG] Calling tables.default with:', JSON.stringify(tableArgs, null, 2));
console.error('[DEBUG] Result type:', typeof result);
}4. Documentation
Created comprehensive troubleshooting guide: mcp-server/TROUBLESHOOTING.md
How to Fix for Users
Users experiencing zero results should:
Set up database connection using one of these methods:
bash# Method 1: Via service key (recommended) hana-cli serviceKey -i <instance-name> -k <key-name> # Method 2: Interactive setup hana-cli connectVerify connection:
bashhana-cli statusCheck configuration file exists:
default-env.jsonshould be in the project root- Should contain valid HANA credentials
Testing
All improvements have been tested:
- ✓ Error handling with missing configuration
- ✓ Proper error messages guide users to solution
- ✓ Schema transformation logic remains functional
- ✓ Debug mode provides diagnostic information
Files Modified
utils/base.js- Added connection validationutils/database/databaseInspect.js- Added schema validationmcp-server/src/index.ts- Added debug loggingmcp-server/README.md- Added prerequisite documentationmcp-server/TROUBLESHOOTING.md- New troubleshooting guide