Back to MCP directory
publicPublicdnsLocal runtime

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

Runtime guide

cloud

Hosted runtime

Hosted servers run from a provider-managed environment. You usually connect the MCP client to the hosted endpoint or follow the provider's authorization flow, without keeping a local process alive

  1. Open provider connection page
  2. Authorize or copy endpoint
  3. Connect from your MCP client
terminal

Local runtime / other methods

Local servers run on your own machine or infrastructure. You normally copy the server_config into your MCP client, install the required package, and provide env variables from env_schema when needed

  1. Copy server_config
  2. Install required package
  3. Fill env variables and restart client