Skip to content

Commit 24b7b59

Browse files
authored
Merge pull request #299375 from dlepow/apimmcp
[APIM] MCP server from REST API
2 parents fa5403a + 161e760 commit 24b7b59

16 files changed

+187
-31
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
title: Include file
3+
description: Include file
4+
services: api-center
5+
author: dlepow
6+
7+
ms.service: azure-api-center
8+
ms.topic: include
9+
ms.date: 05/12/2025
10+
ms.author: danlep
11+
ms.custom: Include file
12+
---
13+
14+
## About MCP servers
15+
16+
AI agents are becoming widely adopted because of enhanced large language model (LLM) capabilities. However, even the most advanced models face limitations because of their isolation from external data. Each new data source potentially requires custom implementations to extract, prepare, and make data accessible for the models.
17+
18+
The [model context protocol](https://www.anthropic.com/news/model-context-protocol) (MCP) helps solve this problem. MCP is an open standard for connecting AI models and agents with external data sources such as local data sources (databases or computer files) or remote services (systems available over the internet, such as remote databases or APIs).
19+
20+
### MCP architecture
21+
22+
The following diagram illustrates the MCP architecture:
23+
24+
:::image type="content" source="media/about-mcp-servers/mcp-architecture.png" alt-text="Diagram of model context protocol (MCP) architecture.":::
25+
26+
The architecture consists of the following components:
27+
28+
| Component | Description |
29+
|----------------|-------------------------------------------------------------------------------------------------|
30+
| **MCP hosts** | LLM applications such as chat apps or AI assistants in your IDEs (like GitHub Copilot in Visual Studio Code) that need to access external capabilities |
31+
| **MCP clients**| Protocol clients, inside the host application, that maintain 1:1 connections with servers |
32+
| **MCP servers**| Lightweight programs that each expose specific capabilities and provide context, tools, and prompts to clients |
33+
| **MCP protocol**| Transport layer in the middle |
34+
35+
MCP follows a client-server architecture where a host application can connect to multiple servers. Whenever your MCP host or client needs a tool, it connects to the MCP server. The MCP server then connects to, for example, a database or an API. MCP hosts and servers connect with each other through the MCP protocol.
36+
37+
### Remote versus local MCP servers
38+
39+
MCP utilizes a client-host-server architecture built on [JSON-RPC 2.0 for messaging](https://modelcontextprotocol.io/docs/concepts/architecture). Communication between clients and servers occurs over defined transport layers, and supports primarily two modes of operation:
40+
41+
* **Remote MCP servers** - MCP clients connect to MCP servers over the internet, establishing a connection using HTTP and server-sent events (SSE), and authorizing the MCP client access to resources on the user's account using OAuth.
42+
43+
* **Local MCP servers** MCP clients connect to MCP servers on the same machine, using standard input/output as a local transport method.

articles/api-center/register-discover-mcp-server.md

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,36 +14,7 @@ ms.author: danlep
1414

1515
This article describes how to use Azure API Center to maintain an inventory (or *registry*) of remote model context protocol (MCP) servers and help stakeholders discover them using the API Center portal. MCP servers expose backend APIs or data sources in a standard way to AI agents and models that consume them.
1616

17-
## About MCP servers
18-
19-
AI agents are becoming widely adopted because of enhanced large language model (LLM) capabilities. However, even the most advanced models face limitations because of their isolation from external data. Each new data source potentially requires custom implementations to extract, prepare, and make data accessible for the models.
20-
21-
The [model context protocol](https://www.anthropic.com/news/model-context-protocol) (MCP) helps solve this problem. MCP is an open standard for connecting AI models and agents with external data sources such as local data sources (databases or computer files) or remote services (systems available over the internet, such as remote databases or APIs).
22-
23-
### MCP architecture
24-
25-
The following diagram illustrates the MCP architecture:
26-
27-
:::image type="content" source="media/register-discover-mcp-server/mcp-architecture.png" alt-text="Diagram of model context protocol (MCP) architecture.":::
28-
29-
The architecture consists of the following components:
30-
31-
| Component | Description |
32-
|----------------|-------------------------------------------------------------------------------------------------|
33-
| **MCP hosts** | LLM applications such as chat apps or AI assistants in your IDEs (like GitHub Copilot in Visual Studio Code) that need to access external capabilities |
34-
| **MCP clients**| Protocol clients, inside the host application, that maintain 1:1 connections with servers |
35-
| **MCP servers**| Lightweight programs that each expose specific capabilities and provide context, tools, and prompts to clients |
36-
| **MCP protocol**| Transport layer in the middle |
37-
38-
MCP follows a client-server architecture where a host application can connect to multiple servers. Whenever your MCP host or client needs a tool, it connects to the MCP server. The MCP server then connects to, for example, a database or an API. MCP hosts and servers connect with each other through the MCP protocol.
39-
40-
### Remote versus local MCP servers
41-
42-
MCP utilizes a client-host-server architecture built on [JSON-RPC 2.0 for messaging](https://modelcontextprotocol.io/docs/concepts/architecture). Communication between clients and servers occurs over defined transport layers, and supports primarily two modes of operation:
43-
44-
* **Remote MCP servers** - MCP clients connect to MCP servers over the internet, establishing a connection using HTTP and server-sent events (SSE), and authorizing the MCP client access to resources on the user's account using OAuth.
45-
46-
* **Local MCP servers** MCP clients connect to MCP servers on the same machine, using standard input/output as a local transport method.
17+
[!INCLUDE [about-mcp-servers](includes/about-mcp-servers.md)]
4718

4819
## MCP servers in your API inventory
4920

articles/api-management/TOC.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,8 @@
212212
href: azure-openai-api-from-specification.md
213213
- name: Authenticate and authorize to Azure OpenAI
214214
href: api-management-authenticate-authorize-azure-openai.md
215+
- name: Expose REST API as MCP server
216+
href: export-rest-mcp-server.md
215217
- name: Semantic caching for Azure OpenAI API requests
216218
href: azure-openai-enable-semantic-caching.md
217219
- name: Protect Azure OpenAI keys

articles/api-management/api-management-features.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ author: dlepow
66

77
ms.service: azure-api-management
88
ms.topic: concept-article
9-
ms.date: 10/15/2024
9+
ms.date: 05/12/2025
1010
ms.author: danlep
1111
---
1212

@@ -48,6 +48,9 @@ Each API Management [pricing tier](api-management-key-concepts.md#api-management
4848
| Azure Monitor and Log Analytics request logs | No | Yes | Yes | Yes | Yes | Yes |Yes | Yes |
4949
| Application Insights request logs | Yes | Yes | Yes | Yes | Yes | Yes |Yes | Yes |
5050
| Static IP | No | Yes | Yes | No |Yes | No | Yes | No |
51+
| Export API to Power Platform | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes |
52+
| Export API to Postman | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes |
53+
| Export API to MCP server (preview) | No | No | Yes | No | Yes | No | Yes | No |
5154

5255
<sup>1</sup> Enables the use of Microsoft Entra ID (and Azure AD B2C) as an identity provider for user sign in on the developer portal.<br/>
5356
<sup>2</sup> Including related functionality such as users, groups, issues, applications, and email templates and notifications.<br/>
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
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+
16.4 KB
Loading
85.7 KB
Loading
52.4 KB
Loading
49.1 KB
Loading

0 commit comments

Comments
 (0)