Logo Python MCP 天气服务器与 OAuth 2.1 认证

Python MCP 天气服务器与 OAuth 2.1 认证

Tổ chức
Azure-Samples

A production-ready Model Context Protocol (MCP) server built with FastAPI that provides weather information using the National Weather Service API. Features full MCP OAuth 2.1 compliance with PKCE,…

Nhà phát hànhAzure-Samples
Kho mãremote-mcp-webapp-python-auth-oauth
Ngôn ngữPython
Bản fork
12
Sao
27
Công cụ có sẵn
0
Phương thức truyền tảistreamable-http
Danh mục
Liên kết
  • Kết nối công cụ với quy trình làm việc AI

    Python MCP 天气服务器与 OAuth 2.1 认证 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ở

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

Python MCP Weather Server with OAuth 2.1 Authentication

A production-ready Model Context Protocol (MCP) server built with FastAPI that provides weather information using the National Weather Service API. Features full MCP OAuth 2.1 compliance with PKCE, dynamic client registration, and Azure AD integration. Ready for deployment to Azure App Service with Azure Developer CLI (azd).

🌟 Features

  • MCP OAuth 2.1 Specification Compliant: Complete implementation of MCP Authorization Specification (2025-03-26)
  • PKCE Required: Secure authorization with Proof Key for Code Exchange (RFC 7636, S256 method)
  • Dynamic Client Registration: Automatic client registration per RFC 7591
  • Authorization Server Metadata: Discovery endpoint per RFC 8414
  • Third-Party Authorization: Uses Azure AD as authorization server
  • MCP Protocol Headers: Full support for MCP-Protocol-Version: 2025-03-26
  • JWT Token Management: Secure token-based authentication
  • Weather Tools:
    • get_alerts: Get weather alerts for any US state
    • get_forecast: Get detailed weather forecast for any location
  • Azure Ready: Pre-configured for Azure App Service deployment
  • Web Test Interface: Built-in OAuth 2.1 flow testing

🔐 MCP Authorization Implementation

This server implements the complete MCP Authorization Specification (2025-03-26):

OAuth 2.1 Endpoints

  • GET /.well-known/oauth-authorization-server - Authorization server metadata (RFC 8414)
  • POST /register - Dynamic client registration (RFC 7591)
  • GET /authorize - Authorization endpoint with PKCE (RFC 7636)
  • POST /token - Token endpoint for code exchange and refresh
  • GET /auth/azure/callback - Third-party authorization callback

MCP Protocol Features

  • ✅ Protocol Version Headers: MCP-Protocol-Version: 2025-03-26
  • ✅ PKCE Required: All clients must use S256 method
  • ✅ Dynamic Registration: Automatic client onboarding
  • ✅ JWT Authentication: Bearer token validation on MCP endpoints
  • ✅ Proper Error Handling: 401/403/400 responses with details
  • ✅ Azure AD Integration: Enterprise-grade authorization server

⚠️ Important: Complete OAuth setup required before use. See AUTH_SETUP.md for Azure AD configuration instructions.

💻 Local Development

Prerequisites

  • Python 3.8+
  • Azure account with completed OAuth setup (see AUTH_SETUP.md)

Setup & Run

  1. Complete OAuth setup first: Follow the instructions in AUTH_SETUP.md to create your Azure App Registration.

  2. Clone and install dependencies:

    bash
    git clone <your-repo-url>
    cd remote-mcp-webapp-python-auth-oauth
    python -m venv venv
    .\venv\Scripts\Activate.ps1  # Windows
    # source venv/bin/activate   # macOS/Linux
    pip install -r requirements.txt
  3. Configure environment variables:

    bash
    cp .env.example .env
    # Edit .env with your Azure OAuth credentials from AUTH_SETUP.md
  4. Start the development server:

    bash
    .\start_server.ps1  # Windows
    # or manually:
    uvicorn main:app --host 0.0.0.0 --port 8000 --reload
  5. Access the server:

🔌 Connect to the Local MCP Server

Authentication Required

Before connecting any MCP client, you must authenticate:

  1. Get JWT Token: Visit http://localhost:8000/mcp_oauth_test.html
  2. Complete OAuth Flow: Use the built-in OAuth 2.1 test interface
  3. Copy JWT Token: Use the token in your MCP client configuration

Using MCP Inspector

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

    bash
    npx @modelcontextprotocol/inspector
  2. CTRL+click the URL displayed by the app (e.g. http://localhost:5173/#resources)

  3. Configure authenticated connection:

    • Set transport type to HTTP

    • Set URL to: http://localhost:8000/

    • Add Authorization header: Bearer <your-jwt-token>

    💡 Getting your JWT token: Visit http://localhost:8000/mcp_oauth_test.html to complete the OAuth 2.1 flow and obtain your JWT token.

  4. Test the connection: List Tools, click on a tool, and Run Tool

Configuration for MCP Clients

json
{
  "mcpServers": {
    "weather-mcp-server-local": {
      "transport": {
        "type": "http",
        "url": "http://localhost:8000/",
        "headers": {
          "Authorization": "Bearer <your-jwt-token>"
        }
      },
      "name": "Weather MCP Server (Local with Auth)",
      "description": "Authenticated MCP Server with weather tools"
    }
  }
}
```   > 💡 **Replace `<your-jwt-token>`** with the actual JWT token obtained from the OAuth 2.1 flow at `/mcp_oauth_test.html`.

## 🚀 Quick Deploy to Azure

### Prerequisites

- [Azure CLI](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli)
- [Azure Developer CLI (azd)](https://learn.microsoft.com/en-us/azure/developer/azure-developer-cli/install-azd)
- Active Azure subscription
- **Completed OAuth setup** (see [AUTH_SETUP.md](AUTH_SETUP.md))

### Deploy in 5 Commands

```bash
# 1. Login to Azure
azd auth login

# 2. Initialize the project  
azd init

# 3. Set OAuth environment variables (from your AUTH_SETUP.md)
azd env set AZURE_CLIENT_ID "your-client-id"
azd env set AZURE_TENANT_ID "your-tenant-id"
azd env set AZURE_CLIENT_SECRET "your-client-secret"
azd env set JWT_SECRET_KEY "your-secure-jwt-secret"

# 4. Deploy to Azure (first time to get the URL)
azd up

# 5. Update environment with deployed URL and redeploy
azd env set BASE_URL "https://app-web-[unique-id].azurewebsites.net"
azd env set AZURE_REDIRECT_URI "https://app-web-[unique-id].azurewebsites.net/auth/azure/callback"
azd env set ENVIRONMENT "production"
azd up

Post-Deployment Setup

⚠️ Critical: After deployment, you must update your Azure App Registration:

  1. Note your deployed URL: https://app-web-[unique-id].azurewebsites.net/
  2. Go to Azure Portal → Microsoft Entra ID → App registrations → Your App
  3. Click Authentication → Add redirect URI: https://app-web-[unique-id].azurewebsites.net/auth/azure/callback
  4. Click Save

💡 Note: The redirect URI must be /auth/azure/callback (not /auth/callback) for the MCP OAuth 2.1 flow to work correctly.

Test Your Deployment

After deployment, your authenticated MCP server will be available at:

  • OAuth 2.1 Test Interface: https://<your-app>.azurewebsites.net/mcp_oauth_test.html
  • Health Check: https://<your-app>.azurewebsites.net/health
  • MCP Capabilities: https://<your-app>.azurewebsites.net/mcp/capabilities
  • API Docs: https://<your-app>.azurewebsites.net/docs

🔌 Connect to the Remote MCP Server

Follow the same guidance as the local setup, but use your Azure App Service URL and ensure you have a valid JWT token from the deployed authentication endpoint.

Configuration for deployed server:

json
{
  "mcpServers": {
    "weather-mcp-server-azure": {
      "transport": {
        "type": "http", 
        "url": "https://<your-app>.azurewebsites.net/",
        "headers": {
          "Authorization": "Bearer <your-jwt-token>"
        }
      },
      "name": "Weather MCP Server (Azure with Auth)",
      "description": "Authenticated MCP Server hosted on Azure"
    }
  }
}

🧪 Testing

Interactive OAuth 2.1 Testing

The test interface provides:

  1. Complete OAuth 2.1 Flow: Dynamic client registration → Authorization → Token exchange
  2. PKCE Validation: Test the full Proof Key for Code Exchange flow
  3. MCP Endpoint Testing: Test authenticated weather tools
  4. JWT Token Display: View and validate your authentication tokens
  5. Client Callback Testing: Includes /client-callback endpoint for OAuth flow validation

OAuth Flow Architecture

The server implements a complete OAuth 2.1 flow:

  • Client Registration: Dynamic client registration with auto-generated credentials
  • Authorization: User redirected to Azure AD for authentication
  • Azure Callback: Server receives Azure auth code at /auth/azure/callback
  • Client Callback: Server redirects to client's callback (e.g., /client-callback) with authorization code
  • Token Exchange: Client exchanges authorization code for JWT access token

MCP Client Testing

Test with any MCP-compatible client using the authenticated endpoints and your JWT token.

🌦️ Data Source

This server uses the National Weather Service (NWS) API:

  • Real-time weather alerts and warnings
  • Detailed weather forecasts
  • Official US government weather data
  • No API key required
  • High reliability and accuracy

🔒 Security Features

  • ✅ OAuth 2.1 Compliance: Full MCP Authorization Specification implementation
  • ✅ PKCE Required: S256 method for all authorization flows
  • ✅ Dynamic Client Registration: Secure automatic client onboarding
  • ✅ Azure AD Integration: Enterprise-grade authorization server
  • ✅ JWT Token Security: Configurable expiration and secure validation
  • ✅ Protocol Version Enforcement: MCP-Protocol-Version header validation
  • ✅ Request Logging: Full audit trail with user identification
  • ✅ CORS Protection: Proper cross-origin resource sharing policies

Cài đặt

TypingMind
Yêu cầu:

Node.js 18+

{
  "mcpServers": {
    "azure-samples-remote-mcp-webapp-python-auth-oauth": {
      "command": "",
      "args": []
    }
  }
}

Dùng MCP Python MCP 天气服务器与 OAuth 2.1 认证 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 Python MCP 天气服务器与 OAuth 2.1 认证, 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 kết nối qua URL máy chủ MCP được lưu trữ từ xa trong TypingMind.

Thêm URL máy chủ MCP

Dùng cách này khi Python MCP 天气服务器与 OAuth 2.1 认证 đã được lưu trữ từ xa hoặc nhóm của bạn muốn có một trình kết nối dùng chung cho nhiều người dùng.

1

Mở mục Trình kết nối MCP

Trong TypingMind, vào Plugin, mở mục Trình kết nối MCP, rồi chọn Thêm URL.

  1. Mở TypingMind trong trình duyệt của bạn.
  2. Vào mục Plugin.
  3. Mở mục Trình kết nối MCP.
  4. Nhấp vào Thêm URL.
Biểu mẫu Thêm URL máy chủ MCP tùy chỉnh của TypingMind
2

Dán URL máy chủ

Nhập URL máy chủ của bạn vào trường URL máy chủ. Thêm tên kết nối, mô tả, biểu tượng, header HTTP tùy chỉnh hoặc cài đặt ứng dụng khách OAuth nếu máy chủ yêu cầu.

  1. Dán URL máy chủ của bạn vào trường URL máy chủ.
  2. Nhập tên kết nối cho Python MCP 天气服务器与 OAuth 2.1 认证.
  3. Thêm mô tả và biểu tượng nếu bạn muốn dễ nhận biết kết nối hơn.
  4. Thêm header HTTP tùy chỉnh hoặc thông tin ứng dụng khách OAuth nếu máy chủ yêu cầu xác thực.
3

Tạo kết nối

Nhấp vào Tạo kết nối, sau đó quay lại danh sách Plugin và xác nhận kết nối MCP mới đang hoạt động.

  1. Nhấp vào Tạo kết nối.
  2. Quay lại danh sách trình kết nối MCP.
  3. Xác nhận kết nối Python MCP 天气服务器与 OAuth 2.1 认证 hiển thị trạng thái đang hoạt động.
  4. Làm mới danh sách plugin nếu kết nối chưa xuất hiện ngay.
4

Đổi mô hình mà không cần kết nối lại

Bắt đầu cuộc trò chuyện với mô hình bạn thích, bật các công cụ của Python MCP 天气服务器与 OAuth 2.1 认证 trong mục Plugin và chuyển sang mô hình khác khi cần. Kết nối MCP vẫn sẵn dùng trong không gian làm việc TypingMind.

  1. Bắt đầu cuộc trò chuyện mới trong TypingMind.
  2. Chọn mô hình AI bạn muốn dùng.
  3. Bật các công cụ của Python MCP 天气服务器与 OAuth 2.1 认证 trong mục Plugin.
  4. Yêu cầu mô hình dùng công cụ khi cần.
  5. Chuyển sang mô hình AI khác và dùng lại cùng kết nố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 Python MCP 天气服务器与 OAuth 2.1 认证 giúp tôi làm việc này không?
Python MCP 天气服务器与 OAuth 2.1 认证
Được. Tôi đã đọc.
Đây là kết quả tôi tìm được bằng Python MCP 天气服务器与 OAuth 2.1 认证.

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

Máy chủ MCP Python MCP 天气服务器与 OAuth 2.1 认证 dùng để làm gì?

Python MCP 天气服务器与 OAuth 2.1 认证 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 Python MCP 天气服务器与 OAuth 2.1 认证 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 Python MCP 天气服务器与 OAuth 2.1 认证 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 Python MCP 天气服务器与 OAuth 2.1 认证 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 Python MCP 天气服务器与 OAuth 2.1 认证, 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 Python MCP 天气服务器与 OAuth 2.1 认证 với TypingMind?

Bạn có thể kết nối Python MCP 天气服务器与 OAuth 2.1 认证 trong TypingMind bằng cách thêm URL máy chủ MCP được lưu trữ từ xa của dịch vụ này. Cách này hữu ích khi bạn muốn dùng kết nối MCP từ xa ngay trong không gian làm việc TypingMind.

MCP Python MCP 天气服务器与 OAuth 2.1 认证 cung cấp những công cụ nào trong TypingMind?

Python MCP 天气服务器与 OAuth 2.1 认证 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 Python MCP 天气服务器与 OAuth 2.1 认证 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 Python MCP 天气服务器与 OAuth 2.1 认证 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 👇