Table of Contents
- Introduction
- Prerequisites
- Setting Up Azure Foundry AI Agent
- Creating Your First Agent
- Configuring MCP Server Connection
- Testing and Validation
- Troubleshooting
- Next Steps
Introduction
This guide provides complete, step-by-step instructions for connecting to Model Context Protocol (MCP) servers from Azure Foundry AI Agent without writing any code. Azure Foundry AI Agent allows you to create intelligent agents that leverage MCP tools through simple YAML configuration, making it accessible to users of all technical levels.
What You’ll Build
By the end of this guide, you’ll have:
- An Azure Foundry AI Agent connected to a remote MCP server
- The ability to use MCP tools (like getting time in different timezones) through natural language
- A working agent that can orchestrate complex workflows using MCP tools
- Knowledge of how to configure additional MCP servers
Architecture Overview
Why No Code?
Azure Foundry AI Agent is a codeless/low-code solution that uses:
- Visual Designer: Drag-and-drop interface for agent configuration
- YAML Configuration: Simple text-based configuration for advanced settings
- Pre-built Tool Types: Including MCP, OpenAPI, Bing Search, Code Interpreter, and more
- Managed Orchestration: Azure handles all the complex LLM-to-tool communication
Prerequisites
Before you begin, ensure you have:
Azure Environment
-
Azure Subscription
- An active Azure subscription
- Access to create Azure AI Foundry resources
-
Azure AI Foundry Hub
- Create one following the Azure AI Foundry setup guide
- A deployed model (e.g.,
gpt-4,gpt-35-turbo)
-
VS Code with Azure AI Foundry Extension
- Visual Studio Code installed
- Azure AI Foundry for VS Code extension (search for “Azure AI Foundry” in extensions)
- Sign in with your Azure account
MCP Server Access
- MCP Server URL: A publicly accessible MCP server endpoint
- For this tutorial, we use the MCP server described in Building MCP Server with ASP.NET Core
- The server should have an SSE endpoint available (typically
/sse)
Knowledge Requirements
- Basic understanding of Azure cloud concepts
- Familiarity with natural language prompts
- No coding knowledge required!
Setting Up Azure Foundry AI Agent
Step 1: Install VS Code Extension
- Open Visual Studio Code
- Click on the Extensions icon in the left sidebar (or press
Ctrl+Shift+X) - Search for “Azure AI Foundry”
- Click Install on the official Microsoft extension
Step 2: Sign In to Azure
- Click on the Azure icon in the left sidebar (cloud icon)
- Click Sign in to Azure
- Follow the browser authentication flow
- Return to VS Code once authentication completes
Step 3: Set Default Project
- In the VS Code command palette (
Ctrl+Shift+P), type: “Azure AI Foundry: Set Default Project” - Select your Azure subscription
- Select your Azure AI Foundry hub
- Select your project
You’ll see the Azure AI Foundry Explorer panel in the left sidebar showing:
- Your hub name
- Agents section
- Connected resources
Creating Your First Agent
Step 1: Create New Agent
-
In the Azure AI Foundry Explorer panel (left sidebar):
- Locate the Agents section
- Click the "+" icon next to “Agents”
-
A new agent configuration window opens with:
- YAML configuration on the left side
- Visual designer on the right side
Step 2: Configure Basic Agent Settings
In the visual designer panel, fill in these fields:
-
Agent Name (required):
-
Model (required):
- Click the model dropdown
- Select your deployed model (e.g.,
gpt-4,gpt-35-turbo)
-
Description:
-
Instructions:
Step 3: Save Initial Configuration
- Press
Ctrl+S(or use File → Save) - The YAML configuration is automatically saved
Step 4: Review Generated YAML
Your YAML configuration should look like this:
name: my-mcp-time-agent
model:
deployment: gpt-4
parameters:
temperature: 0.7
top_p: 1
description: An agent that can tell you the current time in any timezone using MCP tools
instructions: |
You are a helpful assistant with access to tools for getting time information.
When users ask about the current time in specific locations or timezones,
use the available MCP tools to provide accurate, real-time information.
Always respond with the timezone used for clarity.
tools: []
Configuring MCP Server Connection
Important Note: Manual YAML Configuration Required
Unfortunately, the Azure Foundry visual designer and VS Code extension’s UI currently cannot automatically discover tools from MCP servers. This is a known limitation. However, you can configure MCP servers manually by editing the YAML.
The following steps describe the solution developed during this tutorial:
Step 1: Edit the Agent YAML Configuration
The agent’s YAML file is already open in your editor. Look for the tools: section (currently empty []).
Step 2: Add MCP Server Configuration
Replace the empty tools: [] line with the following MCP server configuration:
tools:
- type: mcp
id: get_time
options:
server_url: https://your-mcp-server-url/sse
Important: Replace https://your-mcp-server-url/sse with your actual MCP server URL.
Step 3: Optional - Specify Allowed Tools
You can optionally restrict which tools the agent can access by adding allowed_tools:
tools:
- type: mcp
id: get_time
options:
server_url: https://your-mcp-server-url/sse
allowed_tools:
- get_current_utc_time
- get_current_time_for_timezone
Step 4: Save Configuration
- Press
Ctrl+S(or File → Save) - The configuration is saved locally
Complete Example YAML
Here’s a complete agent configuration with MCP tools:
name: my-mcp-time-agent
model:
deployment: gpt-4
parameters:
temperature: 0.7
top_p: 1
description: An agent that can tell you the current time in any timezone using MCP tools
instructions: |
You are a helpful assistant with access to tools for getting time information.
When users ask about the current time in specific locations or timezones,
use the available MCP tools to provide accurate, real-time information.
Always respond with the timezone used for clarity.
tools:
- type: mcp
id: get_time
options:
server_url: https://your-mcp-server-url/sse
allowed_tools:
- get_current_utc_time
- get_current_time_for_timezone
Understanding the MCP Configuration
Let’s break down each part of the MCP configuration:
| Field | Purpose | Example |
|---|---|---|
type: mcp |
Identifies this as an MCP tool integration | Always mcp |
id: get_time |
Unique identifier for this MCP server instance | Use descriptive names like get_time, weather_tools, etc. |
server_url |
The HTTPS endpoint of your MCP server | https://your-domain.azurewebsites.net/sse |
allowed_tools |
(Optional) List of tools the agent can use | get_current_utc_time, get_current_time_for_timezone |
Step 5: Deploy Agent to Azure
Once your YAML is configured with the MCP server:
- Look for the “Create Agent on Azure AI Foundry” button in VS Code
- Click it to deploy your agent to Azure
- Wait for the deployment to complete
- You’ll see a notification when the agent is ready
Testing and Validation
Step 1: Access Agent in Azure AI Foundry Portal
- Open the Azure AI Foundry portal
- Navigate to your project
- Find your agent in the Agents section
- Click to open the agent details page
Step 2: Test Using Agent Playground
- In the agent details page, find the Playground or Test tab
- You should see a chat interface
Step 3: Test Simple Queries (No Tools)
Try these messages to verify the agent works:
Test 1: Simple greeting
Expected Response: The agent responds with a friendly greeting. No tools should be called.
Step 4: Test Tool Execution
Try these messages to trigger MCP tool calls:
Test 2: Get current UTC time
Expected Response:
The agent should:
- Recognize you’re asking for time
- Call the
get_current_utc_timeMCP tool - Return the result with the timezone clarified
Test 3: Get time in specific timezone
Expected Response:
Test 4: Multiple timezone queries
Expected Response: The agent should call the MCP tool multiple times and provide times for all three locations.
Troubleshooting
Common Issues and Solutions
Issue 1: “Agent Cannot Find MCP Server”
Symptoms:
- Tool calls fail with “MCP server not found” errors
- Agent responds that tools are unavailable
Solutions:
-
Verify MCP Server URL:
- Ensure the URL in
server_urlis correct - Test the URL in a browser or with curl:
curl -i https://your-mcp-server-url/sse - You should get a 200 status code
- Ensure the URL in
-
Check Server Accessibility:
- Ensure the MCP server is publicly accessible (no VPN/firewall blocking)
- Verify HTTPS is working (not just HTTP)
- Test from a different network if possible
-
Review Configuration:
- Make sure the YAML format is correct
- Verify there are no typos in the
server_url - Ensure proper indentation in the YAML
-
Redeploy Agent:
- After fixing the URL, save the YAML
- Click “Update Agent on Azure AI Foundry” to redeploy
- Wait for deployment to complete
Issue 2: “Tool Execution Times Out”
Symptoms:
- Tool calls take a very long time
- Agent eventually responds with timeout error
Solutions:
-
Check MCP Server Performance:
- Test the MCP server directly:
time curl -i https://your-mcp-server-url/sse - A healthy server should respond within 5 seconds
- Test the MCP server directly:
-
Check Network Connectivity:
- Ensure no network issues between Azure and your MCP server
- If server is on-premise, consider hosting it on Azure (Container Apps, App Service)
-
Increase Timeout (if configurable):
- Some agent configurations allow timeout adjustments
- Check Azure AI Foundry documentation for timeout settings
Issue 3: “Tool Name Not Found” or “Unknown Tool”
Symptoms:
- Agent doesn’t recognize available tools
- Error messages about undefined tools
Solutions:
-
Verify Tool Names:
- Check the MCP server documentation for exact tool names
- Common tool names for the example server:
get_current_utc_timeget_current_time_for_timezone
- Tool names are case-sensitive!
-
Update allowed_tools List:
- If using
allowed_tools, ensure names match exactly:allowed_tools: - get_current_utc_time - get_current_time_for_timezone
- If using
-
Remove allowed_tools (if unsure):
- Remove the
allowed_toolssection to allow all tools:tools: - type: mcp id: get_time options: server_url: https://your-mcp-server-url/sse
- Remove the
Issue 4: “MCP Server Returns Error”
Symptoms:
- Tool calls execute but return errors
- Error messages about invalid parameters
Solutions:
-
Check Tool Arguments:
- For timezone tool, ensure valid IANA timezone identifiers:
- For timezone tool, ensure valid IANA timezone identifiers:
-
Test Tool Directly:
- If possible, test the MCP tool directly using the server’s test interface
- Review the MCP server’s documentation for parameter requirements
-
Check Agent Instructions:
- Your agent’s instructions might need to guide the LLM better
- Add examples to the instructions:
instructions: | When users ask for time, use get_current_time_for_timezone with IANA timezone identifiers like 'America/New_York', 'Europe/London', 'Asia/Tokyo'. Do not use abbreviations like EST or PST.
Issue 5: “Cannot Modify Agent in Portal”
Symptoms:
- Portal shows agent but won’t let you edit it
- Changes don’t save
Solutions:
-
Edit in VS Code Instead:
- Keep editing in VS Code where you created it
- Make changes to the YAML file
- Press
Ctrl+Sto save - Click “Update Agent on Azure AI Foundry”
-
Check Permissions:
- Ensure you have write permissions to the project
- Verify your Azure account has the necessary roles
-
Reload Extension:
- Close and reopen VS Code
- The extension may need to refresh its connection
Issue 6: “YAML Syntax Error”
Symptoms:
- Red squiggly lines in the YAML editor
- Deployment fails with syntax errors
Solutions:
-
Check Indentation:
- YAML is strict about indentation
- Use 2 spaces per indentation level (not tabs)
- Example:
tools: # 0 spaces - type: mcp # 2 spaces id: get_time # 4 spaces options: # 4 spaces server_url: ... # 6 spaces allowed_tools: # 6 spaces - tool_name # 8 spaces
-
Check Quotes:
- String values don’t need quotes unless they contain special characters
- URLs should be quoted if they contain colons or slashes:
server_url: "https://your-server/sse" # Good server_url: https://your-server/sse # Also acceptable
-
Use YAML Validator:
- Copy your YAML to an online validator: https://www.yamllint.com/
- Fix any reported issues
Debugging Tips
-
Enable Verbose Logging:
- Look for agent execution logs in Azure AI Foundry portal
- Logs show which tools were called and their results
-
Test Agent Directly in Portal:
- Use the Playground interface to test
- This provides immediate feedback
-
Check Deployment Status:
- Verify agent deployment completed successfully
- Look for any warning or error messages during deployment
-
Review MCP Server Logs (if accessible):
- Check your MCP server’s logs for connection or execution errors
- This helps identify whether issues are on the agent or server side
Getting Help
If you’re still experiencing issues:
-
Check Microsoft Documentation:
-
Review MCP Server Documentation:
- If using a custom MCP server, consult its documentation
- For the example server, see Building MCP Server with ASP.NET Core
-
Check Azure Status:
- Verify Azure services are operational: https://status.azure.com/
Next Steps
Enhancements to Consider
-
Add Multiple MCP Servers:
tools: - type: mcp id: time_tools options: server_url: https://time-server.azurewebsites.net/sse - type: mcp id: weather_tools options: server_url: https://weather-server.azurewebsites.net/sse -
Combine with Other Tool Types:
- Add Bing Search for web queries
- Add Code Interpreter for calculations
- Add OpenAPI specs for REST API integration
-
Refine Agent Behavior:
- Adjust model parameters (temperature, top_p)
- Enhance instructions with more examples
- Add context about tool capabilities
-
Implement Approval Workflows:
- Configure tools to require approval before execution
- Useful for sensitive operations
-
Monitor and Optimize:
- Track agent usage and performance
- Analyze which tools are used most
- Optimize instructions based on user queries
Integration with Applications
To integrate your agent into applications:
-
Use Agent API:
- Call the agent via REST API from web apps, mobile apps, or services
- Azure AI Foundry provides SDK and API documentation
-
Build Frontend Applications:
- Create a chat UI in React, Vue, or your preferred framework
- Call agent endpoints to get responses
-
Integrate with Existing Systems:
- Connect agents to business applications
- Use as decision-making component in workflows
Learning Resources
- Azure AI Foundry: https://learn.microsoft.com/en-us/azure/ai-foundry/
- Model Context Protocol: https://modelcontextprotocol.io/
- Building MCP Server with ASP.NET Core
- Azure OpenAI: https://learn.microsoft.com/en-us/azure/ai-services/openai/