Skip to content

fix: scope MySQL list_tables to configured database#3490

Open
luohui1 wants to merge 1 commit into
googleapis:mainfrom
luohui1:codex/2212-mysql-list-tables-db-scope-20260622
Open

fix: scope MySQL list_tables to configured database#3490
luohui1 wants to merge 1 commit into
googleapis:mainfrom
luohui1:codex/2212-mysql-list-tables-db-scope-20260622

Conversation

@luohui1

@luohui1 luohui1 commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Description

Scopes the MySQL list_tables query 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

  • Make sure you reviewed
    CONTRIBUTING.md
  • Make sure to open an issue as a
    bug/issue
    before writing your code! That way we can discuss the change, evaluate
    designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)
  • Make sure to add ! if this involve a breaking change

Testing

  • go test ./internal/tools/mysql/mysqllisttables -count=1
  • go test ./internal/tools/mysql/mysqllisttables -run 'TestInvokeScopesListTablesToConfiguredDatabase|TestInvokePreservesUnscopedBehaviorWithoutConfiguredDatabase' -count=1
  • go test ./internal/server/mcp/jsonrpc ./internal/tools/mysql/mysqllisttables -count=1

AI disclosure: this PR was prepared by Codex (GPT-5) acting as an AI coding agent on behalf of @luohui1.

Fixes #2212

@luohui1 luohui1 requested review from a team as code owners June 22, 2026 10:44

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
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))

@luohui1 luohui1 force-pushed the codex/2212-mysql-list-tables-db-scope-20260622 branch from 027edc4 to bf85821 Compare June 22, 2026 10:45
@luohui1 luohui1 force-pushed the codex/2212-mysql-list-tables-db-scope-20260622 branch from bf85821 to f1cd60c Compare June 22, 2026 10:48
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.

cloud-sql-mysql prebuilt tools queries to entire instance instead of configured database in that instance

2 participants