返回 MCP 目录
public公开dns本地运行

MCPonFuncOnACA

该项目是一个基于Azure Functions和Python的远程MCP服务器快速启动模板,支持通过HTTPS和安全密钥进行通信,并集成了Booking COM旅游API实现景点查询和评价功能。

article

README

🚀 使用 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 <your_function_app_name> --location <region> --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://<your_function_app_name>.azurewebsites.net/runtime/webhooks/mcp/sse

📚 详细文档

注意事项

下一步

help

运行方式说明

cloud

托管运行

托管运行通常表示这个 MCP Server 由服务方环境承载,用户一般按页面提供的连接方式或授权流程接入,不需要在本地长期启动一个 MCP 进程

  1. 打开服务方连接页
  2. 完成授权或复制端点
  3. 在 MCP 客户端中连接
terminal

本地运行 / 其它方式

本地运行通常需要用户在自己的电脑或服务器上安装依赖,把 server_config 复制到 MCP 客户端,并按 env_schema 补齐环境变量、密钥或其它配置

  1. 复制 server_config
  2. 安装所需依赖
  3. 补齐环境变量后重启客户端