Function,serverless,ai,mcp,cognitive-services,language-model,search,monitoring,insights,identity,scaling
## Description
This architecture deploys a serverless solution based on Azure Functions implementing the Model Context Protocol (MCP) to enhance AI application capabilities through Azure OpenAI and Azure Cognitive Search services.
The architecture implements the Model Context Protocol to:
Enhance Context: The function enriches prompts sent to GPT-4 by adding relevant contextual information retrieved from Azure Cognitive Search.
Index Snippets: Code snippets and other information are stored in Azure Storage containers and indexed by Azure Cognitive Search.
Perform Semantic Search: When receiving a query, the architecture searches for the most relevant snippets using vector search capabilities.
Augment Prompts: Relevant snippets are added to the prompt context before being sent to Azure OpenAI, enabling more precise and contextually appropriate responses.
Manage Permissions: The architecture leverages managed identities to secure access to various resources.
This architecture represents a modern implementation of the Retrieval Augmented Generation (RAG) pattern, utilizing Azure cloud services to significantly enhance the relevance and accuracy of responses generated by OpenAI models.
**N.B:**
- The Terraform code is automatically generated with best practices and contains variables that you can customize to fir your needs.
- You have full control to change, add, delete resources or their configuration. The newly generated code will reflect these changes.
- You can replace some resources with Terraform modules.
> terraform apply status: successful
>
## Architecture components
| Component | Description |
|-----------|-------------|
| **Azure Functions** | Serverless compute service hosting the .NET 8.0 isolated application that implements the Model Context Protocol, deployed on Premium EP1 plan for consistent performance and scaling |
| **Azure OpenAI Service** | Cognitive service providing access to GPT-4 model (version 0613) with 8 capacity units to process natural language understanding and generation tasks |
| **Azure Cognitive Search** | Search-as-a-service solution used to index and retrieve snippets, configured with standard tier providing vector search capabilities for semantic matching |
| **Azure Storage Account** | Provides blob storage for function code, application data, and hosts a dedicated container for snippets that need to be indexed |
| **Application Insights** | Application performance monitoring service that tracks function performance, failures, and usage patterns with live metrics |
| **Log Analytics Workspace** | Centralized logging solution that aggregates and analyzes log data from multiple Azure services within the architecture |
| **User-Assigned Managed Identity** | Security principal that provides identity for the search service to access storage resources without storing credentials in code |
| **System-Assigned Managed Identity** | Automatically created and managed identity tied to the lifecycle of specific Azure resources, used for authenticating to services that support Azure AD authentication |
| **App Service Plan** | Hosting plan (EP1 Premium) that defines the compute resources, scaling capabilities, and pricing tier for the function app |
| **GitHub Integration** | Source control integration with GitHub Actions workflow for continuous integration and deployment of function code |
| **Storage Container** | Dedicated blob container named "snippets" that stores the content to be indexed by the search service |
| **Role Assignment** | RBAC configuration that grants the managed identity "Storage Blob Data Reader" permissions to access the storage account |
## Requirements
| Name | Configuration |
| --- | --- |
| Terraform | all versions |
| Provider | AZURERM|
| Provider version | >= 4.25.0 |
| Access | Admin access |
## How to use the architecture
Clone the architecture and modify the following variables according to your needs:
| Variable Name | Description |
|---------------|-------------|
| `app_service_plan_sku` | App Service Plan SKU determining compute resources and pricing tier (e.g., EP1 for Premium, Y1 for Consumption) |
| `cognitive_deployment` | Object containing OpenAI model deployment details including name, format, type, version, scale type, and capacity |
| `environment` | Deployment environment identifier (dev, staging, prod) used for resource naming |
| `function_app_name` | Base name for the Azure Function App resource |
| `function_project_path` | Path to the .NET function project directory containing the source code |
| `function_runtime` | Runtime stack for the function app (e.g., python, node, dotnet-isolated) |
| `function_runtime_version` | Version of the runtime to use for the function app |
| `function_version` | Version identifier for the Azure Function runtime |
| `github_pat` | GitHub Personal Access Token for connecting App Service to GitHub repository (sensitive value) |
| `location` | Azure region where resources will be deployed |
| `openai_models` | Map of OpenAI models to deploy in the environment |
| `openai_sku` | SKU for the Azure OpenAI service determining capabilities and pricing |
| `project_name` | Name of the project used for resource naming and tagging |
| `search_service_sku` | SKU for Azure Cognitive Search service determining capabilities and pricing |
| `tags` | Map of tags to apply to all deployed resources for governance and cost management |
| | |
Get code source for the azure function : https://github.com/samirbelkessa/Az-MCP-Function.git
Once deployed, you can use the Model Context Protocol Function : https://www.youtube.com/watch?v=XwnEtZxaokg&t=522s
**N.B:**
- Feel free to remove the resources that are not relevant to your use-case.
- Some variables have default values, please change it if it doesn't fit your deployment.
## Maintainer(s)
You can reach out to these maintainers if you need help or assistance:
- [Brainboard team](mailto:support@brainboard.co)