Skip to content

Add validation for service start --transport option#511

Merged
jongio merged 10 commits intomicrosoft:mainfrom
jongio:invalidargs
Sep 22, 2025
Merged

Add validation for service start --transport option#511
jongio merged 10 commits intomicrosoft:mainfrom
jongio:invalidargs

Conversation

@jongio
Copy link
Copy Markdown
Contributor

@jongio jongio commented Sep 18, 2025

What does this PR do?

Add validation to the transport option so the server doesn't hang when an invalid option is provided.

GitHub issue number?

Fixes #311

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
    • Updated command list in /docs/azmcp-commands.md and/or /docs/fabric-commands.md
    • 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
  • Extra steps for Azure MCP Server tool changes:
    • Updated test prompts in /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

Adds validation for the --transport option in ServiceStartCommand to prevent the server from hanging on invalid input and introduces tests for invalid and valid transport values. Also performs cleanup by removing unused using directives across multiple files. Adds targeted unit tests for transport validation logic.

Reviewed Changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tools/Azure.Mcp.Tools.Search/tests/Azure.Mcp.Tools.Search.UnitTests/Index/IndexGetCommandTests.cs Removed unused static using.
tools/Azure.Mcp.Tools.Monitor/src/Commands/HealthModels/BaseMonitorHealthModelsCommand.cs Removed unused usings.
tools/Azure.Mcp.Tools.Monitor/src/Commands/BaseWorkspaceMonitorCommand.cs Removed unused using.
tools/Azure.Mcp.Tools.Foundry/src/Services/Models/CognitiveServicesAccountDeploymentProperties.cs Removed unused using.
tools/Azure.Mcp.Tools.Foundry/src/Services/Models/CognitiveServicesAccountDeploymentData.cs Removed unused using.
tools/Azure.Mcp.Tools.EventGrid/src/Services/IEventGridService.cs Removed unused using.
tools/Azure.Mcp.Tools.EventGrid/src/Services/EventGridService.cs Removed unused usings.
tools/Azure.Mcp.Tools.ApplicationInsights/tests/.../RecommendationListCommandTests.cs Removed unused usings.
core/Azure.Mcp.Core/tests/.../CommandResultExtensionsTests.cs Removed unused using.
core/Azure.Mcp.Core/tests/.../ServiceStartCommandTests.cs Added tests for transport option validation.
core/Azure.Mcp.Core/src/Areas/Server/Commands/ServiceStartCommand.cs Added transport retrieval and validation logic.

Comment thread core/Azure.Mcp.Core/src/Areas/Server/Commands/ServiceStartCommand.cs Outdated
Comment thread core/Azure.Mcp.Core/src/Areas/Server/Commands/ServiceStartCommand.cs Outdated
@jongio jongio marked this pull request as draft September 18, 2025 23:30
@jongio jongio requested a review from Copilot September 19, 2025 00:11
@jongio jongio marked this pull request as ready for review September 19, 2025 00:12
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

Copilot reviewed 28 out of 28 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (1)

core/Azure.Mcp.Core/tests/Azure.Mcp.Core.UnitTests/Areas/Server/ServiceStartCommandTests.cs:1

  • The test calls a private method ValidateTransport but this method doesn't exist in the test class. This test will fail at runtime. The method should either be implemented in the test class or use reflection to call the private method in the command class.
// Copyright (c) Microsoft Corporation.

Comment thread core/Azure.Mcp.Core/src/Commands/BaseCommand.cs
Comment thread core/Azure.Mcp.Core/src/Commands/JsonSourceGenerationContext.cs
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

Copilot reviewed 224 out of 224 changed files in this pull request and generated 9 comments.

Comment thread tools/Azure.Mcp.Tools.Postgres/src/Services/PostgresService.cs
Comment thread tools/Azure.Mcp.Tools.MySql/src/Services/MySqlService.cs
Comment thread tools/Azure.Mcp.Tools.KeyVault/src/Services/KeyVaultService.cs
Comment thread tools/Azure.Mcp.Tools.KeyVault/src/Services/KeyVaultService.cs
…lity and early returns; add BindOptions method in ToolsListCommand; enhance BaseCommand with option binding and error handling improvements.
…ode enum

- Updated assertions in SessionHostListCommandTests to replace integer status codes with HttpStatusCode enum values for better readability and maintainability.
- Made similar updates across various unit test files including SessionHostUserSessionListCommandTests, CreateWorkbooksCommandTests, DeleteWorkbooksCommandTests, ListWorkbooksCommandTests, ShowWorkbooksCommandTests, UpdateWorkbooksCommandTests, and Public API command tests.
- Ensured consistency in error handling by using HttpStatusCode for all relevant assertions.
…roved clarity and consistency across commands and tests.
… enum for improved clarity and maintainability.
…SerializeCorrectly test to use HttpStatusCode enum for improved clarity and consistency.
@jongio jongio enabled auto-merge (squash) September 22, 2025 21:22
@jongio jongio merged commit 80e354e into microsoft:main Sep 22, 2025
48 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Azure MCP Server Sep 22, 2025
colbytimm pushed a commit to colbytimm/microsoft-mcp that referenced this pull request Sep 27, 2025
* Add validation for service start --transport option

* Update inheritance model to allow ServiceStart and other BaseCommand commands to work with BindOptions

* Formatting

* Refactor validation method to remove nullable parameter and update tests accordingly

* Make BindOptions method abstract to enforce implementation in derived classes

* Refactor validation logic in ServiceStartCommand for improved readability and early returns; add BindOptions method in ToolsListCommand; enhance BaseCommand with option binding and error handling improvements.

* Refactor HTTP status code assertions in unit tests to use HttpStatusCode enum

- Updated assertions in SessionHostListCommandTests to replace integer status codes with HttpStatusCode enum values for better readability and maintainability.
- Made similar updates across various unit test files including SessionHostUserSessionListCommandTests, CreateWorkbooksCommandTests, DeleteWorkbooksCommandTests, ListWorkbooksCommandTests, ShowWorkbooksCommandTests, UpdateWorkbooksCommandTests, and Public API command tests.
- Ensured consistency in error handling by using HttpStatusCode for all relevant assertions.

* Refactor HTTP status code handling to use HttpStatusCode enum for improved clarity and consistency across commands and tests.

* Refactor error handling in GetCosmosClientAsync to use HttpStatusCode enum for improved clarity and maintainability.

* Refactor status code assertion in ExecuteAsync_EnrichedClusterFields_SerializeCorrectly test to use HttpStatusCode enum for improved clarity and consistency.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

server-Azure.Mcp Azure.Mcp.Server

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

MCP server hangs on invalid arguments

5 participants