Hello Elise Mjoen,
Welcome to Microsoft Q&A and Thank you for reaching out.
In addition to inputs given by Jorre De Backer, please see if the following helps
The connectivity failure between the Azure AI Foundry agent and the MCP server exposed through Azure API Management indicates a gateway‑level request handling issue rather than a model or agent limitation.
The error message reflects that the request could not be processed successfully by the API Management layer before reaching the backend REST API. This behavior is commonly observed when endpoint configuration, authentication handling, or streaming support is not fully aligned with MCP invocation requirements.
The following might be the reason for the observed behaviour
- Incorrect MCP endpoint usage -exposing a REST API as an MCP server creates multiple endpoints such as /tools, /mcp, and /sse.Using the wrong endpoint path can lead to 404, 405, or generic 500‑class errors during invocation.
- Conflicting authentication headers - when subscription enforcement is enabled in API Management, only one subscription key is expected. Passing both Ocp-Apim-Subscription-Key and an additional backend key can cause request validation failures at the gateway.
- Missing CORS configuration-MCP tool calls originate from a different domain than the API gateway. Without a configured CORS policy, API Management may block preflight or runtime requests, resulting in silent or generic errors.
- Response buffering or payload inspection-Streaming MCP calls can fail if API Management buffers responses or inspects payloads.Such policies can interrupt streaming behavior and cause timeouts or processing errors.
- Networking constraints in VNET deployments- for API Management deployed inside a virtual network, DNS resolution and outbound connectivity must be permitted. Routing or DNS misconfigurations can lead to intermittent or consistent connection failures.
- Complex MCP tool schema-highly complex or deeply nested schemas increase processing time during /tools discovery. This can result in schema retrieval timeouts or failures before tool invocation.
- Lack of systematic validation and testing-without manual testing of /tools and /mcp, gateway‑level issues can remain undetected. Diagnostics and incremental testing help isolate whether failures occur at the gateway, network, or schema level.
Please check if the following troubleshooting steps help –
1.Please confirm the correct MCP endpoint
- Use the /mcp endpoint for standard MCP invocation.
- Use /sse only when Server‑Sent Events are required.
- Use /tools only for schema validation and testing.
2.Consider simplifying the authentication
- Retain only the API Management subscription key: Ocp-Apim-Subscription-Key
- Remove additional backend keys such as x-api-key from the MCP tool configuration unless explicitly handled within API Management policies.
3.Configure CORS in API Management
- Please add a CORS policy in the inbound section at API or operation scope.
- Start with a permissive policy to validate connectivity, then restrict origins as needed.
4.Review and disable response buffering
- Check inbound and outbound policies for buffering, content validation, or payload logging.
- Remove or disable these policies for streaming MCP endpoints.
5. Validate endpoints manually
- Test GET /tools using curl or Postman to confirm schema retrieval.
- Test POST /mcp with a minimal payload.
- Enable API Management diagnostics to capture detailed request and error information.
6.If applicable , kindly review VNET connectivity
- Confirm DNS resolution for the API Management hostname.
- Ensure outbound traffic from the virtual network to the API Management endpoint is permitted.
7.Simplify MCP schema if needed
- Temporarily reduce schema complexity to identify problematic operations or definitions.
References:
Overview of MCP servers in Azure API Management | Microsoft Learn
Connect to MCP Server Endpoints for agents - Microsoft Foundry | Microsoft Learn
Azure API Management policy reference - cors | Microsoft Learn
Model Context Protocol (MCP): Integrating Azure OpenAI for Enhanced Tool Integration and Prompting | Microsoft Community Hub
Thank you!
Please 'Upvote'(Thumbs-up) and 'Accept' as answer if the reply was helpful. This will be benefitting other community members who face the same issue.