Skip to content

Auto-detect APIView environment from URL domain#14569

Draft
swathipil wants to merge 2 commits intoAzure:mainfrom
swathipil:swathipil/update-apiview-env-detection
Draft

Auto-detect APIView environment from URL domain#14569
swathipil wants to merge 2 commits intoAzure:mainfrom
swathipil:swathipil/update-apiview-env-detection

Conversation

@swathipil
Copy link
Copy Markdown
Member

@swathipil swathipil commented Mar 18, 2026

closing #13656 in favor of this.

The azsdk_apiview_get_comments tool required users to manually set APIVIEW_ENVIRONMENT to match the URL's target environment. Querying apiviewstagingtest.com with default production environment returned empty results.

Changes

  • Added domain-based detection in APIViewReviewTool.GetEnvironmentFromUrl():

    • apiviewstagingtest.com → staging
    • localhost → local
    • default → production
    • APIVIEW_ENVIRONMENT override preserved (takes precedence)
  • Threading environment through call chain:

    • APIViewReviewTool extracts environment from URL, passes downstream
    • IAPIViewService.GetCommentsByRevisionAsync/GetRevisionContent accept environment parameter
    • IAPIViewHttpService.GetAsync accepts environment instead of reading env var internally
  • Removed APIViewHttpService.GetEnvironment() static method

Example

# Before: required manual env var setup
export APIVIEW_ENVIRONMENT=staging
azsdk apiview get-comments --url "https://apiviewstagingtest.com/review/..."

# After: works automatically
azsdk apiview get-comments --url "https://apiviewstagingtest.com/review/..."

@github-actions github-actions Bot added the azsdk-cli Issues related to Azure/azure-sdk-tools::tools/azsdk-cli label Mar 18, 2026
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why are we doing this change to identify apiview host? apiview staging should be used only for development and testing purpose. right? All other uses cases (once this feature is available to users) must use production URL and production host.

Why don't we simply use an env variable to override the host in Apiview http service class. If AZSDK_APIVIEW_HOST_NAME env variable is present and it has value then use it as host name. Otherwise just use the default apiview url.

If someone wants to test with a different APIView instance than production instance, they should just set the env variable.

Copy link
Copy Markdown
Member

@praveenkuttappan praveenkuttappan left a comment

Choose a reason for hiding this comment

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

I don't think this change is required other than providing a simple env var to override the host name, mcp tool is connecting to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

azsdk-cli Issues related to Azure/azure-sdk-tools::tools/azsdk-cli

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants