Skip to content

Migrate Foundry MCP server to use external integration.#1771

Merged
g2vinay merged 26 commits intomicrosoft:mainfrom
g2vinay:add-foundry-mcp-server
Mar 4, 2026
Merged

Migrate Foundry MCP server to use external integration.#1771
g2vinay merged 26 commits intomicrosoft:mainfrom
g2vinay:add-foundry-mcp-server

Conversation

@g2vinay
Copy link
Contributor

@g2vinay g2vinay commented Feb 19, 2026

This PR migrates Microsoft Foundry from in-process tool files to the external MCP server
at https://mcp.ai.azure.com, then adds the authentication plumbing needed for the Azure MCP
server to call that external server on the user's behalf.

Changes:

  1. Foundry → external MCP server (registry.json)
    All Foundry source files (commands, services, options, models, tests, setup) have been deleted.
    Instead, registry.json now contains a "foundry" entry that points the runtime at the hosted
    server:

    The Foundry project references have also been removed from both Microsoft.Mcp.slnx and
    Azure.Mcp.Server.slnx.

  2. AccessTokenHandlerTokenCredential-based constructor

    A second constructor was added so the registry HTTP client can be wired directly to a
    TokenCredential instance rather than always going through IAzureTokenCredentialProvider:

  3. CustomChainedCredentialforceBrowserFallback parameter

    A new forceBrowserFallback constructor parameter allows callers to opt into
    InteractiveBrowserCredential as a last resort without requiring AZURE_TOKEN_CREDENTIALS to
    be unset globally. The flag is suppressed when AZURE_TOKEN_CREDENTIALS=prod, so CI/headless
    environments are never interrupted by a browser popup.

  4. SafeTokenCredentialnormalizeScopes parameter

    Non-MSAL credentials (AzureCliCredential, ManagedIdentityCredential, etc.) use a
    resource-based auth model: they expect a scope of the form https://host/.default and strip the
    /.default suffix internally to derive the resource URL. They cannot handle arbitrary MSAL
    permission scopes like https://mcp.ai.azure.com/Foundry.Mcp.Tools.

    SafeTokenCredential now accepts normalizeScopes: true, which transparently converts any
    non-/.default scope to its resource/.default form before forwarding to the inner credential.

- CustomChainedCredential: add forceBrowserFallback param, suppressed when
  AZURE_TOKEN_CREDENTIALS=prod; enables InteractiveBrowserCredential fallback
  only in user-identity modes (SingleIdentityTokenCredentialProvider)
- SafeTokenCredential: add normalizeScopes=true for all 8 non-MSAL credentials
  (EnvironmentCredential, WorkloadIdentity, ManagedIdentity, VisualStudio,
  VisualStudioCode, AzureCli, AzurePowerShell, AzureDeveloperCli)
  Converts https://mcp.ai.azure.com/Foundry.Mcp.Tools to
  https://mcp.ai.azure.com/.default so resource-based credential types
  receive the correct scope format; InteractiveBrowserCredential is unwrapped
  and receives the verbatim MSAL permission scope
- Microsoft.Mcp.slnx and Azure.Mcp.Server.slnx: remove deleted
  Azure.Mcp.Tools.Foundry project references
@g2vinay g2vinay marked this pull request as ready for review February 25, 2026 18:06
@g2vinay g2vinay requested review from a team and xiangyan99 as code owners February 25, 2026 18:06
Copilot AI review requested due to automatic review settings February 25, 2026 18:06
@g2vinay g2vinay requested review from a team as code owners February 25, 2026 18:06
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

This PR migrates the Foundry toolset from an in-process implementation (tools/Azure.Mcp.Tools.Foundry) to an external MCP integration hosted at https://mcp.ai.azure.com, and updates Azure MCP’s auth plumbing so the registry HTTP client can obtain tokens for that external server (including optional interactive fallback and scope normalization).

Changes:

  • Removed the in-repo Foundry tool project (source, options/models, unit/live tests, test infra, and solution entries).
  • Added a foundry external server entry to registry.json and updated discovery tests accordingly.
  • Extended outbound auth support (new AccessTokenHandler ctor, CustomChainedCredential interactive fallback flag, and SafeTokenCredential scope normalization) and updated DI wiring for registry HTTP clients.

Reviewed changes

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

Show a summary per file
File Description
tools/Azure.Mcp.Tools.Foundry/tests/test-resources.bicep Deleted Foundry test infra deployment template.
tools/Azure.Mcp.Tools.Foundry/tests/test-resources-post.ps1 Deleted Foundry post-deploy hook script.
tools/Azure.Mcp.Tools.Foundry/tests/Azure.Mcp.Tools.Foundry.UnitTests/ThreadListCommandTests.cs Deleted Foundry unit tests (threads list).
tools/Azure.Mcp.Tools.Foundry/tests/Azure.Mcp.Tools.Foundry.UnitTests/ThreadGetMessagesCommandTests.cs Deleted Foundry unit tests (thread messages).
tools/Azure.Mcp.Tools.Foundry/tests/Azure.Mcp.Tools.Foundry.UnitTests/ThreadCreateCommandTests.cs Deleted Foundry unit tests (thread create).
tools/Azure.Mcp.Tools.Foundry/tests/Azure.Mcp.Tools.Foundry.UnitTests/ResourceGetCommandTests.cs Deleted Foundry unit tests (resource get/list).
tools/Azure.Mcp.Tools.Foundry/tests/Azure.Mcp.Tools.Foundry.UnitTests/OpenAiModelsListCommandTests.cs Deleted Foundry unit tests (OpenAI models list).
tools/Azure.Mcp.Tools.Foundry/tests/Azure.Mcp.Tools.Foundry.UnitTests/OpenAiEmbeddingsCreateCommandTests.cs Deleted Foundry unit tests (embeddings).
tools/Azure.Mcp.Tools.Foundry/tests/Azure.Mcp.Tools.Foundry.UnitTests/OpenAiCompletionsCreateCommandTests.cs Deleted Foundry unit tests (completions).
tools/Azure.Mcp.Tools.Foundry/tests/Azure.Mcp.Tools.Foundry.UnitTests/OpenAiChatCompletionsCreateCommandTests.cs Deleted Foundry unit tests (chat completions metadata).
tools/Azure.Mcp.Tools.Foundry/tests/Azure.Mcp.Tools.Foundry.UnitTests/ModelsListCommandTests.cs Deleted Foundry unit tests (catalog models list).
tools/Azure.Mcp.Tools.Foundry/tests/Azure.Mcp.Tools.Foundry.UnitTests/ModelDeploymentCommandTests.cs Deleted Foundry unit tests (model deploy).
tools/Azure.Mcp.Tools.Foundry/tests/Azure.Mcp.Tools.Foundry.UnitTests/KnowledgeIndexSchemaCommandTests.cs Deleted Foundry unit tests (knowledge schema).
tools/Azure.Mcp.Tools.Foundry/tests/Azure.Mcp.Tools.Foundry.UnitTests/KnowledgeIndexListCommandTests.cs Deleted Foundry unit tests (knowledge list).
tools/Azure.Mcp.Tools.Foundry/tests/Azure.Mcp.Tools.Foundry.UnitTests/FoundryServiceEndpointValidationTests.cs Deleted Foundry endpoint validation tests (SSRF/host allowlist).
tools/Azure.Mcp.Tools.Foundry/tests/Azure.Mcp.Tools.Foundry.UnitTests/DeploymentsListCommandTests.cs Deleted Foundry unit tests (deployments list).
tools/Azure.Mcp.Tools.Foundry/tests/Azure.Mcp.Tools.Foundry.UnitTests/Azure.Mcp.Tools.Foundry.UnitTests.csproj Deleted Foundry unit test project file.
tools/Azure.Mcp.Tools.Foundry/tests/Azure.Mcp.Tools.Foundry.UnitTests/AgentsGetSdkCodeSampleCommandTests.cs Deleted Foundry unit tests (SDK sample).
tools/Azure.Mcp.Tools.Foundry/tests/Azure.Mcp.Tools.Foundry.UnitTests/AgentsCreateCommandTests.cs Deleted Foundry unit tests (agent create).
tools/Azure.Mcp.Tools.Foundry/tests/Azure.Mcp.Tools.Foundry.LiveTests/assets.json Deleted recorded-test assets metadata for Foundry live tests.
tools/Azure.Mcp.Tools.Foundry/tests/Azure.Mcp.Tools.Foundry.LiveTests/Azure.Mcp.Tools.Foundry.LiveTests.csproj Deleted Foundry live test project file.
tools/Azure.Mcp.Tools.Foundry/src/Services/Models/CognitiveServicesSku.cs Deleted Foundry internal service model type.
tools/Azure.Mcp.Tools.Foundry/src/Services/Models/CognitiveServicesAccountDeploymentScaleSettings.cs Deleted Foundry internal service model type.
tools/Azure.Mcp.Tools.Foundry/src/Services/Models/CognitiveServicesAccountDeploymentProperties.cs Deleted Foundry internal service model type.
tools/Azure.Mcp.Tools.Foundry/src/Services/Models/CognitiveServicesAccountDeploymentModel.cs Deleted Foundry internal service model type.
tools/Azure.Mcp.Tools.Foundry/src/Services/Models/CognitiveServicesAccountDeploymentData.cs Deleted Foundry internal service model type.
tools/Azure.Mcp.Tools.Foundry/src/Services/IFoundryService.cs Deleted Foundry service interface.
tools/Azure.Mcp.Tools.Foundry/src/Resources/AgentSdkSamples/typescript.md Deleted embedded SDK sample docs.
tools/Azure.Mcp.Tools.Foundry/src/Resources/AgentSdkSamples/python.md Deleted embedded SDK sample docs.
tools/Azure.Mcp.Tools.Foundry/src/Resources/AgentSdkSamples/csharp.md Deleted embedded SDK sample docs.
tools/Azure.Mcp.Tools.Foundry/src/Options/Thread/ThreadListResult.cs Deleted Foundry options/result model.
tools/Azure.Mcp.Tools.Foundry/src/Options/Thread/ThreadListOptions.cs Deleted Foundry options model.
tools/Azure.Mcp.Tools.Foundry/src/Options/Thread/ThreadGetMessagesOptions.cs Deleted Foundry options model.
tools/Azure.Mcp.Tools.Foundry/src/Options/Thread/ThreadCreateResult.cs Deleted Foundry options/result model.
tools/Azure.Mcp.Tools.Foundry/src/Options/Thread/ThreadCreateOptions.cs Deleted Foundry options model.
tools/Azure.Mcp.Tools.Foundry/src/Options/Models/ResourceGetOptions.cs Deleted Foundry options model.
tools/Azure.Mcp.Tools.Foundry/src/Options/Models/OpenAiModelsListOptions.cs Deleted Foundry options model.
tools/Azure.Mcp.Tools.Foundry/src/Options/Models/OpenAiEmbeddingsCreateOptions.cs Deleted Foundry options model.
tools/Azure.Mcp.Tools.Foundry/src/Options/Models/OpenAiCompletionsCreateOptions.cs Deleted Foundry options model.
tools/Azure.Mcp.Tools.Foundry/src/Options/Models/OpenAiChatCompletionsCreateOptions.cs Deleted Foundry options model.
tools/Azure.Mcp.Tools.Foundry/src/Options/Models/ModelsListOptions.cs Deleted Foundry options model.
tools/Azure.Mcp.Tools.Foundry/src/Options/Models/ModelDeploymentOptions.cs Deleted Foundry options model.
tools/Azure.Mcp.Tools.Foundry/src/Options/Models/KnowledgeIndexSchemaOptions.cs Deleted Foundry options model.
tools/Azure.Mcp.Tools.Foundry/src/Options/Models/KnowledgeIndexListOptions.cs Deleted Foundry options model.
tools/Azure.Mcp.Tools.Foundry/src/Options/Models/DeploymentsListOptions.cs Deleted Foundry options model.
tools/Azure.Mcp.Tools.Foundry/src/Options/Models/BaseKnowledgeIndexOptions.cs Deleted Foundry options base type.
tools/Azure.Mcp.Tools.Foundry/src/Options/FoundryOptionDefinitions.cs Deleted Foundry CLI option definitions.
tools/Azure.Mcp.Tools.Foundry/src/Options/Agents/AgentsQueryAndEvaluateOptions.cs Deleted Foundry options model.
tools/Azure.Mcp.Tools.Foundry/src/Options/Agents/AgentsListOptions.cs Deleted Foundry options model.
tools/Azure.Mcp.Tools.Foundry/src/Options/Agents/AgentsGetSdkSampleOptions.cs Deleted Foundry options model.
tools/Azure.Mcp.Tools.Foundry/src/Options/Agents/AgentsEvaluateOptions.cs Deleted Foundry options model.
tools/Azure.Mcp.Tools.Foundry/src/Options/Agents/AgentsCreateOptions.cs Deleted Foundry options model.
tools/Azure.Mcp.Tools.Foundry/src/Options/Agents/AgentsConnectOptions.cs Deleted Foundry options model.
tools/Azure.Mcp.Tools.Foundry/src/Models/ThreadGetMessagesResult.cs Deleted Foundry response model.
tools/Azure.Mcp.Tools.Foundry/src/Models/OpenAiModelsListModels.cs Deleted Foundry response models.
tools/Azure.Mcp.Tools.Foundry/src/Models/ModelInformation.cs Deleted Foundry catalog model type.
tools/Azure.Mcp.Tools.Foundry/src/Models/ModelDeploymentResult.cs Deleted Foundry deployment response model.
tools/Azure.Mcp.Tools.Foundry/src/Models/ModelDeploymentInformation.cs Deleted Foundry model metadata type.
tools/Azure.Mcp.Tools.Foundry/src/Models/ModelCatalogResponse.cs Deleted Foundry catalog response type.
tools/Azure.Mcp.Tools.Foundry/src/Models/ModelCatalogRequest.cs Deleted Foundry catalog request type.
tools/Azure.Mcp.Tools.Foundry/src/Models/ModelCatalogFilter.cs Deleted Foundry catalog filter type.
tools/Azure.Mcp.Tools.Foundry/src/Models/KnowledgeIndexSchema.cs Deleted Foundry knowledge schema type.
tools/Azure.Mcp.Tools.Foundry/src/Models/KnowledgeIndexInformation.cs Deleted Foundry knowledge index type.
tools/Azure.Mcp.Tools.Foundry/src/Models/EmbeddingModels.cs Deleted Foundry embedding response types.
tools/Azure.Mcp.Tools.Foundry/src/Models/CompletionModels.cs Deleted Foundry completion response types.
tools/Azure.Mcp.Tools.Foundry/src/Models/ChatCompletionModels.cs Deleted Foundry chat completion response types.
tools/Azure.Mcp.Tools.Foundry/src/Models/AiResourceInformation.cs Deleted Foundry AI resource models.
tools/Azure.Mcp.Tools.Foundry/src/Models/AgentsQueryAndEvaluateResult.cs Deleted Foundry agent evaluation result type.
tools/Azure.Mcp.Tools.Foundry/src/Models/AgentsGetSdkCodeSampleResult.cs Deleted Foundry SDK sample result type.
tools/Azure.Mcp.Tools.Foundry/src/Models/AgentsEvaluateResult.cs Deleted Foundry evaluation result type.
tools/Azure.Mcp.Tools.Foundry/src/Models/AgentsCreateResult.cs Deleted Foundry agent create result type.
tools/Azure.Mcp.Tools.Foundry/src/Models/AgentsConnectResult.cs Deleted Foundry agent connect result type.
tools/Azure.Mcp.Tools.Foundry/src/Models/AgentFileSearchResult.cs Deleted Foundry internal helper model.
tools/Azure.Mcp.Tools.Foundry/src/GlobalUsings.cs Deleted Foundry global usings file.
tools/Azure.Mcp.Tools.Foundry/src/FoundrySetup.cs Deleted Foundry area setup and command registration.
tools/Azure.Mcp.Tools.Foundry/src/Commands/ThreadListCommand.cs Deleted Foundry command implementation.
tools/Azure.Mcp.Tools.Foundry/src/Commands/ThreadGetMessagesCommand.cs Deleted Foundry command implementation.
tools/Azure.Mcp.Tools.Foundry/src/Commands/ThreadCreateCommand.cs Deleted Foundry command implementation.
tools/Azure.Mcp.Tools.Foundry/src/Commands/ResourceGetCommand.cs Deleted Foundry command implementation.
tools/Azure.Mcp.Tools.Foundry/src/Commands/OpenAiModelsListCommand.cs Deleted Foundry command implementation.
tools/Azure.Mcp.Tools.Foundry/src/Commands/OpenAiEmbeddingsCreateCommand.cs Deleted Foundry command implementation.
tools/Azure.Mcp.Tools.Foundry/src/Commands/OpenAiCompletionsCreateCommand.cs Deleted Foundry command implementation.
tools/Azure.Mcp.Tools.Foundry/src/Commands/OpenAiChatCompletionsCreateCommand.cs Deleted Foundry command implementation.
tools/Azure.Mcp.Tools.Foundry/src/Commands/ModelsListCommand.cs Deleted Foundry command implementation.
tools/Azure.Mcp.Tools.Foundry/src/Commands/ModelDeploymentCommand.cs Deleted Foundry command implementation.
tools/Azure.Mcp.Tools.Foundry/src/Commands/KnowledgeIndexSchemaCommand.cs Deleted Foundry command implementation.
tools/Azure.Mcp.Tools.Foundry/src/Commands/KnowledgeIndexListCommand.cs Deleted Foundry command implementation.
tools/Azure.Mcp.Tools.Foundry/src/Commands/FoundryJsonContext.cs Deleted Foundry STJ source-gen context.
tools/Azure.Mcp.Tools.Foundry/src/Commands/DeploymentsListCommand.cs Deleted Foundry command implementation.
tools/Azure.Mcp.Tools.Foundry/src/Commands/AgentsQueryAndEvaluate.cs Deleted Foundry command implementation.
tools/Azure.Mcp.Tools.Foundry/src/Commands/AgentsListCommand.cs Deleted Foundry command implementation.
tools/Azure.Mcp.Tools.Foundry/src/Commands/AgentsGetSdkSampleCommand.cs Deleted Foundry command implementation.
tools/Azure.Mcp.Tools.Foundry/src/Commands/AgentsEvaluateCommand.cs Deleted Foundry command implementation.
tools/Azure.Mcp.Tools.Foundry/src/Commands/AgentsCreateCommand.cs Deleted Foundry command implementation.
tools/Azure.Mcp.Tools.Foundry/src/Commands/AgentsConnectCommand.cs Deleted Foundry command implementation.
tools/Azure.Mcp.Tools.Foundry/src/Azure.Mcp.Tools.Foundry.csproj Deleted Foundry tool project definition.
tools/Azure.Mcp.Tools.Foundry/src/AssemblyInfo.cs Deleted test visibility attributes tied to Foundry test projects.
servers/Azure.Mcp.Server/src/Program.cs Removed in-process Foundry area registration.
servers/Azure.Mcp.Server/docs/azmcp-commands.md Removed Foundry CLI docs section and Foundry references in best-practices text.
servers/Azure.Mcp.Server/Azure.Mcp.Server.slnx Removed Foundry tool projects from Azure server solution.
core/Microsoft.Mcp.Core/src/Services/Azure/Authentication/CustomChainedCredential.cs Added forceBrowserFallback and scope normalization support via SafeTokenCredential.
core/Microsoft.Mcp.Core/src/Areas/Server/Resources/registry.json Added external foundry registry entry pointing to https://mcp.ai.azure.com with OAuth scopes.
core/Microsoft.Mcp.Core/src/Areas/Server/Resources/consolidated-tools.json Removed Foundry tool mappings from consolidated tool list/metadata.
core/Microsoft.Mcp.Core/src/Areas/Server/RegistryServerServiceCollectionExtensions.cs Adjusted registry HttpClient auth handler wiring (special-casing single-identity provider).
core/Microsoft.Mcp.Core/src/AccessTokenHandler.cs Added TokenCredential-based constructor for outbound auth handler.
core/Azure.Mcp.Core/tests/Azure.Mcp.Core.UnitTests/Areas/Server/Commands/Discovery/RegistryDiscoveryStrategyTests.cs Added tests asserting foundry registry server discovery and properties.
core/Azure.Mcp.Core/tests/Azure.Mcp.Core.UnitTests/Areas/Server/CommandFactoryHelpers.cs Removed Foundry setup from command factory test helper.
Microsoft.Mcp.slnx Removed Foundry tool projects from root solution.
.github/CODEOWNERS Removed Foundry tool path ownership entries.

g2vinay added 5 commits March 2, 2026 22:20
…changes

- CustomChainedCredentialTests: update reflection-based constructor lookup
  from 2-param to 3-param to match new forceBrowserFallback parameter
  added in commit 9b7c48b

- VisualStudioToolNameTests: remove outer TestContext.Current.CancellationToken
  from the linked CTS for I/O operations; add independent 2-minute timeout
  and Fact(Timeout=180000). In --mode all the server eagerly connects to all
  external MCP registry servers (incl. mcp.ai.azure.com) before responding
  to initialize, which can take 15-60+ seconds.
…tness

- RegistryDiscoveryStrategyTests.cs: remove trailing whitespace on blank lines
  (WHITESPACE errors at lines 474/475 and 496/497 in CI)

- VisualStudioToolNameTests.cs: add ReadJsonLineAsync helper to skip non-JSON
  lines in stdout (e.g. azd subprocess diagnostics) before deserializing
  JSON-RPC responses, fixing JsonException when a non-JSON line appears first
g2vinay added 8 commits March 3, 2026 09:42
…s to prevent registry pollution in playback recordings
… (recorded/playback tests)

RecordingRedirectHandler redirects all outgoing HTTP from the server subprocess
through the test proxy. When --mode all is used, RegistryToolLoader tries to
connect to external registry servers (e.g. mcp.ai.azure.com from registry.json).
Those connection attempts hit the test proxy during an active recording/playback
session, producing unrecorded traffic in playback mode or polluting the recording
sequence in record mode.

Guard in RegistryToolLoader.InitializeAsync: if TEST_PROXY_URL is set (injected
by CommandTestsBase.GetEnvironmentVariables only when a TestProxyFixture is
present), skip discovery and mark as initialized with no clients. This fixes
ALL recorded test classes automatically without per-class overrides.

Also removes the redundant InitializeAsync override from FoundryExtensionsCommandTests
that was added as a per-class workaround for the same root cause.
g2vinay added 3 commits March 3, 2026 12:17
- Add FoundryExtensionsSetup to Program.cs RegisterAreas()
- Add FoundryExtensions projects to Microsoft.Mcp.slnx
- Exclude temp_test folder from Azure.Mcp.Core.UnitTests build
Copy link
Member

@xiangyan99 xiangyan99 left a comment

Choose a reason for hiding this comment

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

Maybe you also want to include the project in servers/Azure.Mcp.Server/Azure.Mcp.Server.slnx. :)

g2vinay added 3 commits March 3, 2026 15:52
The foundry_agents_create tool no longer exists after the foundry ->
foundryextensions namespace migration. Having it in the mappedToolList
for create_foundry_agent_resources caused the server to crash when
starting in consolidated mode (--mode consolidated) because:

1. foundryextensions_threads_create is now registered (via FoundryExtensionsSetup in Program.cs)
2. This made matchingCommands non-empty for create_foundry_agent_resources
3. The DEBUG validation check then threw InvalidOperationException when
   foundry_agents_create was not found in filteredCommands

Fix: Remove foundry_agents_create from the mappedToolList, leaving only
foundryextensions_threads_create which is the current replacement.

Fixes ConsolidatedMode_Should_List_Tools_Successfully test failure.
…ions tests individually to fix playback failures
@g2vinay g2vinay merged commit 8e27acc into microsoft:main Mar 4, 2026
15 checks passed
@github-project-automation github-project-automation bot moved this from Untriaged to Done in Azure MCP Server Mar 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tools-Foundry Azure AI Foundry

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants