Anciennement appelé Azure AI Services ou Azure Cognitive Services, il s’agit d’une collection unifiée de fonctionnalités d’IA prédéfinies au sein de la plateforme Microsoft Foundry
Hello Fabien COLOIGNIER,
Welcome to Microsoft Q&A .Thank you for reaching out to us.
Thank you for sharing the detailed investigation results, request payload and error messages.
After reviewing the scenario, the key observation is that the same MCP endpoint and OAuth configuration work successfully when the connection is created through Azure AI Foundry, but fail when the connection is created programmatically and then associated with an agent.
The OAuth connection created through the API is successfully created and can be retrieved through management APIs, indicating that the initial creation request is accepted.
However, when the agent attempts to use that connection, Azure AI Foundry returns the following error during tool enumeration Failed to retrieve ConnectorGateway connection
Since the portal-created connection works while the API-created connection does not, the current evidence does not indicate an issue with the MCP endpoint, OAuth application registration, configured scopes or consent flow itself.
Instead, the behavior suggests there may be a difference between the provisioning workflow used by the AI Foundry portal and the direct API creation path for OAuth connections.
A second important observation is that the same connection also fails to delete and returns a server-side 500 InternalServerError.
When both of the following occur:
- Runtime usage of the connection fails
- Deletion of the connection fails
it suggests that the issue may extend beyond the OAuth configuration itself. This behavior warrants further investigation into the connection's backend state and lifecycle processing.
To help isolate the issue, the following checks can be helpful
- Comparing the complete connection definitions
- Export the full GET response for the working portal-created connection.
- Export the full GET response for the failing API-created connection.
- Compare all returned properties, including authentication metadata, connection state information, provider settings, secret references, and system-generated fields.
- Reproducing using a clean test
- Create a new OAuth connection with a unique name.
- Create a new agent.
- Configure the same MCP endpoint and OAuth application.
- Verify whether the behavior reproduces consistently.
- Validating the API workflow
- Confirm whether the portal is using the same API version (2026-03-01) and request sequence as the scripted implementation.
- Review any differences between the portal workflow and direct REST calls.
The following references might be helpful , please check them out
- Add a new connection to your project - Microsoft Foundry | Microsoft Learn
- Code Samples for the Model Context Protocol Tool (Preview) (classic) - Microsoft Foundry (classic) portal | Microsoft Learn
- Code Samples for the Model Context Protocol Tool (Preview) (classic) - Microsoft Foundry (classic) portal | Microsoft Learn
Thank you
Please "Accept" the answer with an "Upvote" if the response was helpful. This will be benefitting other community members who face the same issue.