Agent with MCP - Agente Azure AI com Model Context Protocol
pratiknesarkar99/agent-with-mcp
Agente Azure AI com integração MCP para extensão de capacidades
Ver no GitHubProjeto que demonstra como construir um agente de IA alimentado por Azure AI integrando Model Context Protocol (MCP) servers. Inclui exemplo prático de agente de gestão de inventário que consulta níveis de estoque e dados de vendas através de ferramentas MCP, com suporte tanto a integração direta quanto remota.
Instalação
npx convez-ai pratiknesarkar99/agent-with-mcp1 comando no terminal: detecta o formato do repositório (marketplace ou plugin avulso) e instala via Claude Code. Requer Node 18+ e o Claude Code instalado.
Métricas
Casos de uso
- Construir agentes que consultam dados de inventário e vendas
- Integrar MCP servers locais e remotos com Azure AI
- Automatizar recomendações de restock e clearance de produtos
- Implementar multi-turn conversations com function calling
Veredito

Referência sólida para implementar agentes Azure AI com MCP, com exemplos práticos de integração direta e remota. Código bem estruturado e documentado, ideal para quem precisa estender capacidades de agentes com protocolo padronizado.
README
A tradução para o português deste README ainda está na fila.
Agent with MCP (Model Context Protocol)
This project demonstrates how to build an AI agent powered by Azure AI that integrates with Model Context Protocol (MCP) servers to extend its capabilities. The example includes an inventory management agent that queries inventory levels and sales data through MCP tools.
Overview
The project showcases two approaches to using MCP with Azure AI agents:
- Direct MCP Server Integration (
client.py) - Runs a local MCP server and connects it directly to an Azure AI agent with function calling. - Remote MCP Tool Integration (
agent.py) - Uses a publicly available MCP server endpoint (Microsoft Learn API specs).
Project Structure
server.py- MCP server implementation with inventory management toolsclient.py- Azure AI agent client that connects to the local MCP serveragent.py- Example showing how to use remote MCP tools with an Azure AI agentrequirements.txt- Python dependencieslabenv/- Python virtual environment
Prerequisites
- Python 3.13 or higher
- Azure AI Project with:
- A valid project endpoint
- A deployed model (e.g., gpt-4o)
- Appropriate Azure credentials (using DefaultAzureCredential)
Setup
-
Clone the repository and navigate to the project directory:
cd /path/to/agent-with-mcp -
Create a virtual environment (if not already created):
python -m venv labenv source labenv/bin/activate # On Windows: labenv\Scripts\activate -
Install dependencies:
pip install -r requirements.txt -
Configure environment variables: Create a
.envfile in the project root:PROJECT_ENDPOINT=https://<your-project>.ai.azure.com MODEL_DEPLOYMENT_NAME=<your-model-deployment>
Usage
Running the Inventory Agent (Direct MCP Integration)
This example runs a local MCP server and connects an AI agent to it:
python client.py
The agent will:
- Start the local MCP server
- Connect to your Azure AI project
- Enter a chat loop where you can ask questions about inventory
Example prompts:
- "What products should we restock?"
- "Which items should we consider for clearance?"
- "Show me the current inventory levels"
Running the Remote MCP Agent
This example demonstrates using a remote MCP server:
python agent.py
The agent will query the Microsoft Learn API MCP server and respond with Azure CLI commands.
Features
Inventory Agent (client.py)
The MCP server provides two tools:
get_inventory_levels()- Returns current stock levels for all productsget_weekly_sales()- Returns units sold in the last week
The agent uses these tools to:
- Recommend restocking if inventory < 10 and weekly sales > 15
- Recommend clearance if inventory > 20 and weekly sales < 5
Agent Implementation
The agent is built using:
- Azure AI Projects SDK - For agent creation and management
- MCP (Model Context Protocol) - For tool integration
- OpenAI Conversations API - For multi-turn conversations
How It Works
- MCP Server Setup: The server exposes inventory data through standardized MCP tools
- Tool Registration: The agent discovers available MCP tools and registers them
- Function Calling: When the agent needs to access inventory data, it calls the appropriate tool
- Response Processing: Tool outputs are passed back to the model for final response generation
Dependencies
Key packages (see requirements.txt for full list):
azure-ai-projects- Azure AI agent frameworkfastmcp- MCP server implementationazure-identity- Azure authenticationpython-dotenv- Environment variable managementopenai- OpenAI API client
Architecture
User Input
↓
Azure AI Agent
↓
Function Calling Layer
↓
MCP Client ← → MCP Server (local or remote)
↓
Tool Execution (get_inventory_levels, get_weekly_sales)
↓
Response Generation
↓
User Output
Authentication
This project uses Azure's DefaultAzureCredential, which attempts authentication in the following order:
- Environment variables (AZURE_CLIENT_ID, AZURE_CLIENT_SECRET, AZURE_TENANT_ID)
- Azure CLI cached credentials
- Managed Identity (if running on Azure)
- Interactive browser login
Ensure you're authenticated with Azure before running the scripts.
Troubleshooting
Connection Issues
- Verify your
.envfile contains the correctPROJECT_ENDPOINTandMODEL_DEPLOYMENT_NAME - Ensure you have Azure credentials configured
MCP Server Errors
- Check that the Python path in
client.pycorrectly points to your virtual environment's Python executable - Verify the
server.pyfile is in the same directory or the correct path is specified
Import Errors
- Make sure all dependencies are installed:
pip install -r requirements.txt - Verify you're using the correct virtual environment
License
This project is provided as an example for educational purposes.