|
| 1 | +--- |
| 2 | +title: Work with Azure AI Foundry Agent Service and MCP Server tools using the Azure AI Foundry for Visual Studio Code extension |
| 3 | +titleSuffix: Azure AI Foundry |
| 4 | +description: Use this article to learn how to use MCP Server tools with Azure AI Foundry Agent Service directly in VS Code. |
| 5 | +manager: mcleans |
| 6 | +ms.service: azure-ai-foundry |
| 7 | +content_well_notification: |
| 8 | + - AI-contribution |
| 9 | +ai-usage: ai-assisted |
| 10 | +ms.topic: how-to |
| 11 | +ms.date: 09/24/2025 |
| 12 | +ms.reviewer: erichen |
| 13 | +ms.author: johalexander |
| 14 | +author: ms-johnalex |
| 15 | +--- |
| 16 | + |
| 17 | +# Work with Azure AI Foundry Agent Service and MCP Server tools in Visual Studio Code (Preview) |
| 18 | + |
| 19 | +In this article, you learn how to add and use the [Model Context Protocol (MCP)](/azure/ai-foundry/agents/how-to/tools/model-context-protocol) tool with Azure AI Agents using the [Azure AI Foundry for Visual Studio Code extension](https://marketplace.visualstudio.com/items?itemName=ms-ai-foundry.vscode-ai-foundry). |
| 20 | + |
| 21 | +After you [build an agent with the Azure AI Foundry Agent Service](./vs-code-agents.md) using this Visual Studio Code extension, you can add [Model Context Protocol (MCP)](/azure/ai-foundry/agents/how-to/tools/model-context-protocol) tools to your agent. |
| 22 | + |
| 23 | + Using or building an MCP server allows your agent to: |
| 24 | + |
| 25 | +- Access up-to-date information from your APIs and services. |
| 26 | +- Retrieve relevant context to enhance the quality of responses from your AI models. |
| 27 | + |
| 28 | +Agents combine AI models with tools to access and interact with your data. |
| 29 | + |
| 30 | +Azure AI Foundry developers can stay productive by developing, testing, and deploying MCP tool calling agents in the familiar and powerful environment of VS Code. |
| 31 | + |
| 32 | +[!INCLUDE [feature-preview](../../includes/feature-preview.md)] |
| 33 | + |
| 34 | +## Create an Azure AI Agent for MCP Tool calling within the designer view |
| 35 | + |
| 36 | +Follow these steps to create an Azure AI Agent to add MCP tools: |
| 37 | + |
| 38 | +- Finish the [Create and edit Azure AI Agents within the designer view](./vs-code-agents.md#create-and-edit-azure-ai-agents-within-the-designer-view) section to sign in to and create your Azure resources and agent. |
| 39 | + |
| 40 | +After creating your agent, you can add tools to it, including MCP tools. |
| 41 | + |
| 42 | +> [!NOTE] |
| 43 | +> For more information about the other tools you can use with Azure AI Agents, see [Tools for Azure AI Agents](/azure/ai-foundry/agents/how-to/tools/overview). |
| 44 | +
|
| 45 | +## Add an existing MCP Server tool to the AI Agent |
| 46 | + |
| 47 | +You can bring multiple remote MCP servers by adding them as tools. For each tool, you need to provide a unique `Server Label` value within the same agent and a `Server URL` value that points to the remote MCP server. |
| 48 | + |
| 49 | +> [!WARNING] |
| 50 | +> The remote MCP servers you use with the MCP tool in this article are made by third parties, not Microsoft. Microsoft doesn't test or verify these servers. For details, see [Considerations for using non-Microsoft services and servers](/azure/ai-foundry/agents/how-to/tools/model-context-protocol?branch=pr-en-us-6966#considerations-for-using-non-microsoft-services-and-servers). |
| 51 | +
|
| 52 | +To add an existing MCP Server tool to your AI Agent, follow these steps: |
| 53 | + |
| 54 | + 1. Select the **Add tool** button in the top-right corner of the **TOOL** section in the designer to show the dropdown. Choose the **MCP Server** tool. |
| 55 | + |
| 56 | +1. Find the remote MCP server that you want to connect to, such as the GitHub MCP server. Create or update an Azure AI Foundry agent with a mcp tool with the following information: |
| 57 | + |
| 58 | + 1. `Server URL`: The URL of the MCP server; for example, [https://gitmcp.io/Azure/azure-rest-api-specs](https://gitmcp.io/Azure/azure-rest-api-specs). |
| 59 | + |
| 60 | + 1. `Server Label`: A unique identifier of this MCP server to the agent; for example, `fetch_rest_api_docs`. |
| 61 | + |
| 62 | + :::image type="content" source="../../media/how-to/get-started-projects-vs-code/agent-mcp-tool-dialog.png" alt-text="Screenshot of the MCP Server tool dialog box." lightbox="../../media/how-to/get-started-projects-vs-code/agent-mcp-tool-dialog.png"::: |
| 63 | + |
| 64 | + 1. Next, select the **Allowed tools** dropdown to choose which tools the MCP server can use: |
| 65 | + |
| 66 | + :::image type="content" source="../../media/how-to/get-started-projects-vs-code/agent-select-mcp-tool.png" alt-text="Screenshot of the MCP Server tool dialog box with the 'Allowed tools' dropdown highlighted." lightbox="../../media/how-to/get-started-projects-vs-code/agent-select-mcp-tool.png"::: |
| 67 | + |
| 68 | +1. After entering the required information, select the **Create tool** button in the bottom-left corner. |
| 69 | + |
| 70 | +### Create Azure AI Agents on the Azure AI Foundry Studio |
| 71 | + |
| 72 | +After you add an MCP tool, update your agent directly on Azure AI Foundry with the following steps: |
| 73 | + |
| 74 | +1. Select the **Create on Azure AI Foundry** button in the bottom-left of the designer. |
| 75 | + |
| 76 | + :::image type="content" source="../../media/how-to/get-started-projects-vs-code/agent-deploy.png" alt-text="Screenshot of the Agent designer with the 'Deploy to Azure AI Foundry' button highlighted." lightbox="../../media/how-to/get-started-projects-vs-code/agent-deploy.png"::: |
| 77 | + |
| 78 | +1. In the VS Code navbar, refresh the **Azure Resources** view. The deployed agent is displayed under the **Agents** subsection. |
| 79 | + |
| 80 | + :::image type="content" source="../../media/how-to/get-started-projects-vs-code/agent-deployed.png" alt-text="Screenshot of the 'Azure Resources' view. The deployed agent is highlighted under the 'Agents' subsection." lightbox="../../media/how-to/get-started-projects-vs-code/agent-deployed.png"::: |
| 81 | + |
| 82 | +#### View the deployed AI Agent details |
| 83 | + |
| 84 | +Selecting the deployed agent opens the **Agent Preferences** page in a view only mode. |
| 85 | + |
| 86 | +- Select the **Edit Agent** button to view the Agent designer and yaml definition of the agent for editing. |
| 87 | +- Select the **Open Code File** button to create a sample code file that uses the agent. |
| 88 | +- Select the **Open Playground** button to open the **Agent Playground**. |
| 89 | + |
| 90 | + :::image type="content" source="../../media/how-to/get-started-projects-vs-code/deployed-agent-view.png" alt-text="Screenshot of the Agent Preferences page with the 'Edit Agent', 'Open Code File', and 'Open Playground' buttons highlighted." lightbox="../../media/how-to/get-started-projects-vs-code/deployed-agent-view.png"::: |
| 91 | + |
| 92 | +### Edit and update the deployed AI Agent |
| 93 | + |
| 94 | +To edit the deployed agent, select the **Edit Agent** button in the **Agent Preferences** page. The agent designer opens with the agent .yaml file. |
| 95 | +Edit the agent's configuration, such as the model, tools, and instructions. After you finish editing, select the **Update on Azure AI Foundry** button in the lower left corner to save your changes. |
| 96 | + |
| 97 | +:::image type="content" source="../../media/how-to/get-started-projects-vs-code/update-agent.png" alt-text="Screenshot of the Agent Preferences page with the 'Update on Azure AI Foundry' button highlighted." lightbox="../../media/how-to/get-started-projects-vs-code/update-agent.png"::: |
| 98 | + |
| 99 | +### Interact with Agents using the MCP Server tool in agents playground |
| 100 | + |
| 101 | +1. Right select on your deployed agent that has an **MCP Server** tool and select the **Open Playground** option, as you did in the previous steps. This action starts a thread with your agent and lets you send messages. |
| 102 | +1. After the **Playground** page is displayed, type a prompt such as "Give me an example for creating a container app" and send it. |
| 103 | +1. Select the authentication mode for the MCP Server tool. Choose the appropriate authentication method and proceed, as in the following image. |
| 104 | + |
| 105 | + :::image type="content" source="../../media/how-to/get-started-projects-vs-code/mcp-tool-authentication.png" alt-text="Screenshot of the MCP Server tool authentication prompt in the Agents Playground." lightbox="../../media/how-to/get-started-projects-vs-code/mcp-tool-authentication.png"::: |
| 106 | +1. Next, select the approval preference for the MCP Server tool. Choose the appropriate approval preference and proceed, as in the following image. |
| 107 | + |
| 108 | + :::image type="content" source="../../media/how-to/get-started-projects-vs-code/mcp-tool-approval-preference.png" alt-text="Screenshot of the MCP Server tool approval preference in the Agents Playground." lightbox="../../media/how-to/get-started-projects-vs-code/mcp-tool-approval-preference.png"::: |
| 109 | + |
| 110 | +1. If you chose `Ask every time` for your approval preference, you need to approve or reject the tool call, as in the following image. |
| 111 | + |
| 112 | + :::image type="content" source="../../media/how-to/get-started-projects-vs-code/mcp-approve-tool.png" alt-text="Screenshot of the MCP Server tool approval prompt in the Agents Playground." lightbox="../../media/how-to/get-started-projects-vs-code/mcp-approve-tool.png"::: |
| 113 | + |
| 114 | +1. The agent uses the model and the MCP Server tools you configured in the agent designer to retrieve the information. The source of the information is displayed in the **Agent Annotations** section, highlighted in the following image. |
| 115 | + :::image type="content" source="../../media/how-to/get-started-projects-vs-code/mcp-tool-response.png" alt-text="Screenshot of the Agents Playground page with agent annotations highlighted in VS Code after using the MCP Server tool." lightbox="../../media/how-to/get-started-projects-vs-code/mcp-tool-response.png"::: |
| 116 | + |
| 117 | +## Cleanup resources |
| 118 | + |
| 119 | +The Azure resources that you created in this article are billed to your Azure subscription. If you don't expect to need these resources in the future, delete them to avoid incurring more charges. |
| 120 | + |
| 121 | +### Delete your agents |
| 122 | + |
| 123 | +[!INCLUDE [tip-left-pane](../../includes/tip-left-pane.md)] |
| 124 | + |
| 125 | +Delete the deployed agent in the [online AI Foundry portal](https://ai.azure.com/?cid=learnDocs). Select **Agents** from the navigation menu on the left, select your agent, then select the **Delete** button. |
| 126 | + |
| 127 | +:::image type="content" source="../../media/how-to/get-started-projects-vs-code/delete-agent.png" alt-text="Screenshot of the AI Foundry portal with Agents from the navigation menu on the left and the Delete button highlighted." lightbox="../../media/how-to/get-started-projects-vs-code/delete-agent.png"::: |
| 128 | + |
| 129 | +### Delete your models |
| 130 | + |
| 131 | +1. In the VS Code navbar, refresh the **Azure Resources** view. Expand the **Models** subsection to display the list of deployed models. |
| 132 | + |
| 133 | +1. Right-click on your deployed model to delete and select the **Delete** option. |
| 134 | + |
| 135 | + :::image type="content" source="../../media/how-to/get-started-projects-vs-code/delete-model.png" alt-text="Screenshot of the model context menu with the Delete option highlighted." lightbox="../../media/how-to/get-started-projects-vs-code/delete-model.png"::: |
| 136 | + |
| 137 | +### Delete your tools |
| 138 | + |
| 139 | +Delete the connected tool with the following steps: |
| 140 | + |
| 141 | +1. Open the Azure portal |
| 142 | +1. Select the Azure Resource Group containing the tool. |
| 143 | +1. Select the **Delete** button. |
| 144 | + |
| 145 | +## Next steps |
| 146 | + |
| 147 | +- Learn about the tools you can use with Azure AI Agents, such as [file search](/azure/ai-services/agents/how-to/tools/file-search?tabs=python&pivots=overview), or [code interpreter](/azure/ai-services/agents/how-to/tools/code-interpreter?tabs=python&pivots=overview). |
0 commit comments