Skip to content

Conversation

@conniey
Copy link
Member

@conniey conniey commented Jan 27, 2026

What does this PR do?

Adds tool name validation to AnalyzeCode.ps1 to ensure only tools with valid naming is added. See: Command Design Principles.

GitHub issue number?

Related: #1566

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 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

@conniey conniey requested a review from a team as a code owner January 27, 2026 00:39
Copilot AI review requested due to automatic review settings January 27, 2026 00:39
@conniey conniey requested review from a team as code owners January 27, 2026 00:39
Copy link
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 a new PowerShell validation step to enforce MCP tool naming character rules and wires it into the existing Analyze-Code.ps1 developer/CI analysis script.

Changes:

  • Added Test-ToolNameCharacters.ps1 to scan tool source files for invalid name characters.
  • Updated Analyze-Code.ps1 to run the new character validation and print violations.

Reviewed changes

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

File Description
eng/scripts/Test-ToolNameCharacters.ps1 New script that scans tools/ for Name definitions and validates allowed characters/dash placement.
eng/scripts/Analyze-Code.ps1 Runs the new tool name character validation and fails analysis when violations are found.

Comment on lines +69 to +70

$hasErrors = $true
Copy link

Copilot AI Jan 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new validation will fail in the current repo and make Analyze-Code.ps1 always report errors: existing tool names include underscores (e.g., tools/Azure.Mcp.Tools.AzureBestPractices/src/AzureBestPracticesSetup.cs:13 has "get_azure_bestpractices" and AIAppBestPracticesCommand has "ai_app"), which Test-ToolNameCharacters.ps1 treats as invalid. Either rename/fix the existing tool names as part of this PR, or scope/exempt this check so it doesn’t break the baseline.

Suggested change
$hasErrors = $true

Copilot uses AI. Check for mistakes.
Comment on lines +78 to +95
class ToolArea {
[string]$ToolArea
[ToolNameViolation[]]$Violations

ToolArea([string]$ToolArea) {
$this.ToolArea = $ToolArea
$this.Violations = @()
}

[void]AddViolation([ToolNameViolation]$violation) {
$this.Violations += $violation
}

[bool]HasViolations() {
return $this.Violations.Count -gt 0
}
}

Copy link

Copilot AI Jan 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ToolArea class is declared but never used (violations are accumulated as a plain array). Removing it (or actually using it to group violations) would reduce dead code and keep the script easier to maintain.

Suggested change
class ToolArea {
[string]$ToolArea
[ToolNameViolation[]]$Violations
ToolArea([string]$ToolArea) {
$this.ToolArea = $ToolArea
$this.Violations = @()
}
[void]AddViolation([ToolNameViolation]$violation) {
$this.Violations += $violation
}
[bool]HasViolations() {
return $this.Violations.Count -gt 0
}
}
# ToolArea class removed; violations are tracked directly as ToolNameViolation objects.

Copilot uses AI. Check for mistakes.
Comment on lines +123 to +137
foreach ($file in $areaTools) {
Write-Debug "Processing: $($file.FullName)"
$content = Get-Content $file.FullName

if ($file.Name -like '*Command.cs') {
$matchingPattern = 'public override string Name => "(.*)";'
} elseif ($file.Name -like '*Setup.cs') {
$matchingPattern = 'public string Name => "(.*)";'
} else {
throw "Unexpected file name: $($file.Name)"
}

foreach ($line in $content) {
if ($line -match $matchingPattern) {
$toolName = $matches[1]
Copy link

Copilot AI Jan 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR description links to command design principles for command group naming, but this script only validates Name properties in *Command.cs/*Setup.cs. As a result, invalid CommandGroup names (e.g., tools/Azure.Mcp.Tools.ManagedLustre/src/ManagedLustreSetup.cs uses "blob_autoexport" / "blob_import") won’t be detected. Consider extending the scan to validate CommandGroup("...") names too, or clarify that this check intentionally excludes command group names.

Copilot uses AI. Check for mistakes.
Comment on lines +139 to +147
# Validate tool name format:
# - Each group contains alphanumeric chars or dashes
# - Each group cannot start or end with a dash
# Pattern breakdown:
# ^ - Start of string
# [a-zA-Z0-9] - First char must be alphanumeric
# ([a-zA-Z0-9-]*[a-zA-Z0-9])? - Optional: middle chars (alphanumeric or dash) ending with alphanumeric
# $ - End of string
$isValid = $($ToolName -match '^[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?$')
Copy link

Copilot AI Jan 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The validation regex allows uppercase letters, but the referenced command design principles specify lowercase command group/service/resource/operation names. To enforce the documented convention, restrict the allowed characters to lowercase (and digits/dashes) rather than [a-zA-Z0-9-].

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Untriaged

Development

Successfully merging this pull request may close these issues.

1 participant