Skip to content

Fix: Support schema-qualified table names in column retrieval#93

Open
tripathishivani wants to merge 1 commit intoAzure-Samples:mainfrom
tripathishivani:shivani/bug-fix-mssqlmcp-decribe-table-tool
Open

Fix: Support schema-qualified table names in column retrieval#93
tripathishivani wants to merge 1 commit intoAzure-Samples:mainfrom
tripathishivani:shivani/bug-fix-mssqlmcp-decribe-table-tool

Conversation

@tripathishivani
Copy link
Copy Markdown

The Problem
The current implementation of the run method in the SQL Server MCP node has two primary issues when retrieving table columns:

  1. Schema Ignorance: If a user provides a schema-qualified name (e.g., sales.Customers), the current query fails to return results because it searches for the literal string sales.Customers within the TABLE_NAME column of INFORMATION_SCHEMA.COLUMNS.
  2. Namespace Collision: If the same table name exists in multiple schemas (e.g., dbo.Users and archive.Users), the current logic could return a combined list of columns from both tables, leading to data corruption in the MCP output.

The Solution
This PR updates the table name parsing logic to be schema-aware:

  1. Parsing: It now splits the input tableName string into schema and name components.
  2. Defaulting: It defaults to the dbo schema if no specific schema is provided, ensuring backward compatibility.
  3. Query Accuracy: The SQL query has been updated to filter by both TABLE_NAME and TABLE_SCHEMA.

Changes

  1. Updated run function in MssqlMcp/Node/src/tools/DescribeTableTool.ts
  2. Modified SQL query to use @tableSchema parameter.

Added logic to handle both simple (Users) and qualified (dbo.Users) table names.

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