Skip to content

General cleanups to improve reliability#2223

Merged
alzimmermsft merged 2 commits intomicrosoft:release/azure/2.xfrom
alzimmermsft:GeneralCleanups2.x
Mar 26, 2026
Merged

General cleanups to improve reliability#2223
alzimmermsft merged 2 commits intomicrosoft:release/azure/2.xfrom
alzimmermsft:GeneralCleanups2.x

Conversation

@alzimmermsft
Copy link
Copy Markdown
Contributor

What does this PR do?

General cleanups to improve reliability:

  • Added resource count limits to cacheable resources which can return an extremely large number of resources.
  • Added standard regex helpers to make regex creation consistent and added timeouts to more locations to prevent hangs on complicated regex patterns.
  • Added additional logging to improve troubleshooting.
  • Minor changes to generic try-catch-ignore patterns to allow cancellation to flow through without being caught.
  • Removed logging for scenario where logging wasn't needed, to reduce noise in logs.

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
    • Created a changelog entry if the change falls among the following: new feature, bug fix, UI/UX update, breaking change, or updated dependencies. Follow the changelog entry guide
  • 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 running the script ./eng/scripts/Process-PackageReadMe.ps1. See Package README
    • 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 command list in servers/Azure.Mcp.Server/docs/azmcp-commands.md
    • Ran ./eng/scripts/Update-AzCommandsMetadata.ps1 to update tool metadata in azmcp-commands.md (required for CI)
    • 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

* General cleanups to improve reliability

* Few small tweaks

* Change log level, remove default param value, update parameter description

* Use ConcurrentDictionary inside group keys instead of managing two dictionaries

* Fix logic

* Give some breadcrumps to display error

* Add ConcurrentHashSet for convenience
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 applies a set of reliability and hardening updates across MCP core and multiple Azure tools, focusing on preventing hangs (regex timeouts), avoiding silent failures, adding safe upper bounds to potentially unbounded listings, and improving troubleshooting/logging.

Changes:

  • Introduces RegexHelper (default 3s timeout) and updates several validators/services to use it.
  • Adds resource-count caps (e.g., tenants, subscriptions, function apps) and improves exception/cancellation handling and logging.
  • Improves safety and correctness in a few flows (e.g., Kusto identifier validation, non-root Docker runtime, tenant-aware subscription enumeration).

Reviewed changes

Copilot reviewed 25 out of 25 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tools/Azure.Mcp.Tools.Redis/src/Services/RedisService.cs Adds logger injection and logs partial failures while allowing cancellation to propagate.
tools/Azure.Mcp.Tools.Postgres/src/Validation/SqlQueryValidator.cs Switches regex calls to use shared default timeout.
tools/Azure.Mcp.Tools.Postgres/src/Services/PostgresService.cs Removes unused Azure.ResourceManager using.
tools/Azure.Mcp.Tools.MySql/src/Services/MySqlService.cs Uses RegexHelper for consistent timeouts/creation.
tools/Azure.Mcp.Tools.Monitor/tests/Azure.Mcp.Tools.Monitor.LiveTests/MonitorCommandTests.cs Updates test wiring for new logger parameters.
tools/Azure.Mcp.Tools.Monitor/src/Services/MonitorWebTestService.cs Uses RegexHelper for compiled regex with timeout.
tools/Azure.Mcp.Tools.Kusto/src/Validation/KustoIdentifierValidator.cs Adds Kusto identifier validation to reduce KQL injection risk.
tools/Azure.Mcp.Tools.Kusto/src/Services/KustoService.cs Validates table name before schema query.
tools/Azure.Mcp.Tools.Kusto/src/Options/KustoOptionDefinitions.cs Expands --limit description with intended bounds.
tools/Azure.Mcp.Tools.Kusto/src/Commands/SampleCommand.cs Clamps --limit to safe bounds before building query.
tools/Azure.Mcp.Tools.FunctionApp/src/Services/FunctionAppService.cs Adds a max function-app cap with warning logging.
tools/Azure.Mcp.Tools.EventGrid/src/Commands/Subscription/SubscriptionListCommand.cs Ensures tenant is honored when enumerating subscriptions.
tools/Azure.Mcp.Tools.Cosmos/src/Validation/CosmosQueryValidator.cs Uses RegexHelper for safe regex timeouts.
tools/Azure.Mcp.Tools.AzureMigrate/src/Helpers/AzureMigrateProjectHelper.cs Passes tenant through to subscription resolution.
tools/Azure.Mcp.Tools.AppConfig/tests/Azure.Mcp.Tools.AppConfig.LiveTests/AppConfigCommandTests.cs Updates test wiring for new logger parameters.
core/Microsoft.Mcp.Core/src/Services/Caching/SingleUserCliCacheService.cs Makes group-key tracking thread-safe and avoids concurrent enumeration issues.
core/Microsoft.Mcp.Core/src/Services/Azure/Authentication/WindowHandleProvider.cs Reduces console exception detail for headless/X11 detection path.
core/Microsoft.Mcp.Core/src/Models/ConcurrentHashSet.cs Adds a minimal concurrent set used by cache group-key tracking.
core/Microsoft.Mcp.Core/src/Helpers/RegexHelper.cs Introduces shared regex creation helper with default timeout and wrapping errors.
core/Microsoft.Mcp.Core/src/Helpers/EmbeddedResourceHelper.cs Uses RegexHelper for resource name pattern matching with timeout.
core/Microsoft.Mcp.Core/src/Areas/Server/Commands/Runtime/McpRuntime.cs Provides fallback message when exception message is empty.
core/Azure.Mcp.Core/tests/Azure.Mcp.Core.LiveTests/Services/Azure/Authentication/AuthenticationIntegrationTests.cs Updates DI setup for new SubscriptionService logger dependency.
core/Azure.Mcp.Core/src/Services/Azure/Tenant/TenantService.cs Adds tenant listing cap and logger dependency.
core/Azure.Mcp.Core/src/Services/Azure/Subscription/SubscriptionService.cs Adds subscription listing cap and logger dependency.
Dockerfile Runs the server as a non-root user in the Alpine runtime image.

Comment thread core/Microsoft.Mcp.Core/src/Services/Caching/SingleUserCliCacheService.cs Outdated
Comment thread tools/Azure.Mcp.Tools.Kusto/src/Options/KustoOptionDefinitions.cs Outdated
@github-project-automation github-project-automation Bot moved this from Untriaged to In Progress in Azure MCP Server Mar 26, 2026
@alzimmermsft alzimmermsft enabled auto-merge (squash) March 26, 2026 17:28
@alzimmermsft alzimmermsft merged commit 97faf01 into microsoft:release/azure/2.x Mar 26, 2026
15 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Azure MCP Server Mar 26, 2026
@alzimmermsft alzimmermsft deleted the GeneralCleanups2.x branch March 26, 2026 17:54
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