This repository demonstrates an advanced implementation of Azure Functions with Model Context Protocol (MCP) integrated with Azure AI Agents for building intelligent shopping assistants. The project showcases how to create remote MCP servers and AI-powered conversational agents that can handle image generation, file search, and interactive customer service scenarios.
The project consists of three main components:
Located in MCP/remote-mcp-functions-python/, this component provides:
- MCP Tool Endpoints: Custom tools exposed via Azure Functions that can be consumed by AI agents
- Image Generation: Integration with Azure OpenAI DALL-E for AI-powered image creation
- Blob Storage Integration: Snippet storage and retrieval using Azure Blob Storage
- Custom Shop Tools: Specialized tools for the ZavaShop use case (custom shirt design, login, product info)
Key Features:
- Secure HTTPS endpoints with function key authentication
- Server-Sent Events (SSE) for real-time MCP communication
- Extensible tool framework using MCP protocol
- Local development support with Azurite storage emulator
- One-command deployment to Azure using
azd
File: zavashop_voicelive_with_mcp_file_agent.py
This implementation demonstrates:
- Prompt Agent using Azure AI Projects SDK
- MCP Tool Integration: Connects to the remote MCP server for image generation
- File Search Capability: Vector store-based product information retrieval
- Approval Workflow: Demonstrates MCP approval request handling for controlled tool execution
File: zavashop_voicelive_with_tool_genai_file_agent.py
This alternative implementation showcases:
- Function Tools: Direct function call handling within the agent
- Azure OpenAI Image Generation: Inline image generation without external MCP server
- Hybrid Tool Approach: Combines file search and custom function tools
The ZavaShop assistant is an AI-powered customer service agent that can:
- Answer Product Queries: Uses file search to retrieve information from product catalogs
- Generate Custom Designs: Creates visual representations of clothing items based on customer descriptions
- Handle Customer Requests: Assists with login, customization, and personalized shopping experiences
Scenario 1: Product Search
User: "Can you list all SKUs in ZavaShop?"
Agent: Uses file search tool → Returns product information from vector store
Scenario 2: Custom Design Generation
User: "Create a blue Uniqlo-style shirt with the Strava logo"
Agent: Triggers image generation → Returns generated image URL
Scenario 3: Custom Shirt with Running Stats
User: "I want a custom shirt with my marathon stats"
Agent: Prompts for login → Retrieves stats → Generates custom design
- Azure Functions: Serverless compute for MCP server hosting
- Azure AI Foundry: Agent orchestration and conversation management
- Azure OpenAI Service: Image generation (DALL-E) and language models
- Azure Blob Storage: Snippet and image storage
- Azure Vector Store: Product information indexing and search
- Python 3.11+: Primary programming language
- Azure Developer CLI (azd): Simplified deployment
- Azure Functions Core Tools: Local development and debugging
- Model Context Protocol: Standardized AI tool integration
- OpenAI SDK: Agent and response handling
azure-ai-projects: AI agent frameworkazure-functions: Function app frameworkazure-storage-blob: Blob storage integrationazure-identity: Azure authenticationopenai: OpenAI client for agent operationsrequests: HTTP client for API callsPillow: Image processing
AzureMCPDemo/
├── MCP/
│ └── remote-mcp-functions-python/ # Remote MCP Server
│ ├── src/
│ │ ├── function_app.py # MCP tool definitions
│ │ ├── requirements.txt # Python dependencies
│ │ └── imgs/ # Generated images directory
│ ├── infra/ # Azure infrastructure (Bicep)
│ │ ├── main.bicep # Main infrastructure template
│ │ └── app/ # Application-specific resources
│ └── azure.yaml # Azure Developer CLI configuration
├── zavashop_voicelive_with_mcp_file_agent.py # MCP-based agent
├── zavashop_voicelive_with_tool_genai_file_agent.py # Function tool-based agent
└── README.md # This file
-
Azure Subscription: An active Azure subscription
-
Development Tools:
- Python 3.11 or higher
- Azure Functions Core Tools (>=4.0.7030)
- Azure Developer CLI (
azd) - Docker (for Azurite storage emulator)
-
Environment Variables: Create a
.envfile with the following:AZURE_AI_PROJECT_ENDPOINT=<your-ai-project-endpoint> AZURE_AI_MODEL_DEPLOYMENT_NAME=<your-model-deployment> AZURE_OPENAI_ENDPOINT=<your-openai-endpoint> AZURE_OPENAI_DEPLOYMENT_NAME=<your-image-model-deployment> AZURE_OPENAI_API_KEY=<your-api-key> AZURE_OPENAI_API_VERSION=2025-04-01-preview MCP_ENDPOINT=<your-mcp-function-endpoint> ASSET_FILE_PATH=<path-to-product-catalog>
docker run -p 10000:10000 -p 10001:10001 -p 10002:10002 \
mcr.microsoft.com/azure-storage/azuritecd MCP/remote-mcp-functions-python/src
pip install -r requirements.txt
func startThe MCP server will be available at: http://0.0.0.0:7071/runtime/webhooks/mcp/sse
npx @modelcontextprotocol/inspectorConnect to: http://0.0.0.0:7071/runtime/webhooks/mcp/sse
# MCP-based agent
python zavashop_voicelive_with_mcp_file_agent.py
# Function tool-based agent
python zavashop_voicelive_with_tool_genai_file_agent.pycd MCP/remote-mcp-functions-python
azd upThis command will:
- Provision Azure Functions, Storage Account, and other required resources
- Deploy the MCP server code
- Configure security and networking
azd env set VNET_ENABLED true
azd upAfter deployment, get the MCP system key:
az functionapp keys list \
--resource-group <resource_group> \
--name <function_app_name>Update your .env file with:
MCP_ENDPOINT=https://<function-app-name>.azurewebsites.net/runtime/webhooks/mcp/sse?code=<mcp_extension_key>
- hello_mcp: Test connectivity and basic functionality
- custom: Initiate custom shirt design process
- login: Authenticate and retrieve user running statistics
- get_snippet: Retrieve saved code snippets from blob storage
- save_snippet: Save code snippets to blob storage
- gen_image: Generate images using Azure OpenAI DALL-E
Each tool is defined using the MCP protocol with:
- Tool Name: Unique identifier
- Description: Natural language description for AI understanding
- Parameters: JSON schema defining input requirements
- Bindings: Azure Functions bindings for storage/compute integration
Advantages:
- Centralized tool management
- Reusable across multiple agents
- Scalable and maintainable
- Supports approval workflows
Use When:
- Multiple agents need the same tools
- Tools require complex infrastructure
- Governance and approval is required
Advantages:
- Simpler implementation
- Direct function execution
- Lower latency
- No external dependencies
Use When:
- Single agent application
- Simple tool logic
- Rapid prototyping
- Function Keys: All endpoints secured with system keys
- HTTPS Only: Enforced SSL/TLS encryption
- CORS Configuration: Restricted origins
- Optional OAuth: Extensible with Azure AD authentication
- VNet Integration: Network isolation support
- Credential Management: Uses Azure DefaultAzureCredential
- MCP Approval Flow: Manual approval for sensitive operations
- Input Validation: Tool parameters validated before execution
- Audit Logging: All tool calls logged for compliance
- User provides natural language prompt
- Agent processes prompt and calls
gen_imagetool - Azure OpenAI DALL-E generates image (base64)
- Image uploaded to Azure Blob Storage
- Public URL returned to user
- Image can be displayed in UI or used for further processing
- Product catalog uploaded to Azure OpenAI Vector Store
- Agent uses FileSearchTool for semantic search
- Relevant product information retrieved and presented
- Context-aware responses based on inventory
az webapp log tail \
--name <function-app-name> \
--resource-group <resource-group>The MCP Inspector provides:
- Real-time tool discovery
- Interactive tool testing
- Response validation
- Debug information
All deployed functions include Application Insights for:
- Performance monitoring
- Error tracking
- Custom telemetry
- Distributed tracing
- Pay only for execution time
- Automatic scaling
- No idle costs
- Blob storage: Pay for capacity used
- Consider lifecycle policies for old images
- Azure OpenAI: Token-based pricing
- Choose appropriate model tiers for use case
- Environment Management: Use separate environments for dev/test/prod
- Secret Management: Store sensitive data in Azure Key Vault
- Error Handling: Implement comprehensive try-catch blocks
- Logging: Use structured logging for better observability
- Testing: Test tools individually before agent integration
- Documentation: Keep tool descriptions clear for AI understanding
- Versioning: Use agent versioning for safe updates
MCP Connection Fails
- Verify function app is running
- Check function key is correct
- Ensure CORS is configured properly
Image Generation Fails
- Validate Azure OpenAI endpoint and key
- Check deployment name matches
- Verify API version compatibility
File Search Returns No Results
- Confirm vector store is created
- Verify file upload succeeded
- Check agent has correct vector_store_ids
Agent Doesn't Use Tools
- Ensure tool descriptions are clear
- Verify instructions reference tool capabilities
- Check MCP approval wasn't rejected
This is a demonstration project showcasing Azure AI capabilities. Feel free to:
- Fork and experiment with custom tools
- Add new agent capabilities
- Improve error handling and logging
- Share feedback and suggestions
- Azure Functions Documentation
- Azure AI Foundry Documentation
- Model Context Protocol Specification
- Azure OpenAI Service
- Azure Developer CLI
This project is provided as-is for demonstration purposes. Refer to individual component licenses for specific terms.
For issues and questions:
- Review the Remote MCP Functions Python Sample
- Check Azure AI Foundry documentation
- Open an issue in this repository
Built with Azure AI | Powered by Model Context Protocol | Enhanced by OpenAI