|
| 1 | +# Azure Functions ⚡️❤️ MCP Servers |
| 2 | + |
| 3 | +> **Idiomas / Languages:** [🇪🇸 Español](README.md) | [🇺🇸 English](README_en.md) |
| 4 | +
|
| 5 | +Hello developer 👋🏻! This repo is part of a video from my YouTube channel that shows how we can create MCP (Model Context Protocol) servers using Azure Functions and use them with GitHub Copilot Chat agent mode. |
| 6 | + |
| 7 | +[](https://github.com/0GiS0/mcp-server-azure-function) |
| 8 | + |
| 9 | +## NuGet package for creating MCP servers 📦 |
| 10 | + |
| 11 | +To create MCP servers using Azure Functions we can use this library: |
| 12 | + |
| 13 | +```bash |
| 14 | +dotnet add package Microsoft.Azure.Functions.Worker.Extensions.Mcp --version 1.0.0-preview.2 |
| 15 | +``` |
| 16 | + |
| 17 | +Here you have all the information about this NuGet package: https://www.nuget.org/packages/Microsoft.Azure.Functions.Worker.Extensions.Mcp |
| 18 | + |
| 19 | +To test this sample code, you need to run the project locally: |
| 20 | + |
| 21 | +```bash |
| 22 | +func start |
| 23 | +``` |
| 24 | + |
| 25 | +And you can use MCP inspector: |
| 26 | + |
| 27 | +```bash |
| 28 | +npx @modelcontextprotocol/inspector http://localhost:7071/runtime/webhooks/mcp/sse |
| 29 | +``` |
| 30 | + |
| 31 | +You can also use GitHub Copilot Chat to interact with this MCP server. For this you just need to create the `.vscode/mcp.json` file or you can include this section inside the `.vscode/settings.json` file: |
| 32 | + |
| 33 | + |
| 34 | +```javascript |
| 35 | +{ |
| 36 | + "inputs": [ |
| 37 | + { |
| 38 | + "type": "promptString", |
| 39 | + "id": "mcp-azure-function-key", |
| 40 | + "description": "Azure Function Key to access the MCP server on Azure", |
| 41 | + "password": true |
| 42 | + }, |
| 43 | + { |
| 44 | + "type": "promptString", |
| 45 | + "id": "mcp-azure-function-name", |
| 46 | + "description": "Azure Function name to access the MCP server on Azure" |
| 47 | + } |
| 48 | + ], |
| 49 | + "servers": { |
| 50 | + "local-mcp-azure-function": { |
| 51 | + "type": "sse", |
| 52 | + "url": "http://localhost:7071/runtime/webhooks/mcp/sse", |
| 53 | + }, |
| 54 | + // "remote-mcp-azure-function": { |
| 55 | + // "type": "sse", |
| 56 | + // "url": "https://${input:mcp-azure-function-name}.azurewebsites.net/runtime/webhooks/mcp/sse", |
| 57 | + // "headers": { |
| 58 | + // "x-functions-key": "${input:mcp-azure-function-key}" |
| 59 | + // } |
| 60 | + // } |
| 61 | + } |
| 62 | +} |
| 63 | +``` |
| 64 | + |
| 65 | +You can also add the MCP through the command line: |
| 66 | + |
| 67 | +```bash |
| 68 | +code --add-mcp '{"name": "local-mcp", "type": "sse", "url": "http://localhost:7071/runtime/webhooks/mcp/sse"}' |
| 69 | +``` |
| 70 | +## GitHub Copilot Chat configuration for using the MCP server 🛠️ |
| 71 | + |
| 72 | +This configuration consists of two main parts: |
| 73 | + |
| 74 | +- `inputs`: which will allow us to avoid hardcoding certain sensitive content |
| 75 | +- `servers`: which will be all those servers, local and remote, that we will be able to enable for GitHub Copilot Chat. |
| 76 | + |
| 77 | +In this example I have the configuration for two servers, the Azure Function that I'm running in development environment and the Azure Function that I already have deployed in Microsoft Azure. As you can see in this second configuration, I use the inputs defined in the first section to use the name of the created Azure Function and the key associated with it to be able to access it. |
| 78 | + |
| 79 | +## Creating an Azure Function in Azure ⚡️ |
| 80 | + |
| 81 | +To create an Azure Function in Azure, you can use the Terraform code hosted in the `infra` directory, but first you need to create a `terraform.tfvars` file with the following information: |
| 82 | + |
| 83 | +```hcl |
| 84 | +# Azure subscription ID |
| 85 | +subscription_id = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" |
| 86 | +# API Key for YouTube, which you could create here: https://console.cloud.google.com/apis/credentials |
| 87 | +youtube_api_key = "XXXXXXXXXXXX" |
| 88 | +``` |
| 89 | + |
| 90 | +Once you have it, you need to log in with Azure CLI: |
| 91 | + |
| 92 | +```bash |
| 93 | +az login |
| 94 | +``` |
| 95 | + |
| 96 | +And then you can run the following commands to create the Azure Function: |
| 97 | + |
| 98 | +```bash |
| 99 | +terraform init |
| 100 | +terraform apply |
| 101 | +``` |
| 102 | +This will create an Azure Function in Azure and configure it to use the code from this repository. Remember that you must have Azure credentials configured on your local machine. |
| 103 | + |
| 104 | +> [!NOTE] |
| 105 | +> Once you have the infrastructure, you must deploy the code of your Azure Function. You can do it easily using the Visual Studio Code plugin. |
| 106 | +
|
| 107 | +Once you have it, when you try to start the MCP server, it will ask you for the name of the function you want to use in Azure and the master key, which you can find in the Azure portal. |
| 108 | + |
| 109 | + |
| 110 | +See you later 👋🏻! |
0 commit comments