Logo Remote MCP Apim Functions Python

Remote MCP Apim Functions Python

Tổ chức
Azure-Samples

Azure API Management as AI Gateway to Remote MCP servers.

Nhà phát hànhAzure-Samples
Kho mãremote-mcp-apim-functions-python
Ngôn ngữBicep
Bản fork
79
Sao
130
Công cụ có sẵn
0
Phương thức truyền tảistdio
Giấy phépMIT
Liên kết
  • Kết nối công cụ với quy trình làm việc AI

    Remote MCP Apim Functions Python cung cấp các khả năng MCP mà ứng dụng khách và tác nhân AI tương thích có thể sử dụng.

  • 0 công cụ có sẵn

    Xem các thao tác có thể gọi bên dưới, kèm tên và mô tả nếu máy chủ cung cấp.

  • Cấu hình sẵn để sao chép

    Dùng các đoạn cấu hình cài đặt mẫu để thiết lập máy chủ này trong ứng dụng khách MCP bạn muốn dùng.

  • Chỉ số quan tâm đến mã nguồn mở

    130 sao và 79 bản fork từ kho mã được liên kết.

Secure Remote MCP Servers using Azure API Management (Experimental)

Diagram

Azure API Management acts as the AI Gateway for MCP servers.

This sample implements the latest MCP Authorization specification

This is a sequence diagram to understand the flow.

Deploy Remote MCP Server to Azure

  1. Register Microsoft.App resource provider.

    • If you are using Azure CLI, run az provider register --namespace Microsoft.App --wait.
    • If you are using Azure PowerShell, run Register-AzResourceProvider -ProviderNamespace Microsoft.App. Then run (Get-AzResourceProvider -ProviderNamespace Microsoft.App).RegistrationState after some time to check if the registration is complete.
  2. Run this azd command to provision the api management service, function app(with code) and all other required Azure resources

    shell
    azd up

Test with MCP Inspector

  1. In a new terminal window, install and run MCP Inspector

    shell
    npx @modelcontextprotocol/inspector
  2. CTRL click to load the MCP Inspector web app from the URL displayed by the app (e.g. http://127.0.0.1:6274/#resources)

  3. Set the transport type to SSE

  4. Set the URL to your running API Management SSE endpoint displayed after azd up and Connect:

    shell
    https://<apim-servicename-from-azd-output>.azure-api.net/mcp/sse
  5. List Tools. Click on a tool and Run Tool.

Technical Architecture Overview

This solution deploys a secure MCP (Model Context Protocol) server infrastructure on Azure. The architecture implements a multi-layered security model with Azure API Management serving as an intelligent gateway that handles authentication, authorization, and request routing.

overview diagram

Deployed Azure Resources

The infrastructure provisions the following Azure resources:

Core Gateway Infrastructure

  • Azure API Management (APIM) - The central security gateway that exposes both OAuth and MCP APIs
    • SKU: BasicV2 (configurable)
    • Identity: System-assigned and user-assigned managed identities
    • Purpose: Handles authentication flows, request validation, and secure proxying to backend services

Backend Compute

  • Azure Function App - Hosts the MCP server implementation
    • Runtime: Python 3.11 on Flex Consumption plan
    • Authentication: Function-level authentication with managed identity integration
    • Purpose: Executes MCP tools and operations (snippet management in this example)

Storage and Data

  • Azure Storage Account - Provides multiple storage functions
    • Function hosting: Stores function app deployment packages
    • Application data: Blob container for snippet storage
    • Security: Configured with managed identity access and optional private endpoints

Security and Identity

  • User-Assigned Managed Identity - Enables secure service-to-service authentication

    • Purpose: Allows Function App to access Storage and Application Insights without secrets
    • Permissions: Storage Blob Data Owner, Storage Queue Data Contributor, Monitoring Metrics Publisher
  • Entra ID Application Registration - OAuth2/OpenID Connect client for authentication

    • Purpose: Enables third-party authorization flow per MCP specification
    • Configuration: PKCE-enabled public client with custom redirect URIs

Monitoring and Observability

  • Application Insights - Provides telemetry and monitoring
  • Log Analytics Workspace - Centralized logging and analytics

Optional Network Security

  • Virtual Network (VNet) - When vnetEnabled is true
    • Private Endpoints: Secure connectivity to Storage Account
    • Network Isolation: Functions and storage communicate over private network

Why These Resources?

Azure API Management serves as the security perimeter, implementing:

  • OAuth 2.0/PKCE authentication flows per MCP specification
  • Session key encryption/decryption for secure API access
  • Request validation and header injection
  • Rate limiting and throttling capabilities
  • Centralized policy management

Azure Functions provides:

  • Serverless, pay-per-use compute model
  • Native integration with Azure services
  • Automatic scaling based on demand
  • Built-in monitoring and diagnostics

Managed Identities eliminate the need for:

  • Service credentials management
  • Secret rotation processes
  • Credential exposure risks

Azure API Management Configuration Details

The APIM instance is configured with two primary APIs that work together to implement the MCP authorization specification:

OAuth API (/oauth/*)

This API implements the complete OAuth 2.0 authorization server functionality required by the MCP specification:

Endpoints and Operations

Authorization Endpoint (GET /authorize)

  • Purpose: Initiates the OAuth 2.0/PKCE flow
  • Policy Logic:
    1. Extracts PKCE parameters from MCP client request
    2. Checks for existing user consent (via cookies)
    3. Redirects to consent page if consent not granted
    4. Generates new PKCE parameters for Entra ID communication
    5. Stores authentication state in APIM cache
    6. Redirects user to Entra ID for authentication

Consent Management (GET/POST /consent)

  • Purpose: Handles user consent for MCP client access
  • Features: Consent persistence via secure cookies

OAuth Metadata Endpoint (GET /.well-known/oauth-authorization-server)

  • Purpose: Publishes OAuth server configuration per RFC 8414
  • Returns: JSON metadata about supported endpoints, flows, and capabilities

Client Registration (POST /register)

  • Purpose: Supports dynamic client registration per MCP specification

Token Endpoint (POST /token)

  • Purpose: Exchanges authorization codes for access tokens
  • Policy Logic:
    1. Validates authorization code and PKCE verifier from MCP client
    2. Exchanges Entra ID authorization code for access tokens
    3. Generates encrypted session key for MCP API access
    4. Caches the access token with session key mapping
    5. Returns encrypted session key to MCP client

Named Values and Configuration

The OAuth API uses several APIM Named Values for configuration:

  • McpClientId - The registered Entra ID application client ID
  • EntraIDFicClientId - Service identity client ID for token exchange
  • APIMGatewayURL - Base URL for callback and metadata endpoints
  • OAuthScopes - Requested OAuth scopes (openid + Microsoft Graph)
  • EncryptionKey / EncryptionIV - For session key encryption

MCP API (/mcp/*)

This API provides the actual MCP protocol endpoints with security enforcement:

Endpoints and Operations

Server-Sent Events Endpoint (GET /sse)

  • Purpose: Establishes real-time communication channel for MCP protocol
  • Security: Requires valid encrypted session token

Message Endpoint (POST /message)

  • Purpose: Handles MCP protocol messages and tool invocations
  • Security: Requires valid encrypted session token

Security Policy Implementation

The MCP API applies a comprehensive security policy to all operations:

  1. Authorization Header Validation

    xml
    <check-header name="Authorization" failed-check-httpcode="401" 
                  failed-check-error-message="Not authorized" ignore-case="false" />
  2. Session Key Decryption

    • Extracts encrypted session key from Authorization header
    • Decrypts using AES with stored key and IV
    • Validates token format and structure
  3. Token Cache Lookup

    xml
    <cache-lookup-value key="@($"EntraToken-{context.Variables.GetValueOrDefault("decryptedSessionKey")}")" 
                        variable-name="accessToken" />
  4. Access Token Validation

    • Verifies cached access token exists and is valid
    • Returns 401 with proper WWW-Authenticate header if invalid
  5. Backend Authentication

    xml
    <set-header name="x-functions-key" exists-action="override">
        <value>{{function-host-key}}</value>
    </set-header>

Security Model

The solution implements a sophisticated multi-layer security model:

Layer 1: OAuth 2.0/PKCE Authentication

  • MCP clients must complete full OAuth flow with Entra ID
  • PKCE prevents authorization code interception attacks
  • User consent management with persistent preferences

Layer 2: Session Key Encryption

  • Access tokens are never exposed to MCP clients
  • Encrypted session keys provide time-bounded access
  • AES encryption with secure key management in APIM

Layer 3: Function-Level Security

  • Function host keys protect direct access to Azure Functions
  • Managed identity ensures secure service-to-service communication
  • Network isolation available via VNet integration

Layer 4: Azure Platform Security

  • All traffic encrypted in transit (TLS)
  • Storage access via managed identities
  • Audit logging through Application Insights

This layered approach ensures that even if one security boundary is compromised, multiple additional protections remain in place.

Dùng MCP Remote MCP Apim Functions Python với nhiều mô hình AI

TypingMind kết nối các công cụ MCP ở cấp không gian làm việc, nên sau khi kết nối Remote MCP Apim Functions Python, bạn có thể dùng với nhiều mô hình AI khác nhau trong TypingMind thay vì phải thiết lập riêng cho từng mô hình. MCP này chạy cục bộ thông qua trình kết nối MCP của TypingMind trên thiết bị của bạn.

Hướng dẫn thiết lập để dùng trình kết nối cục bộ

Dùng cách này khi máy chủ MCP cần truy cập các tệp, ứng dụng hoặc tài nguyên riêng tư trên máy tính của bạn.

1

Mở cài đặt MCP

Trong TypingMind, vào Cài đặt, Cài đặt nâng cao, rồi đến Giao thức ngữ cảnh mô hình và chọn Cài trình kết nối.

  1. Mở TypingMind trong trình duyệt của bạn.
  2. Nhấp vào biểu tượng Cài đặt.
  3. Vào Cài đặt nâng cao.
  4. Mở mục Giao thức ngữ cảnh mô hình.
  5. Nhấp vào Cài trình kết nối rồi chọn Thiết bị này.
Màn hình thiết lập trình kết nối MCP của TypingMind với tùy chọn Thiết bị này được chọn
2

Chạy lệnh trình kết nối

Chọn Thiết bị này, sao chép lệnh từ TypingMind và chạy trong Terminal. Giữ tiến trình chạy trong khi bạn dùng MCP.

  1. Sao chép lệnh thiết lập hiển thị trong TypingMind.
  2. Mở Terminal trên macOS hoặc Windows Terminal trên Windows.
  3. Dán và chạy lệnh.
  4. Xác nhận cài đặt gói nếu Terminal hỏi bạn có muốn tiếp tục không.
  5. Giữ tiến trình trong cửa sổ Terminal chạy trong khi dùng các công cụ MCP.
3

Thêm Remote MCP Apim Functions Python làm máy chủ

Khi trạng thái trình kết nối là Sẵn sàng, nhấp vào Sửa máy chủ và dán cấu hình máy chủ MCP.

  1. Đợi đến khi trạng thái trình kết nối hiển thị Sẵn sàng.
  2. Nhấp vào Sửa máy chủ.
  3. Dán cấu hình máy chủ MCP của Remote MCP Apim Functions Python.
  4. Lưu danh sách máy chủ.
  5. Làm mới nếu bạn muốn xác nhận trình kết nối vẫn sẵn sàng.
Cài đặt MCP của TypingMind hiển thị máy chủ đang hoạt động và nút Sửa máy chủ
{
  "mcpServers": {
    "remote-mcp-apim-functions-python": {
      "command": "npx",
      "args": [
        "-y",
        "<mcp-server-package>"
      ]
    }
  }
}
4

Dùng kết nối với nhiều mô hình

Lưu danh sách máy chủ, mở Plugin, bật các công cụ MCP của Remote MCP Apim Functions Python, sau đó chọn bất kỳ mô hình AI nào được hỗ trợ trong TypingMind và dùng các công cụ trong cuộc trò chuyện hoặc gán chúng cho một tác nhân AI.

  1. Mở trang Plugin trong TypingMind.
  2. Bật các công cụ MCP của Remote MCP Apim Functions Python.
  3. Bắt đầu cuộc trò chuyện và chọn mô hình AI bạn muốn dùng.
  4. Dùng các công cụ MCP trong cuộc trò chuyện hoặc gán chúng cho một tác nhân AI.
  5. Chuyển sang mô hình AI khác bất cứ khi nào cần mà không phải kết nối lại MCP.
Cuộc trò chuyện TypingMind dùng các công cụ MCP đã bật với một mô hình AI được chọn
Bạn có thể dùng Remote MCP Apim Functions Python giúp tôi làm việc này không?
Remote MCP Apim Functions Python
Được. Tôi đã đọc.
Đây là kết quả tôi tìm được bằng Remote MCP Apim Functions Python.

Câu hỏi thường gặp

Máy chủ MCP Remote MCP Apim Functions Python dùng để làm gì?

Remote MCP Apim Functions Python là máy chủ MCP cho phép các ứng dụng AI tương thích kết nối với công cụ và ngữ cảnh bên ngoài. Trong TypingMind, bạn chỉ cần thêm máy chủ MCP này một lần để các công cụ của nó có sẵn trong không gian làm việc AI của bạn.

Bạn có thể dùng MCP Remote MCP Apim Functions Python với nhiều mô hình AI trong TypingMind không?

Có. TypingMind kết nối các công cụ MCP ở cấp không gian làm việc, nên bạn có thể dùng Remote MCP Apim Functions Python với nhiều mô hình AI như Claude, ChatGPT, Gemini hoặc các mô hình khác đã cấu hình trong TypingMind mà không cần thiết lập máy chủ MCP riêng cho từng mô hình.

Vì sao nên dùng MCP Remote MCP Apim Functions Python với TypingMind?

TypingMind là một trong những giao diện trò chuyện với LLM tốt nhất vì tập hợp nhiều mô hình AI, prompt, plugin, tác nhân AI, khóa API và công cụ MCP vào một không gian làm việc. Khi kết nối Remote MCP Apim Functions Python, bạn có thể dùng các công cụ MCP của dịch vụ này với những mô hình ưa thích, đồng thời giữ quy trình trò chuyện gọn gàng trong TypingMind.

Làm cách nào để kết nối MCP Remote MCP Apim Functions Python với TypingMind?

Remote MCP Apim Functions Python hoạt động thông qua trình kết nối MCP cục bộ của TypingMind. Đây là lựa chọn phù hợp nhất khi máy chủ MCP cần truy cập tệp cục bộ, ứng dụng máy tính, công cụ dòng lệnh hoặc tài nguyên riêng trên máy tính của bạn.

MCP Remote MCP Apim Functions Python cung cấp những công cụ nào trong TypingMind?

Remote MCP Apim Functions Python cung cấp các chức năng MCP mà bạn có thể bật từ trang Plugin của TypingMind để dùng trong trò chuyện hoặc gán cho tác nhân AI.

Bạn có cần chia sẻ khóa API với TypingMind để dùng MCP Remote MCP Apim Functions Python không?

Không. TypingMind ưu tiên xử lý cục bộ và cho phép bạn kiểm soát nhà cung cấp mô hình, khóa API, prompt và cấu hình MCP. Nếu Remote MCP Apim Functions Python yêu cầu xác thực, hãy thêm các header, cài đặt OAuth hoặc cấu hình cục bộ cần thiết cho máy chủ MCP đó khi tạo kết nối.

Máy chủ MCP liên quan

Xem tất cả

Tạo ngay không gian làm việc AI riêng

Đăng ký bản tin của chúng tôi để nhận thông báo về tính năng mới và các đợt tặng quà sắp tới 👇