8000 fix(tool/spanner-list-tables): return constraint key columns as separate JSON array elements by beskvladimir-create · Pull Request #4603 · googleapis/mcp-toolbox · GitHub
[go: up one dir, main page]

Skip to content

fix(tool/spanner-list-tables): return constraint key columns as separate JSON array elements - #4603

Open
beskvladimir-create wants to merge 4 commits into
googleapis:mainfrom
beskvladimir-create:fix/spanner-list-tables-constraint-columns
Open

beskvladimir-create wants to merge 4 commits into
googleapis:mainfrom
beskvladimir-create:fix/spanner-list-tables-constraint-columns

Conversation

@beskvladimir-create
Copy link
Copy Markdown
Contributor

Description

spanner-list-tables and the prebuilt spanner-postgres list_tables use one aggregate, constraint_columns_agg_cte.column_names_json_list, both inside constraint_definition and as the JSON array of constraint_columns / foreign_key_referenced_columns:

  • spanner-list-tables (GoogleSQL and PostgreSQL dialects): the list holds bare names and the joined string is wrapped in one pair of quotes, so PRIMARY KEY (singer_id, album_id) comes back as "constraint_columns":["singer_id,album_id"], and constraints without (referenced) columns get [""] instead of [].
  • Prebuilt spanner-postgres list_tables: the list holds quoted names, which is right for the arrays but produces "constraint_definition":"PRIMARY KEY ("id")". processRows in the Spanner source runs json.Unmarshal on every object_details value, so the detailed output fails with unable to unmarshal JSON for any table with a primary key.

Fix: constraint_columns_agg_cte now keeps both a bare list (for constraint_definition) and a quoted list (for the JSON arrays):

  • spanner-list-tables: new quoted_column_names_json_list, used for constraint_columns and foreign_key_referenced_columns without the extra surrounding quotes. constraint_definition is unchanged.
  • spanner-postgres.yaml: new bare column_names_list, used in the four places where constraint_definition concatenates key columns. The arrays are unchanged.

Columns, indexes and simple output are not affected.

Testing: I copied the PostgreSQL-dialect string-building expressions (old and new) into psql on PostgreSQL 16.15 with sample key-column rows and parsed the output with a JSON parser: before, the prebuilt output did not parse and the tool output had ["singer_id,album_id"]; after, both give "constraint_columns":["singer_id","album_id"], "foreign_key_referenced_columns":["singer_id"] and [] for constraints without columns. The GoogleSQL statement uses the same pattern and was only checked by reading. I added runSpannerListTablesConstraintColumnsTest to TestSpannerToolEndpoints; it checks the composite primary key (id, target_id) and the foreign key of the existing interleaved edge table. I could not run Spanner or the Go integration tests locally, so the test relies on CI.

Security: no new parameters; the tool still binds table_names and output_format as query parameters and the change only affects how catalog values are concatenated into the JSON string.

PR Checklist

  • Make sure you reviewed CONTRIBUTING.md
  • Make sure to open an issue as a bug/issue before writing your code!
  • Ensure you have manually reviewed the entire diff before requesting a review
  • 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 (not a breaking change)

🛠️ Fixes #4602

@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 spanner-postgres and spanner-list-tables tools to correctly handle multi-column constraints by introducing a new quoted_column_names_json_list field. This ensures that composite key columns are returned as individual elements in the JSON output. Additionally, a new integration test, runSpannerListTablesConstraintColumnsTest, was added to verify that primary and foreign key constraints with multiple columns are correctly parsed and returned by the tool.

This branch has not been deployed

No deployments
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.

spanner list_tables: composite key constraint_columns come back as one string, and the prebuilt spanner-postgres list_tables returns invalid JSON

2 participants

0