Skip to content

Commit 3bc7ba3

Browse files
authored
Merge pull request #157 from microsoft/softchris-patch-1
docs: Adding APIM case study
2 parents cb4f276 + 302cb23 commit 3bc7ba3

File tree

2 files changed

+192
-1
lines changed

2 files changed

+192
-1
lines changed

09-CaseStudy/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# MCP in Action: Real-World Case Studies
1+
# MCP in Action: Real-World Case Studies
22

33
The Model Context Protocol (MCP) is transforming how AI applications interact with data, tools, and services. This section presents real-world case studies that demonstrate practical applications of MCP in various enterprise scenarios.
44

09-CaseStudy/apimsample.md

Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
# Case Study: Expose REST API in API Management as an MCP server
2+
3+
Azure API Management, is a service that provides a Gateway on top of your API Endpoints. How it works is that Azure API Management acts like a proxy in front of your APIs and can decide what to do with incoming requests.
4+
5+
By using it, you add a whole host of features like:
6+
7+
- **Security**, you can use everything from API keys, JWT to managed identity.
8+
- **Rate limiting**, a great feature is being able to decide how many calls get through per a certain time unit. This helps ensure all users have a great experience and also that your service isn't overwhelmed with requests.
9+
- **Scaling & Load balancing**. You can set up a number of endpoints to balance out the load and you can also decide how to "load balance".
10+
- **AI features like semantic caching**, token limit and token monitoring and more. These are great features that improves responsiveness as well as helps you be on top of your token spending. [Read more here](https://learn.microsoft.com/en-us/azure/api-management/genai-gateway-capabilities).
11+
12+
## Why MCP + Azure API Management?
13+
14+
Model Context Protocol is quickly becoming a standard for agentic AI apps and how to expose tools and data in a consistent way. Azure API Management is a natural choice when you need to "manage" APIs. MCP Servers often integrate with other APIs to resolve requests to a tool for example. Therefore combining Azure API Management and MCP makes a lot of sense.
15+
16+
## Overview
17+
18+
In this specific use case we'll learn to expose API endpoints as an MCP Server. By doing this, we can easily make this endpoints part of an agentic app while also leveraging the features from Azure API Management.
19+
20+
## Key Features
21+
22+
- You select the endpoint methods you want exposed as tools.
23+
- The additional features you get is dependent on what you configure in the policy section for your API. But here we will show you how you can add rate limiting.
24+
25+
## Pre-step: import an API
26+
27+
If you have an API in Azure API Management already great, then you can skip this step. If not, check out this link, [importing an API to Azure API Management](https://learn.microsoft.com/en-us/azure/api-management/import-and-publish#import-and-publish-a-backend-api).
28+
29+
## Expose API as MCP Server
30+
31+
To expose the API endpoints, let's follow these steps:
32+
33+
1. Navigate to Azure Portal and the following address <https://portal.azure.com/?Microsoft_Azure_ApiManagement=mcp>
34+
Navigate to your API Management instance.
35+
36+
1. In the left menu, select APIs > MCP Servers > + Create new MCP Server.
37+
38+
1. In API, select a REST API to expose as an MCP server.
39+
40+
1. Select one or more API Operations to expose as tools. You can select all operations or only specific operations.
41+
42+
![Select methods to expose](https://learn.microsoft.com/en-us/azure/api-management/media/export-rest-mcp-server/create-mcp-server-small.png)
43+
44+
45+
1. Select **Create**.
46+
47+
1. Navigate to the menu option **APIs** and **MCP Servers**, you should see the following:
48+
49+
![See the MCP Server in the main pane](https://learn.microsoft.com/en-us/azure/api-management/media/export-rest-mcp-server/mcp-server-list.png)
50+
51+
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.
52+
53+
## Optional: Configure policies
54+
55+
Azure API Management has the core concept of policies where you set up different rules for your endpoints like for example rate limiting or semantic caching. These policies are authored in XML.
56+
57+
Here's how you can set up a policy to rate limit your MCP Server:
58+
59+
1. In the portal, under APIs, select **MCP Servers**.
60+
61+
1. Select the MCP server you created.
62+
63+
1. In the left menu, under MCP, select **Policies**.
64+
65+
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). Here's XML that will cause it to rate limit:
66+
67+
```xml
68+
<rate-limit-by-key calls="5"
69+
renewal-period="30"
70+
counter-key="@(context.Request.IpAddress)"
71+
remaining-calls-variable-name="remainingCallsPerIP"
72+
/>
73+
```
74+
75+
Here's an image of the policy editor:
76+
77+
![Policy editor](https://learn.microsoft.com/en-us/azure/api-management/media/export-rest-mcp-server/mcp-server-policies-small.png)
78+
79+
## Try it out
80+
81+
Let's ensure our MCP Server is working as intended.
82+
83+
For this, we will use Visual Studio Code and GitHub Copilot and its Agent mode. We will add the MCP server to a *mcp.json* while. By doing so, Visual Studio Code will act as a client with agentic capabilities and end users will be able to type a prompt and interact with said server.
84+
85+
Let's see how, to add the MCP server in Visual Studio Code:
86+
87+
1. Use the MCP: **Add Server command from the Command Palette**.
88+
89+
1. When prompted, select the server type: **HTTP (HTTP or Server Sent Events)**.
90+
91+
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), note how the difference between the transports is `/sse` or `/mcp`.
92+
93+
1. Enter a server ID of your choice. This is not an important value but it will help you remember what this server instance is.
94+
95+
1. Select whether to save the configuration to your workspace settings or user settings.
96+
97+
- **Workspace settings** - The server configuration is saved to a .vscode/mcp.json file only available in the current workspace.
98+
99+
*mcp.json*
100+
101+
```json
102+
"servers": {
103+
"APIM petstore" : {
104+
"type": "sse",
105+
"url": "url-to-mcp-server/sse"
106+
}
107+
}
108+
```
109+
110+
or if you choose streaming HTTP as transport it would be slightly different:
111+
112+
```json
113+
"servers": {
114+
"APIM petstore" : {
115+
"type": "http",
116+
"url": "url-to-mcp-server/mcp"
117+
}
118+
}
119+
```
120+
121+
- **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:
122+
123+
![User setting](https://learn.microsoft.com/en-us/azure/api-management/media/export-rest-mcp-server/mcp-servers-visual-studio-code.png)
124+
125+
1. You also need to add configuration, a header to make sure it authenticates properly towards Azure API Management. It uses a header called **Ocp-Apim-Subscription-Key*.
126+
127+
- Here's how you can add it to settings:
128+
129+
![Adding header for authentication](https://learn.microsoft.com/en-us/azure/api-management/media/export-rest-mcp-server/mcp-server-with-header-visual-studio-code.png), this will cause the a prompt to be displayed to ask your for the API key value which you can find in Azure Portal for your Azure API Management instance.
130+
131+
- To add it to *mcp.json* instead, you can add it like so:
132+
133+
```json
134+
"inputs": [
135+
{
136+
"type": "promptString",
137+
"id": "apim_key",
138+
"description": "API Key for Azure API Management",
139+
"password": true
140+
}
141+
]
142+
"servers": {
143+
"APIM petstore" : {
144+
"type": "http",
145+
"url": "url-to-mcp-server/mcp",
146+
"headers": {
147+
"Ocp-Apim-Subscription-Key": "Bearer ${input:apim_key}"
148+
}
149+
}
150+
}
151+
```
152+
153+
### Use Agent mode
154+
155+
Now we're all set up in either settings or in *.vscode/mcp.json*. Let's try it out.
156+
157+
Theres should be a Tools icon like so, where the exposed tools from your server are listed:
158+
159+
![Tools from the server](https://learn.microsoft.com/en-us/azure/api-management/media/export-rest-mcp-server/tools-button-visual-studio-code.png)
160+
161+
1. Click the tools icon and you should see a list of tools like so:
162+
163+
![Tools](https://learn.microsoft.com/en-us/azure/api-management/media/export-rest-mcp-server/select-tools-visual-studio-code.png)
164+
165+
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. Here's an example prompt:
166+
167+
```text
168+
get information from order 2
169+
```
170+
171+
You will now be presented with a tools icon asking you to proceed calling a tool. Select to continue running the tool, you should now see an output like so:
172+
173+
![Result from prompt](https://learn.microsoft.com/en-us/azure/api-management/media/export-rest-mcp-server/chat-results-visual-studio-code.png)
174+
175+
**what you see above depends what tools you've setup, but the ideas is that you get a textual response like above**
176+
177+
178+
## References
179+
180+
Here's how you can learn more:
181+
182+
- [Tutorial on Azure API Management and MCP](https://learn.microsoft.com/en-us/azure/api-management/export-rest-mcp-server)
183+
- [Python sample: Secure remote MCP servers using Azure API Management (experimental)](https://github.com/Azure-Samples/remote-mcp-apim-functions-python)
184+
185+
- [MCP client authorization lab](https://github.com/Azure-Samples/AI-Gateway/tree/main/labs/mcp-client-authorization)
186+
187+
- [Use the Azure API Management extension for VS Code to import and manage APIs](https://learn.microsoft.com/en-us/azure/api-management/visual-studio-code-tutorial)
188+
189+
- [Register and discover remote MCP servers in Azure API Center](https://learn.microsoft.com/en-us/azure/api-center/register-discover-mcp-server)
190+
- [AI Gateway](https://github.com/Azure-Samples/AI-Gateway) Great repo that shows many AI capabilities with Azure API Management
191+
- [AI Gateway workshops](https://azure-samples.github.io/AI-Gateway/) Contains workshops using Azure Portal, which is a great way to start evaluating AI capabilities.

0 commit comments

Comments
 (0)