MCPonFuncOnACA

MCPonFuncOnACA

🚀 使用 Azure Functions(Python)的远程 MCP 服务器

本项目可在 Azure Functions 上运行一个远程 MCP 服务器。借助此快速入门模板,你能轻松使用 Azure Functions 和 Python 构建并部署自定义远程 MCP 服务器到云端。MCP 服务器通过实验性功能支持,可作为工具提供给语言模型(LLM)。

🚀 快速开始

这是一个快速入门模板,用于轻松构建和部署自定义远程 MCP 服务器到云中使用 Azure Functions 和 Python。MCP 服务器通过实验性功能支持,可以作为工具提供给语言模型(LLM)。MCP 功能需要在函数应用中启用,并且可以在 host.json 中引用实验性捆绑包。

{
"extensions": {
"httpExtension": {},
"mcpExtension": {}
},
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle.Experimental",
"version": "[4.*, 5.0.0)"
}
}

✨ 主要特性

  • 可借助 Azure Functions 和 Python 构建并部署自定义远程 MCP 服务器到云端。
  • MCP 服务器通过实验性功能支持,能作为工具提供给语言模型(LLM)。

📦 安装指南

必要条件

创建函数应用

使用 azd 命令创建一个新的 Azure Functions 应用,并指定运行时为 Python:

azd init --name  --location  --runtime python

进入项目目录并初始化 mcp.json 和其他必要文件:

cd . && azd up

💻 使用示例

基础用法

配置 MCP 服务器

host.json 中启用实验性功能和 MCP 扩展:

{
"extensions": {
"httpExtension": {},
"mcpExtension": {}
},
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle.Experimental",
"version": "[4.*, 5.0.0)"
}
}

mcp.json 中定义 MCP 工具:

{
"myMCPTool": {
"type": "functionTrigger",
"description": "Retrieve attractions at a search location.",
"properties": {},
"trigger": {
"funcName": "get_attractions"
}
}
}

创建函数

src 目录下创建一个 Python 函数文件(例如 function_app.py),并添加以下代码:

import logging
import json

def get_attractions(context):
"""
Retrieves attractions at a search location using the RapidAPI endpoint.

Args:
context: The trigger context containing the input arguments.

Returns:
str: A JSON string containing the attractions or an error message.
"""
content = json.loads(context)
query = content["arguments"].get("query", "").strip()
language_code = content["arguments"].get("languagecode", "en-us").strip()

# Add your logic to call RapidAPI here

return json.dumps({
"result": "Success",
"message": f"Successfully retrieved attractions for {query}"
})

def hello_mcp(context):
"""
A simple function that returns a greeting message.

Args:
context: The trigger context (not used in this function).

Returns:
str: A greeting message.
"""
return "Hello I am MCPTool!"

高级用法

部署到 Azure

使用 azd 命令将项目部署到 Azure:

azd up

这会创建所有必要的 Azure 资源,包括函数应用、存储账户和 API 管理实例。

访问 MCP 服务器

部署完成后,可以从 VS Code 或任何兼容的客户端访问 MCP 服务器。通过 mcp.json 配置工具,并使用以下 URL 访问:

https://.azurewebsites.net/runtime/webhooks/mcp/sse

📚 详细文档

注意事项

下一步

  • 在你的 MCP 服务器上添加 API 管理
  • 在你的 MCP 服务器上启用 内置身份验证
  • 启用 VNET 使用 VNET_ENABLED=true 标志
  • 了解更多关于 Microsoft 的相关 MCP 努力
  • 0 关注
  • 0 收藏,9 浏览
  • system 提出于 2025-10-05 14:21

相似服务问题

相关AI产品