kaman05010/azure-mcp-server
If you are the rightful owner of azure-mcp-server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
A Python-based Model Context Protocol (MCP) server that integrates Azure OpenAI with Azure MCP tools to provide intelligent conversational AI capabilities with access to Azure services.
Azure MCP Server
A Python-based Model Context Protocol (MCP) server that integrates Azure OpenAI with Azure MCP tools to provide intelligent conversational AI capabilities with access to Azure services.
Overview
This project creates a bridge between Azure OpenAI and Azure MCP tools, enabling AI conversations that can dynamically call Azure services through MCP tool integration. The server handles tool calls, manages conversation context, and provides a seamless chat interface.
Features
- Azure OpenAI Integration: Uses Azure OpenAI GPT models for conversational AI
- MCP Tool Support: Connects to Azure MCP server for tool execution
- Authentication: Leverages Azure Identity for secure authentication
- Async Architecture: Built with asyncio for efficient concurrent operations
- Interactive Chat: Command-line interface for real-time conversations
- Error Handling: Comprehensive error handling and logging
Architecture
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β User Input βββββΆβ Azure MCP βββββΆβ Azure OpenAI β
β β β Server β β Service β
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β β
βΌ βΌ
ββββββββββββββββββββ βββββββββββββββββββ
β MCP Tools β β AI Response β
β (Azure Services)β β β
ββββββββββββββββββββ βββββββββββββββββββ
Prerequisites
- Python 3.10 or higher (required for MCP package)
- Node.js and npm (for Azure MCP server)
- Azure OpenAI resource
- Azure CLI (for authentication)
Installation
-
Clone the repository:
git clone <repository-url> cd azuremcpserver
-
Create and activate virtual environment:
python3.11 -m venv .venv source .venv/bin/activate # On macOS/Linux
-
Install dependencies:
pip install -r requirements.txt
-
Install Node.js dependencies (for MCP server):
# Node.js will be used automatically via npx # Ensure you have Node.js installed node --version npm --version
Configuration
-
Create environment file:
cp .env.example .env
-
Configure environment variables:
AZURE_OPENAI_ENDPOINT=https://your-resource-name.openai.azure.com/ AZURE_OPENAI_MODEL=gpt-4
-
Authenticate with Azure:
az login
Usage
Running the Server
# Activate virtual environment
source .venv/bin/activate
# Run the server
python src/mcp_server/azure_mcp_server.py
Interactive Chat
Once running, the server will:
- Initialize Azure OpenAI client
- Connect to Azure MCP server
- List available tools
- Start interactive chat loop
Example interaction:
Available tools:
- azure_storage_list
- azure_keyvault_get
- azure_vm_status
Prompt: List all storage accounts in my subscription
AI: I'll help you list the storage accounts. Let me use the Azure storage tool...
[Tool execution and response]
Project Structure
azuremcpserver/
βββ src/
β βββ mcp_server/
β βββ azure_mcp_server.py # Main server implementation
β βββ test_azure_mcp_server.py # Unit tests
βββ requirements.txt # Python dependencies
βββ .env.example # Environment template
βββ .env # Environment variables (create this)
βββ README.md # This file
βββ docs/ # Additional documentation
Development
Running Tests
# Run all tests
python -m pytest src/mcp_server/test_azure_mcp_server.py -v
# Run with coverage
python -m pytest src/mcp_server/test_azure_mcp_server.py -v --cov=src/mcp_server/
# Run specific test
python -m pytest src/mcp_server/test_azure_mcp_server.py::test_run_initialization -v
Code Style
The project follows Python best practices:
- Type hints where applicable
- Async/await for asynchronous operations
- Comprehensive error handling
- Logging for debugging and monitoring
API Reference
Main Functions
run()
Main async function that orchestrates the MCP server operation.
Functionality:
- Initializes Azure OpenAI client
- Connects to MCP server via stdio
- Manages conversation loop
- Handles tool calls and responses
Key Components
- Azure OpenAI Client: Handles AI model interactions
- MCP Client Session: Manages MCP server communication
- Tool Management: Discovers and executes available tools
- Conversation Loop: Maintains chat context and history
Troubleshooting
Common Issues
-
ModuleNotFoundError for 'azure'
- Ensure virtual environment is activated
- Reinstall requirements:
pip install -r requirements.txt
-
MCP package requires Python 3.10+
- Install Python 3.10 or higher
- Create new virtual environment with correct Python version
-
npx command not found
- Install Node.js:
brew install node
(macOS) or equivalent - Verify installation:
npx --version
- Install Node.js:
-
Azure authentication errors
- Run
az login
to authenticate - Verify Azure CLI is installed and configured
- Run
Debug Mode
Enable detailed logging by setting:
logging.basicConfig(level=logging.DEBUG)
Contributing
- Fork the repository
- Create a feature branch:
git checkout -b feature-name
- Make changes and add tests
- Run tests:
python -m pytest
- Submit a pull request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
For issues and questions:
- Create an issue in the repository
- Check the troubleshooting section
- Review Azure OpenAI and MCP documentation