关于 Azure Functions ⚡️❤️ MCP Servers
该示例仓库演示如何借助 Azure Functions 创建 MCP 服务,并在 GitHub Copilot Chat 的 Agent 模式中使用。内容涵盖本地运行、连接配置,以及使用 Terraform 创建 Azure Function 的示例。
主要功能
- 01基于 Azure Functions 创建 MCP 服务
- 02本地启动示例项目
- 03配置 GitHub Copilot Chat 连接
- 04通过 Terraform 创建 Azure Function
适用场景
- 01学习在 Azure Functions 中实现 MCP 服务
- 02在本地使用 MCP Inspector 测试服务
- 03配置 GitHub Copilot Chat 连接本地或远程服务
- 04用 Terraform 部署 Azure Function 基础设施
MCP 相关
仓库示例使用 Azure Functions 的 MCP 扩展创建服务,并展示通过 SSE 连接 MCP Inspector 和 GitHub Copilot Chat。
配置
本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。
工具
本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。
详细介绍
Azure Functions ⚡️❤️ MCP 服务
你好,开发者 👋🏻!这个仓库是我 YouTube 频道上一段视频的配套内容,视频展示了如何借助 Azure Functions 创建 MCP(Model Context Protocol)服务,并在 GitHub Copilot Chat 的 Agent 模式中使用它们。
用于创建 MCP 服务的 NuGet 包 📦
要借助 Azure Functions 创建 MCP 服务,我们可以使用这个库:
dotnet add package Microsoft.Azure.Functions.Worker.Extensions.Mcp --version 1.0.0-preview.2
此 NuGet 包的完整信息请见:https://www.nuget.org/packages/Microsoft.Azure.Functions.Worker.Extensions.Mcp
要测试这段示例代码,你需要在本地运行项目:
func start
你也可以使用 MCP inspector:
npx @modelcontextprotocol/inspector http://localhost:7071/runtime/webhooks/mcp/sse
你还可以使用 GitHub Copilot Chat 与这个 MCP 服务交互。为此,只需创建文件 .vscode/mcp.json,或者在文件 .vscode/settings.json 中添加这一部分:
{
"inputs": [
{
"type": "promptString",
"id": "mcp-azure-function-key",
"description": "Azure Function Key to access the MCP server on Azure",
"password": true
},
{
"type": "promptString",
"id": "mcp-azure-function-name",
"description": "Azure Function name to access the MCP server on Azure"
}
],
"servers": {
"local-mcp-azure-function": {
"type": "sse",
"url": "http://localhost:7071/runtime/webhooks/mcp/sse",
},
// "remote-mcp-azure-function": {
// "type": "sse",
// "url": "https://${input:mcp-azure-function-name}.azurewebsites.net/runtime/webhooks/mcp/sse",
// "headers": {
// "x-functions-key": "${input:mcp-azure-function-key}"
// }
// }
}
}
你也可以通过命令行添加 MCP:
code --add-mcp '{"name": "local-mcp", "type": "sse", "url": "http://localhost:7071/runtime/webhooks/mcp/sse"}'
配置 GitHub Copilot Chat 以使用 MCP 服务 🛠️
此配置由两部分组成:
inputs:让我们无需硬编码某些敏感内容servers:包含所有可为 GitHub Copilot Chat 启用的本地和远程服务。
在这个示例中,我配置了两个服务:一个是在开发环境中运行的 Azure Function,另一个是已部署到 Microsoft Azure 的 Azure Function。正如你在第二项配置中看到的,我使用了第一部分中定义的 inputs,以便使用所创建 Azure Function 的名称及其关联的密钥进行访问。
在 Azure 中创建 Azure Function ⚡️
要在 Azure 中创建 Azure Function,你可以使用 infra 目录中的 Terraform 代码,但需要先创建一个 terraform.tfvars 文件,并填入以下信息:
# ID de la suscripción de Azure
subscription_id = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
# API Key para YouTube, la cual podrías crear aquí: https://console.cloud.google.com/apis/credentials
youtube_api_key = "XXXXXXXXXXXX"
准备好之后,你需要使用 Azure CLI 登录:
az login
然后,你可以运行以下命令来创建 Azure Function:
terraform init
terraform apply
这将会在 Azure 中创建一个 Azure Function,并将其配置为使用此仓库中的代码。请记得在本地计算机上配置 Azure 凭据。
说明
准备好基础设施后,你需要部署 Azure Function 的代码。你可以轻松地使用 Visual Studio Code 插件完成此操作。
准备好之后,当你尝试启动 MCP 服务时,系统会要求你输入要在 Azure 中使用的函数名称和主密钥;你可以在 Azure 门户中找到它们。
回头见 👋🏻!
评论
一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。
