Skip to content

Conversation

designcomputer
Copy link
Owner

@designcomputer designcomputer commented Apr 18, 2025

Fix: Handle Result Sets for SHOW, CREATE TABLE, and DESCRIBE Commands

Problem

When executing SHOW INDEX FROM table_name, SHOW CREATE TABLE table_name, or DESCRIBE table_name through the MCP tool, it returns an error: "Error executing query: Unread result found". This happens because the code was specifically checking for queries that start with "SELECT" rather than checking if the query returns a result set.

Solution

This PR changes the condition from checking the query syntax (query.strip().upper().startswith("SELECT")) to checking the existence of a result set (cursor.description is not None). This makes the code more robust and allows it to handle all types of queries that return result sets, not just SELECT queries.

Additionally, it adds more robust error handling for result fetching operations and improves debug output.

Changes Made

  1. Changed the condition from:
elif query.strip().upper().startswith("SELECT"):

To:

elif cursor.description is not None:
  1. Added error handling for fetchall():
try:
    rows = cursor.fetchall()
    # Process rows...
except Error as e:
    logger.warning(f"Error fetching results: {str(e)}")
    return [TextContent(type="text", text=f"Query executed but error fetching results: {str(e)}")]
  1. Added additional debug output to stderr for better troubleshooting

Testing

I've tested this change with various command types:

  • SELECT queries: Work as before
  • SHOW CREATE TABLE: Now works correctly
  • SHOW INDEX: Now works correctly
  • DESCRIBE: Now works correctly

Related Issues

This PR addresses PR #7 which introduced a similar fix but didn't include the additional error handling.

@designcomputer designcomputer merged commit 799be6c into main Apr 18, 2025
2 checks passed
@designcomputer designcomputer deleted the fix/handle-show-describe-commands branch April 18, 2025 20:18
hyemin916 pushed a commit to hyemin916/mysql_mcp_server that referenced this pull request Aug 29, 2025
- Add support for Unix socket connections via MYSQL_SOCKET_PATH env var
- Automatically detect and use socket connection when MYSQL_SOCKET_PATH is set
- Fix TypeScript build errors caused by duplicate variable declarations in evals.ts
- Update documentation with Unix socket example
- Add integration tests for Unix socket connections
- Update Smithery configuration to support socket connections
- Maintain backward compatibility with existing TCP/IP connections

Handles designcomputer#37, Fixes designcomputer#46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant