Skip to content

Use ConnectionStringBuilder instead of string interpolation#2056

Merged
xiangyan99 merged 4 commits intomainfrom
connection_builder
Mar 16, 2026
Merged

Use ConnectionStringBuilder instead of string interpolation#2056
xiangyan99 merged 4 commits intomainfrom
connection_builder

Conversation

@xiangyan99
Copy link
Copy Markdown
Member

What does this PR do?

[Provide a clear, concise description of the changes]

Use ConnectionStringBuilder instead of string interpolation

[Any additional context, screenshots, or information that helps reviewers]

GitHub issue number?

[Link to the GitHub issue this PR addresses]

Pre-merge Checklist

  • Required for All PRs
    • Read contribution guidelines
    • PR title clearly describes the change
    • Commit history is clean with descriptive messages (cleanup guide)
    • Added comprehensive tests for new/modified functionality
    • Updated servers/Azure.Mcp.Server/CHANGELOG.md and/or servers/Fabric.Mcp.Server/CHANGELOG.md for product changes (features, bug fixes, UI/UX, updated dependencies)
  • For MCP tool changes:
    • One tool per PR: This PR adds or modifies only one MCP tool for faster review cycles
    • Updated servers/Azure.Mcp.Server/README.md and/or servers/Fabric.Mcp.Server/README.md documentation
    • Validate README.md changes using script at eng/scripts/Process-PackageReadMe.ps1. See Package README
    • Updated command list in /servers/Azure.Mcp.Server/docs/azmcp-commands.md and/or /docs/fabric-commands.md
    • Run .\eng\scripts\Update-AzCommandsMetadata.ps1 to update tool metadata in azmcp-commands.md (required for CI)
    • For new or modified tool descriptions, ran ToolDescriptionEvaluator and obtained a score of 0.4 or more and a top 3 ranking for all related test prompts
    • For tools with new names, including new tools or renamed tools, update consolidated-tools.json
    • For renamed tools, follow the Tool Rename Checklist and tag the PR with the breaking-change label
    • For new tools associated with Azure services or publicly available tools/APIs/products, add URL to documentation in the PR description
  • Extra steps for Azure MCP Server tool changes:
    • Updated test prompts in /servers/Azure.Mcp.Server/docs/e2eTestPrompts.md
    • 👉 For Community (non-Microsoft team member) PRs:
      • Security review: Reviewed code for security vulnerabilities, malicious code, or suspicious activities before running tests (crypto mining, spam, data exfiltration, etc.)
      • Manual tests run: added comment /azp run mcp - pullrequest - live to run Live Test Pipeline

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 hardens the PostgreSQL and MySQL tools against connection-string injection by switching from string interpolation to provider connection-string builders, and adds regression tests plus a server changelog entry documenting the fix.

Changes:

  • PostgreSQL: replace interpolated connection strings with NpgsqlConnectionStringBuilder via a new helper.
  • MySQL: replace interpolated connection strings with MySqlConnectionStringBuilder via a new helper (and expose it for unit testing).
  • Add regression unit tests for connection-string injection scenarios and a changelog entry.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
tools/Azure.Mcp.Tools.Postgres/tests/Azure.Mcp.Tools.Postgres.UnitTests/Services/PostgresServiceConnectionStringInjectionTests.cs New regression tests validating injected database values don’t override Host / SSL settings.
tools/Azure.Mcp.Tools.Postgres/src/Services/PostgresService.cs Uses a new BuildConnectionString helper to build safe PostgreSQL connection strings.
tools/Azure.Mcp.Tools.MySql/tests/Azure.Mcp.Tools.MySql.UnitTests/Services/MySqlServiceConnectionStringInjectionTests.cs New regression tests validating injected database/user values don’t override Server / SSL settings.
tools/Azure.Mcp.Tools.MySql/src/Services/MySqlService.cs Uses MySqlConnectionStringBuilder via a new internal BuildConnectionString helper (SSL required).
servers/Azure.Mcp.Server/changelog-entries/1773675545058.yaml Records the security bug fix in the server changelog.

Comment thread tools/Azure.Mcp.Tools.Postgres/src/Services/PostgresService.cs
Comment thread tools/Azure.Mcp.Tools.Postgres/src/Services/PostgresService.cs
Comment thread tools/Azure.Mcp.Tools.Postgres/src/Services/PostgresService.cs
Comment thread tools/Azure.Mcp.Tools.Postgres/src/Services/PostgresService.cs
xiangyan99 and others added 3 commits March 16, 2026 08:51
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@xiangyan99 xiangyan99 merged commit 809daac into main Mar 16, 2026
15 checks passed
@github-project-automation github-project-automation Bot moved this from Untriaged to Done in Azure MCP Server Mar 16, 2026
@xiangyan99 xiangyan99 deleted the connection_builder branch March 16, 2026 17:29
colbytimm pushed a commit to colbytimm/microsoft-mcp that referenced this pull request Apr 20, 2026
…t#2056)

* Use ConnectionStringBuilder instead of string interpolation

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* fix test

* dotnet format

---------

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

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants