Skip to content

Fix Postgres data-plane params and add multi-schema table listing#2864

Open
vcolin7 wants to merge 5 commits into
mainfrom
vcolin7/postgres-dataplane-schema-fixes
Open

Fix Postgres data-plane params and add multi-schema table listing#2864
vcolin7 wants to merge 5 commits into
mainfrom
vcolin7/postgres-dataplane-schema-fixes

Conversation

@vcolin7

@vcolin7 vcolin7 commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Cleans up the PostgreSQL data-plane service surface and unblocks listing tables that live outside the public schema.

Why: The data-plane methods threaded subscriptionId/resourceGroup through to code that connects directly to Postgres via Npgsql and never used them, and azmcp postgres list could only ever see tables in the public schema because the schema was hardcoded in the query.

Approach:

  • #471 (unused params): Removed subscriptionId and resourceGroup from ListDatabasesAsync, ExecuteQueryAsync, ListTablesAsync, and GetTableSchemaAsync on both IPostgresService and PostgresService, and updated every caller.

  • #469 (multi-schema listing): Added an optional --schema option (defaults to public for backward compatibility) on the table-listing path. ListTablesAsync now takes a schema argument and runs a parameterized query so the schema is never interpolated:

    SELECT table_name FROM information_schema.tables WHERE table_schema = @schema ORDER BY table_name;

GitHub issue number?

Pre-merge Checklist

  • Required for All PRs
    • Read contribution guidelines
    • PR title clearly describes the change
    • Commit history is clean with descriptive messages
    • Added comprehensive tests for new/modified functionality
    • Created a changelog entry if the change falls among the following: new feature, bug fix, UI/UX update, breaking change, or updated dependencies
  • For MCP tool changes:
    • One tool per PR: This PR modifies only the PostgreSQL tool
    • Updated servers/Azure.Mcp.Server/README.md and/or servers/Fabric.Mcp.Server/README.md documentation — N/A (no surface/description rename; only an added optional option)
    • Validate README.md changes running the script ./eng/scripts/Process-PackageReadMe.ps1 — N/A
    • For new or modified tool descriptions, ran ToolDescriptionEvaluator — N/A (tool description unchanged)
    • For tools with new names, update consolidated-tools.json — N/A (no new/renamed tools)
    • For renamed tools, follow the Tool Rename Checklist — N/A
    • For new tools associated with Azure services, add URL to documentation — N/A
  • Extra steps for Azure MCP Server tool changes:
    • Updated command list in servers/Azure.Mcp.Server/docs/azmcp-commands.md
    • Ran ./eng/scripts/Update-AzCommandsMetadata.ps1 to update tool metadata — please run/verify in CI
    • Updated test prompts in servers/Azure.Mcp.Server/docs/e2eTestPrompts.md

Invoking Livetests

Copilot submitted PRs are not trustworthy by default. Users with write access to the repo need to validate the contents of this PR before leaving a comment with the text /azp run mcp - pullrequest - live. This will trigger the necessary livetest workflows to complete required validation.

Resolves #471 by removing the unused subscriptionId and resourceGroup
parameters from the ListDatabasesAsync, ExecuteQueryAsync, ListTablesAsync
and GetTableSchemaAsync data-plane methods (these connect directly via
Npgsql) and updating all callers. ARM server-config methods and the
--subscription/--resource-group CLI options are unchanged.

Resolves #469 by adding an optional --schema parameter (default 'public')
to the table-listing path. ListTablesAsync now accepts a schema argument
and uses a parameterized query:
SELECT table_name FROM information_schema.tables WHERE table_schema = @Schema ORDER BY table_name;

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI 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.

Pull request overview

This PR refines the Azure PostgreSQL tool’s data-plane surface by removing unused ARM-scoping parameters from IPostgresService/PostgresService, and extends azmcp postgres list to support listing tables from non-public schemas via a new optional --schema argument (defaulting to public).

Changes:

  • Removed unused subscriptionId / resourceGroup parameters from PostgreSQL data-plane service methods and updated all callers/tests accordingly.
  • Added --schema to the postgres list table-listing path and updated ListTablesAsync to use a parameterized information_schema query with deterministic ordering.
  • Updated unit tests + docs (azmcp-commands.md, e2eTestPrompts.md) and added a server changelog entry.

Reviewed changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tools/Azure.Mcp.Tools.Postgres/tests/Azure.Mcp.Tools.Postgres.Tests/Table/TableSchemaGetCommandTests.cs Updates mocked GetTableSchemaAsync calls to match the new signature.
tools/Azure.Mcp.Tools.Postgres/tests/Azure.Mcp.Tools.Postgres.Tests/Services/PostgresServiceTests.cs Updates service tests and adds a new assertion that table listing uses a parameterized @schema query.
tools/Azure.Mcp.Tools.Postgres/tests/Azure.Mcp.Tools.Postgres.Tests/Services/PostgresServiceServerNameValidationTests.cs Updates validation tests for new method signatures and adds required schema arg for table listing.
tools/Azure.Mcp.Tools.Postgres/tests/Azure.Mcp.Tools.Postgres.Tests/Services/PostgresServiceParameterizedQueryTests.cs Removes unused subscription/RG params from data-plane calls in parameterization-focused tests.
tools/Azure.Mcp.Tools.Postgres/tests/Azure.Mcp.Tools.Postgres.Tests/Services/PostgresServiceConnectionStringInjectionTests.cs Updates injection regression tests for new signatures and adds schema arg for table listing.
tools/Azure.Mcp.Tools.Postgres/tests/Azure.Mcp.Tools.Postgres.Tests/PostgresListCommandTests.cs Adds coverage for --schema provided vs omitted (default public) and updates signatures.
tools/Azure.Mcp.Tools.Postgres/tests/Azure.Mcp.Tools.Postgres.Tests/Database/DatabaseQueryCommandTests.cs Updates ExecuteQueryAsync call sites and negative assertions to new signature.
tools/Azure.Mcp.Tools.Postgres/src/Services/PostgresService.cs Removes unused params and parameterizes the schema filter for table listing.
tools/Azure.Mcp.Tools.Postgres/src/Services/IPostgresService.cs Updates interface signatures to remove subscription/RG for data-plane methods; adds schema to ListTablesAsync.
tools/Azure.Mcp.Tools.Postgres/src/Options/PostgresOptionDefinitions.cs Introduces the --schema option definition.
tools/Azure.Mcp.Tools.Postgres/src/Options/BasePostgresOptions.cs Adds Schema to the base options model for binding/JSON.
tools/Azure.Mcp.Tools.Postgres/src/Commands/Table/TableSchemaGetCommand.cs Updates the data-plane call to GetTableSchemaAsync (drops unused params).
tools/Azure.Mcp.Tools.Postgres/src/Commands/PostgresListCommand.cs Registers/binds --schema and forwards it (defaulting to public) to ListTablesAsync.
tools/Azure.Mcp.Tools.Postgres/src/Commands/Database/DatabaseQueryCommand.cs Updates the data-plane call to ExecuteQueryAsync (drops unused params).
servers/Azure.Mcp.Server/docs/e2eTestPrompts.md Adds an E2E prompt row covering schema-scoped table listing.
servers/Azure.Mcp.Server/docs/azmcp-commands.md Documents the optional --schema parameter for azmcp postgres list.
servers/Azure.Mcp.Server/changelog-entries/vcolin7-postgres-schema-listing.yaml Adds a changelog entry for the schema option + data-plane signature cleanup.
Comments suppressed due to low confidence (1)

tools/Azure.Mcp.Tools.Postgres/src/Commands/PostgresListCommand.cs:43

  • --schema can be provided without --database, but it has no effect unless the command is listing tables (--server + --database). This can lead to confusing output (users think they scoped by schema but actually listed servers/databases). Add a validator that requires --database when --schema has a value.
        command.Validators.Add(result =>
        {
            // Validate that --server is provided when --database is specified
            if (!string.IsNullOrEmpty(result.GetValueOrDefault<string>(PostgresOptionDefinitions.DatabaseOptional.Name)) &&
                string.IsNullOrEmpty(result.GetValueOrDefault<string>(PostgresOptionDefinitions.ServerOptional.Name)))

Comment thread servers/Azure.Mcp.Server/changelog-entries/vcolin7-postgres-schema-listing.yaml Outdated
@vcolin7 vcolin7 assigned vcolin7 and unassigned vcolin7 Jun 12, 2026
@vcolin7 vcolin7 requested a review from alzimmermsft June 12, 2026 02:02
vcolin7 and others added 4 commits June 15, 2026 12:25
Address maintainer review feedback on the Postgres data-plane commands.
The query and table-schema-get commands connect directly via Npgsql and
never use ARM scoping, but --subscription/--resource-group were still
exposed in their MCP input schema. Re-parent BaseDatabaseCommand to
GlobalCommand so those options are no longer registered, and add
regression tests asserting the options are absent. Control-plane
commands (list, server config/param) keep them.

Relates to #469 and #471.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tools-Postgres PostgreSQL

Projects

Status: Untriaged

Development

Successfully merging this pull request may close these issues.

3 participants