Skip to content

DI Refactor: Azure.Mcp.Tools.Postgres#2079

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/mcp-158-refactor-azure-mcp-tools-postgres
Draft

DI Refactor: Azure.Mcp.Tools.Postgres#2079
Copilot wants to merge 2 commits intomainfrom
copilot/mcp-158-refactor-azure-mcp-tools-postgres

Conversation

Copy link
Contributor

Copilot AI commented Mar 17, 2026

Removes context.GetService<IPostgresService>() calls from ExecuteAsync across all Postgres commands, replacing them with constructor-injected dependencies.

Changes

  • Commands — All 6 command classes now accept IPostgresService as a constructor parameter and use it via a private readonly field:

    • PostgresListCommand
    • DatabaseQueryCommand
    • ServerParamGetCommand
    • ServerParamSetCommand
    • ServerConfigGetCommand
    • TableSchemaGetCommand
  • Tests — Updated all unit test constructors to pass the mock service directly to the command.

  • PostgresSetup.cs — No changes required; DI container resolves IPostgresService automatically since commands are registered via AddSingleton<TCommand>().

Before / After

// Before
public sealed class ServerParamGetCommand(ILogger<ServerParamGetCommand> logger)
    : BaseServerCommand<ServerParamGetOptions>(logger)
{
    public override async Task<CommandResponse> ExecuteAsync(...)
    {
        IPostgresService pgService = context.GetService<IPostgresService>()
            ?? throw new InvalidOperationException("PostgreSQL service is not available.");
        ...
    }
}

// After
public sealed class ServerParamGetCommand(IPostgresService postgresService, ILogger<ServerParamGetCommand> logger)
    : BaseServerCommand<ServerParamGetOptions>(logger)
{
    private readonly IPostgresService _postgresService = postgresService;

    public override async Task<CommandResponse> ExecuteAsync(...)
    {
        var parameterValue = await _postgresService.GetServerParameterAsync(...);
        ...
    }
}

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.

Original prompt

This section details on the original issue you should resolve

<issue_title>DI Refactor: Azure.Mcp.Tools.Postgres</issue_title>
<issue_description>## Summary

Refactor Azure.Mcp.Tools.Postgres to use constructor dependency injection instead of resolving services via context.GetService<T>() in ExecuteAsync.

This is a sub-issue of #158.

Instructions

Follow the algorithm described in tools/di-refactor-plan.md with {ToolArea} = Postgres.

An example PR is: #1815
</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…Service

Co-authored-by: conniey <10136526+conniey@users.noreply.github.com>
Copilot AI changed the title [WIP] [microsoft/mcp#158] Refactor Azure.Mcp.Tools.Postgres for DI DI Refactor: Azure.Mcp.Tools.Postgres Mar 17, 2026
Copilot AI requested a review from conniey March 17, 2026 10:22
@joshfree joshfree added the Do Not Merge Do Not Merge / WIP PRs label Mar 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Do Not Merge Do Not Merge / WIP PRs

Projects

Status: Untriaged

Development

Successfully merging this pull request may close these issues.

DI Refactor: Azure.Mcp.Tools.Postgres

3 participants