feat: Add configurable verbose error mode for AI debugging #83
+163
−15
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
The MSSQL MCP server intentionally sanitizes error messages for security, making it impossible for AI agents to debug SQL command failures.
Before:
{ "success": false, "message": "Failed to execute query: Database query execution failed", "error": "SQL_EXECUTION_FAILED" }No actionable information for debugging - AI agents can't identify syntax errors, invalid columns, or table issues.
Solution
Added configurable VERBOSE_ERRORS mode that exposes full SQL error details when enabled while keeping secure defaults for production.
After (VERBOSE_ERRORS=true):
{ "success": false, "message": "Failed to execute query: Invalid object name 'NonexistentTable'.", "error": "SQL_EXECUTION_FAILED", "details": { "code": "EREQUEST", "number": 208, "state": 1, "class": 16, "lineNumber": 1, "serverName": "empoweranalyticssql", "procName": "", "stack": "RequestError: Invalid object name...", "originalError": { "query": "SELECT * FROM NonexistentTable" } } }Changes
Files Added
MssqlMcp/Node/src/utils/errorHandler.ts- Error formatting utilitiesMssqlMcp/Node/VERBOSE_ERRORS.md- Complete documentationFiles Modified
MssqlMcp/Node/src/index.ts- Use formatError() in main handlerMssqlMcp/Node/src/tools/ReadDataTool.ts- Use formatSqlError() for SQL errorsNew Features
isVerboseErrorMode()- Check VERBOSE_ERRORS env varformatError()- Format errors with optional verbose detailsformatSqlError()- SQL-specific error formatting with query contextUsage
Enable in MCP configuration:
{ "mcpServers": { "mssql": { "command": "node", "args": ["/path/to/MssqlMcp/Node/dist/index.js"], "env": { "SERVER_NAME": "your-server.database.windows.net", "DATABASE_NAME": "your-database", "READONLY": "true", "VERBOSE_ERRORS": "true" } } } }Testing
Verified with intentional SQL errors:
✅ Invalid table name (Error #208):
✅ Invalid column name (Error #207):
Security
Impact
For AI Agents:
For Developers:
Related
This enhancement is particularly valuable when using the MCP with:
Tested on: