AA

alejandro-ao/mcp-fastapi-auth

Developer tools

このページは AI により自動翻訳されています。技術的な詳細は原文をご確認ください。 原文を見る

17 stars 18 forks 品質 43 トレンド 21

OAuth 2.1 と ScaleKit の FastAPI で MCP Auth のデモ

概要

これは、Scalkitを使用してOAuth 2.1認証を認可サーバーとして実装するセキュアなモデルコンテキストプロトコル(MCP)サーバーです。 サーバは、適切な認証と認可を確保しながら、Tavily APIを介してWeb検索機能を提供します。 MCP(Model Context Protocol)は、LMSとツールとリソース間の通信用に設計されたプロトコルです。 この実装は、OAuth 2.1 認証を介してエンタープライズレベルのセキュリティを追加し、アクセス制御が重要である生産展開に適しています。 - : スケールキット認証サーバーを使用してセキュアなアクセス - : MCP認証仕様を実装 - : Tavily API経由でWeb検索機能を提供 - : 自動クライアント登録をサポート - : 適切なオーディエンスチェックでアクセストークンを検証 - : PKCE、適切なエラー処理、およびトークンオーディエンス検証を実行 1. : Scalekit 2. でサインアップ : Tavily 3 から API キーを取得する.

概要(AI 翻訳)

これは、Scalkitを使用してOAuth 2.1認証を認可サーバーとして実装するセキュアなモデルコンテキストプロトコル(MCP)サーバーです。 サーバは、適切な認証と認可を確保しながら、Tavily APIを介してWeb検索機能を提供します。

MCPとは?

MCP(Model Context Protocol)は、LMSとツールとリソース間の通信用に設計されたプロトコルです。 この実装は、OAuth 2.1 認証を介してエンタープライズレベルのセキュリティを追加し、アクセス制御が重要である生産展開に適しています。

##特徴

  • OAuth 2.1 認証: Scalekit 認可サーバーを使用してセキュアなアクセス
  • MCPの承諾:MCPの承認の指定を実装して下さい -Web検索: Tavily API経由でWeb検索機能を提供
  • ダイナミッククライアント登録: 自動クライアント登録をサポート
  • トークン検証: アクセストークンを適切なオーディエンスで検証 -Security Best Practices:PKCE、適切なエラー処理、およびトークンオーディエンスの検証を実行

前提条件

1.Scalekit Account: スケールキットでサインアップ 2.Tavily API Key:TavilyからAPIキーを取得する 3。 Python 3.

このページは AI により自動翻訳されています。技術的な詳細は原文をご確認ください。

README

以下は原文 README の抜粋です。原文を見る。

MCP Server with OAuth 2.1 Authentication

This is a secure Model Context Protocol (MCP) server that implements OAuth 2.1 authentication using Scalekit as the authorization server. The server provides web search capabilities through the Tavily API while ensuring proper authentication and authorization.

What is MCP?

MCP (Model Context Protocol) is a protocol designed for communication between LLMs and tools or resources. This implementation adds enterprise-grade security through OAuth 2.1 authentication, making it suitable for production deployments where access control is critical.

Features

  • OAuth 2.1 Authentication: Secure access using Scalekit authorization server
  • MCP Compliance: Implements the MCP authorization specification
  • Web Search: Provides web search functionality via Tavily API
  • Dynamic Client Registration: Supports automatic client registration
  • Token Validation: Validates access tokens with proper audience checking
  • Security Best Practices: Implements PKCE, proper error handling, and token audience validation

Prerequisites

  1. Scalekit Account: Sign up at Scalekit
  2. Tavily API Key: Get your API key from Tavily
  3. Python 3.11+: Required for running the server

Setup

1. Install Dependencies

pip install -e .

2. Configure Environment Variables

Copy the example environment file and configure your settings:

cp .env.example .env

Edit .env with your actual values:

# Your Scalekit environment URL
SCALEKIT_ENVIRONMENT_URL=https://your-company.scalekit.com

# Your MCP server's resource identifier
RESOURCE_IDENTIFIER=https://your-mcp-server.com

# Server port (optional)
PORT=10000

# Tavily API key
TAVILY_API_KEY=your_tavily_api_key_here

3. Configure Scalekit

In the Scalekit dashboard:

  1. Navigate to MCP servers and click Add MCP server
  2. Configure your server:
    • Server name: “Web Search MCP Server”
    • Resource identifier: Your server URL (e.g., https://your-mcp-server.com)
    • Allow dynamic client registration: Enable this
    • Access token lifetime: 300-3600 seconds
    • Scopes: web-search:read, web-search:write

Running the Server

python src/server.py

The server will start on http://localhost:10000 (or your configured port).

API Endpoints

OAuth Discovery Endpoints

  • GET /.well-known/oauth-protected-resource - Resource metadata for MCP client discovery
  • GET /.well-known/oauth-authorization-server - Authorization server metadata (proxied from Scalekit)

OAuth Endpoints

  • POST /oauth/register - Dynamic client registration (proxied to Scalekit)

MCP Endpoints

  • POST /web-search/mcp - Main MCP endpoint (requires authentication)

Authentication Flow

GitHub で README 全文を見る

インストール

This server does not publish a one-line install command.

Open the repository installation guide MCP 初心者?mcpskill.org のガイドから始めましょう →