fix: scope MySQL list_tables to configured database#3490
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the list_tables tool for MySQL and Cloud SQL MySQL to scope table listing to the configured database when available, falling back to all user schemas if no database is configured. It updates the compatibleSource interface, the SQL query, and adds corresponding unit tests. The reviewer suggested using TRIM(@connected_schema) in the SQL comparison to ensure robust matching against accidental whitespace.
| CROSS JOIN (SELECT @table_names := ?, @output_format := ?, @connected_schema := ?) AS variables | ||
| WHERE | ||
| T.TABLE_SCHEMA NOT IN ('mysql', 'information_schema', 'performance_schema', 'sys') | ||
| AND (NULLIF(TRIM(@connected_schema), '') IS NULL OR T.TABLE_SCHEMA = @connected_schema) |
There was a problem hiding this comment.
To ensure robust matching even if the configured database name contains accidental leading or trailing whitespace (e.g., from environment variables or configuration files), use TRIM(@connected_schema) in the comparison as well, matching the TRIM used in the NULLIF check.
| AND (NULLIF(TRIM(@connected_schema), '') IS NULL OR T.TABLE_SCHEMA = @connected_schema) | |
| AND (NULLIF(TRIM(@connected_schema), '') IS NULL OR T.TABLE_SCHEMA = TRIM(@connected_schema)) |
027edc4 to
bf85821
Compare
bf85821 to
f1cd60c
Compare
Description
Scopes the MySQL
list_tablesquery to the configured source database when one is set, so Cloud SQL MySQL prebuilt tools no longer list tables from every database in the instance.The existing all-user-schemas behavior is preserved for sources without a configured database. This also updates the prebuilt tool descriptions and MCP schema expectation to describe the configured-database default.
PR Checklist
CONTRIBUTING.md
bug/issue
before writing your code! That way we can discuss the change, evaluate
designs, and agree on the general idea
!if this involve a breaking changeTesting
go test ./internal/tools/mysql/mysqllisttables -count=1go test ./internal/tools/mysql/mysqllisttables -run 'TestInvokeScopesListTablesToConfiguredDatabase|TestInvokePreservesUnscopedBehaviorWithoutConfiguredDatabase' -count=1go test ./internal/server/mcp/jsonrpc ./internal/tools/mysql/mysqllisttables -count=1AI disclosure: this PR was prepared by Codex (GPT-5) acting as an AI coding agent on behalf of @luohui1.
Fixes #2212