|
| 1 | +--- |
| 2 | +title: Expose REST API in API Management as MCP server | Microsoft Docs |
| 3 | +description: Learn how to expose a REST API in Azure API Management as an MCP server, enabling API operations as tools accessible via the Model Context Protocol (MCP). |
| 4 | +author: dlepow |
| 5 | +ms.service: azure-api-management |
| 6 | +ms.topic: how-to |
| 7 | +ms.date: 05/18/2025 |
| 8 | +ms.author: danlep |
| 9 | +--- |
| 10 | + |
| 11 | +# Expose REST API in API Management as an MCP server |
| 12 | + |
| 13 | +[!INCLUDE [api-management-premium-standard-basic](../../includes/api-management-availability-premium-standard-basic.md)] |
| 14 | + |
| 15 | + |
| 16 | +In API Management, you can expose a REST API managed in API Management as a remote [Model Context Protocol (MCP)](https://www.anthropic.com/news/model-context-protocol) server. Expose one or more of the API operations as tools that MCP clients can call using the MCP protocol. |
| 17 | + |
| 18 | +Using API Management to expose remote MCP servers provides centralized control over authentication, authorization, and monitoring. It simplifies the process of exposing APIs as MCP servers while helping to mitigate common security risks and ensuring scalability. |
| 19 | + |
| 20 | +> [!NOTE] |
| 21 | +> This feature is currently in preview. It's being released first to the **AI Gateway Early** [update group](configure-service-update-settings.md). |
| 22 | +
|
| 23 | +In this article, you learn how to: |
| 24 | + |
| 25 | +* Expose a REST API in API Management as an MCP server |
| 26 | +* Configure policies for the MCP server |
| 27 | +* Test the generated MCP server from an MCP client |
| 28 | + |
| 29 | +[!INCLUDE [about-mcp-servers](../api-center/includes/about-mcp-servers.md)] |
| 30 | + |
| 31 | +## Prerequisites |
| 32 | + |
| 33 | ++ Complete the following quickstart: [Create an Azure API Management instance](get-started-create-service-instance.md). Currently only the **Premium**, **Standard**, and **Basic** tiers of API Management support MCP servers. |
| 34 | ++ Make sure that your instance manages a REST API that you'd like to expose as an MCP server. To import a sample API, see [Import and publish your first API](import-and-publish.md). |
| 35 | + > [!NOTE] |
| 36 | + > Only HTTP APIs from API Management can be exposed as MCP servers. |
| 37 | ++ To test the MCP server, you can use Visual Studio Code with access to [GitHub Copilot](https://code.visualstudio.com/docs/copilot/setup). |
| 38 | + |
| 39 | + |
| 40 | +## Expose API as an MCP server |
| 41 | + |
| 42 | + |
| 43 | +1. In the Azure portal, access the MCP server preview at the following URL: |
| 44 | + |
| 45 | + ``` |
| 46 | + https://portal.azure.com/?Microsoft_Azure_ApiManagement=mcp |
| 47 | + ``` |
| 48 | +1. Navigate to your API Management instance. |
| 49 | +1. In the left menu, select **APIs** > **MCP Servers** > **+ Create new MCP Server**. |
| 50 | +1. In **API**, select a REST API to expose as an MCP server. |
| 51 | +1. Select one or more **API Operations** to expose as tools. You can select all operations or only specific operations. |
| 52 | +1. Select **Create**. |
| 53 | +
|
| 54 | +:::image type="content" source="media/export-rest-mcp-server/create-mcp-server-small.png" alt-text="Screenshot of creating an MCP server in the portal." lightbox="media/export-rest-mcp-server/create-mcp-server.png"::: |
| 55 | +
|
| 56 | +The MCP server is created and the API operations are exposed as tools. The MCP server is listed in the **MCP Servers** pane. The **URL** column shows the endpoint of the MCP server that you can call for testing or within a client application. |
| 57 | +
|
| 58 | +
|
| 59 | +:::image type="content" source="media/export-rest-mcp-server/mcp-server-list.png" alt-text="Screenshot of the MCP server list in the portal."::: |
| 60 | +
|
| 61 | +## Configure policies for the MCP server |
| 62 | +
|
| 63 | +Configure one or more API Management [policies](api-management-howto-policies.md) to help manage the MCP server. The policies are applied to all API operations exposed as tools in the MCP server and can be used to control access, authentication, and other aspects of the tools. |
| 64 | +
|
| 65 | +For a tutorial on how to configure policies, see [Transform and protect your API](transform-api.md). |
| 66 | +
|
| 67 | +To configure policies for the MCP server: |
| 68 | +
|
| 69 | +1. In the portal, under **APIs**, select **MCP Servers**. |
| 70 | +1. Select the MCP server you created. |
| 71 | +1. In the left menu, under **MCP**, select **Policies**. |
| 72 | +1. In the policy editor, add or edit the policies you want to apply to the MCP server's tools. The policies are defined in XML format. For example, you can add a policy to limit calls to the MCP server's tools (in this example, 5 calls per 30 second per client IP address). |
| 73 | +
|
| 74 | + ```xml |
| 75 | + <rate-limit-by-key calls="5" renewal-period="30" counter-key="@(context.Request.IpAddress)" remaining-calls-variable-name="remainingCallsPerIP" /> |
| 76 | + ``` |
| 77 | +
|
| 78 | + :::image type="content" source="media/export-rest-mcp-server/mcp-server-policies-small.png" alt-text="Screenshot of the policy editor for an MCP server." lightbox="media/export-rest-mcp-server/mcp-server-policies.png"::: |
| 79 | +
|
| 80 | +## Test and use the MCP server |
| 81 | +
|
| 82 | +To verify that the MCP server is working, you can use Visual Studio Code to send requests to the MCP server tools. |
| 83 | +
|
| 84 | +In Visual Studio Code, use GitHub Copilot chat in agent mode (preview) to add the MCP server and use the tools. For background about MCP servers in Visual Studio Code, see [Use MCP Servers in VS Code (Preview)](https://code.visualstudio.com/docs/copilot/chat/mcp-servers). |
| 85 | +
|
| 86 | +### Add the MCP server in Visual Studio Code |
| 87 | +
|
| 88 | +To add the MCP server in Visual Studio Code: |
| 89 | +
|
| 90 | +1. Use the **MCP: Add Server** command from the Command Palette. |
| 91 | +
|
| 92 | +1. When prompted, select the server type: **HTTP (HTTP or Server Sent Events)**. |
| 93 | +1. Enter the **URL of the MCP server** in API Management. Example: `https://<apim-service-name>.azure-api.net/<api-name>-mcp/sse` (for SSE endpoint) or `https://<apim-service-name>.azure-api.net/<api-name>-mcp/mcp` (for MCP endpoint) |
| 94 | +1. Enter a **server ID** of your choice. |
| 95 | +1. Select whether to save the configuration to your **workspace settings** or **user settings**. |
| 96 | + * **Workspace settings** - The server configuration is saved to a `.vscode/mcp.json` file only available in the current workspace. |
| 97 | +
|
| 98 | + * **User settings** - The server configuration is added to your global `settings.json` file and is available in all workspaces. The configuration looks similar to the following: |
| 99 | +
|
| 100 | + :::image type="content" source="media/export-rest-mcp-server/mcp-servers-visual-studio-code.png" alt-text="Screenshot of MCP servers configured in Visual Studio Code."::: |
| 101 | + |
| 102 | +Add fields to the JSON configuration for settings such as authentication header. The following example shows the configuration for an API Management subscription key passed in a header as in input value. Learn more about the [configuration format](https://code.visualstudio.com/docs/copilot/chat/mcp-servers#_configuration-format) |
| 103 | +
|
| 104 | +:::image type="content" source="media/export-rest-mcp-server/mcp-server-with-header-visual-studio-code.png" alt-text="Screenshot of authentication header configuration for an MCP server"::: |
| 105 | +
|
| 106 | +### Use tools in agent mode |
| 107 | +
|
| 108 | +After adding an MCP server, you can use tools in agent mode. |
| 109 | +
|
| 110 | +1. In GitHub Copilot chat, select **Agent** mode and select the **Tools** button to see available tools. |
| 111 | +
|
| 112 | + :::image type="content" source="media/export-rest-mcp-server/tools-button-visual-studio-code.png" alt-text="Screenshot of Tools button in chat."::: |
| 113 | +
|
| 114 | +1. Select one or more tools from the MCP server to be available in the chat. |
| 115 | +
|
| 116 | + :::image type="content" source="media/export-rest-mcp-server/select-tools-visual-studio-code.png" alt-text="Screenshot of selecting tools in Visual Studio Code."::: |
| 117 | +
|
| 118 | +1. Enter a prompt in the chat to invoke the tool. For example, if you selected a tool to get information about an order, you can ask the agent about an order. |
| 119 | +
|
| 120 | + ```copilot-prompt |
| 121 | + Get information for order 2 |
| 122 | + ``` |
| 123 | +
|
| 124 | + Select **Continue** to see the results. The agent uses the tool to call the MCP server and returns the results in the chat. |
| 125 | + |
| 126 | + :::image type="content" source="media/export-rest-mcp-server/chat-results-visual-studio-code.png" alt-text="Screenshot of chat results in Visual Studio Code."::: |
| 127 | +
|
| 128 | +## Related content |
| 129 | +
|
| 130 | +* [Python sample: Secure remote MCP servers using Azure API Management (experimental)](https://github.com/Azure-Samples/remote-mcp-apim-functions-python) |
| 131 | +
|
| 132 | +* [MCP client authorization lab](https://github.com/Azure-Samples/AI-Gateway/tree/main/labs/mcp-client-authorization) |
| 133 | +
|
| 134 | +* [Use the Azure API Management extension for VS Code to import and manage APIs](visual-studio-code-tutorial.md) |
| 135 | +
|
| 136 | +* [Register and discover remote MCP servers in Azure API Center](../api-center/register-discover-mcp-server.md) |
| 137 | +
|
0 commit comments