Azure APIM MCP

Arjun Thakur 0 Reputation points
2025-12-12T08:22:10.53+00:00

MCP Server in Azure API Management: rewrite-uri Policy Not Applied to Backend Calls

Description:

I am exposing a REST API as an MCP server in Azure API Management. The underlying REST API has:

Base URL: https://backend-service/internal/<resource>

Operation template: GET /api/<resource>

Actual working endpoint: https://backend-service/internal/<resource>/v1/api/<resource>

The MCP server is calling the backend without the /v1 version segment, resulting in 404 errors.

What I've tried:

Applied a rewrite-uri policy to the MCP server API's inbound section:

xml
<inbound>
  <rewrite-uri template="/v1/api/<resource>" />
  <base />
</inbound>

The policy executes without errors, but the final backend call is still made to:

text
https://backend-service/internal/<resource>/api/<resource>

instead of:

text
https://backend-service/internal/<resource>/v1/api/<resource>

Observations:

Direct APIM API calls (non-MCP) with the same operation work correctly and hit the versioned endpoint.

The rewrite-uri policy shows no errors in APIM traces.

The version segment (/v1) is not reflected in the actual backend request URL.

Questions:

Is rewrite-uri supported in MCP server API policies? Is there a known limitation with how MCP processes request paths?

  1. Should path rewriting be placed in a different policy location (e.g., the backend REST API instead)?

Are there alternative approaches to prepend version segments for MCP tool invocations?MCP Server in Azure API Management: rewrite-uri Policy Not Applied to Backend Calls

Description:

I am exposing a REST API as an MCP server in Azure API Management. The underlying REST API has:

  Base URL: `https://backend-service/internal/<resource>`
  
     Operation template: `GET /api/<resource>`
     
        Actual working endpoint: `https://backend-service/internal/<resource>/v1/api/<resource>`
        

The MCP server is calling the backend without the /v1 version segment, resulting in 404 errors.

What I've tried:

Applied a rewrite-uri policy to the MCP server API's inbound section:

   xml
   <inbound>
  <rewrite-uri template="/v1/api/<resource>" />
  <base />
</inbound>

The policy executes without errors, but the final backend call is still made to:

   text
   https://backend-service/internal/<resource>/api/<resource>

instead of:

   text
   https://backend-service/internal/<resource>/v1/api/<resource>

Observations:

  Direct APIM API calls (non-MCP) with the same operation work correctly and hit the versioned endpoint.
  
     The `rewrite-uri` policy shows no errors in APIM traces.
     
        The version segment (`/v1`) is not reflected in the actual backend request URL.
        

Questions:

Is rewrite-uri supported in MCP server API policies? Is there a known limitation with how MCP processes request paths?

Should path rewriting be placed in a different policy location (e.g., the backend REST API instead)?

Are there alternative approaches to prepend version segments for MCP tool invocations?

1.

Azure API Management
Azure API Management
An Azure service that provides a hybrid, multi-cloud management platform for APIs.
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Gowtham CP 7,000 Reputation points Volunteer Moderator
    2025-12-12T08:51:38.0466667+00:00

    Hi Arjun Thakur ,

    Thanks for the question.

    rewrite-uri is not applied in MCP Server APIs MCP Server operations in Azure API Management do not use the standard API pipeline when constructing backend URLs. The backend call is generated from the operation’s original path template and backend base URL, not from the rewritten URI produced by inbound policies. Therefore, rewrite-uri executes but is not used when MCP constructs the backend request. Reference: API Management policy execution flow https://dori-uw-1.kuma-moon.com/azure/api-management/api-management-policies#policy-execution

    Why the backend URL must carry the version prefix Because MCP bypasses inbound path rewrites, the version segment (/v1) must be added using backend-level policies such as set-backend-service or by modifying the backend service-base-url. These policies influence the backend target before MCP generates the request, which makes them effective for MCP tools. Reference: set-backend-service policy https://dori-uw-1.kuma-moon.com/azure/api-management/set-backend-service-policy

    Supported approach today Update the backend base URL so that the MCP request is formed correctly:

    Example:

    <backend>
        <service-base-url>
            https://backend-service/internal/@{context.Request.MatchedParameters.resource}/v1
        </service-base-url>
    </backend>
    

    This ensures the effective backend call becomes: https://backend-service/internal//v1/api/

    Current limitation MCP Server currently does not support path rewriting via rewrite-uri for backend URL construction. Only backend base URL overrides are honored in MCP tool execution paths. This behavior is consistent with the MCP request flow described in API Management documentation. Reference: API Management overview of request processing https://dori-uw-1.kuma-moon.com/azure/api-management/api-management-howto-policies#how-policies-are-applied

    I hope this helps. If the answer is useful, you may accept it to close the thread.

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.