Sample authenticated MCP server built with FastAPI and FastMCP

Sample authenticated MCP server built with FastAPI and FastMCP

mcp-authentication-samples•byflowsoft-org

A sample MCP server that uses OAuth2 Bearer tokens from Microsoft Entra ID (Azure AD) to protect its endpoint, runnable locally with FastAPI and FastMCP.

License: Not specified•Runtime: Awaiting documentation review•Category: auth security

WHAT IT DOES

  • •Protects the MCP server with OAuth2 Bearer tokens issued by Microsoft Entra ID.
  • •Configures a BearerAuthProvider with JWKS URI, issuer, audience and required scopes for token validation.
  • •Ships an oauth-protected-resource.json describing the resource, scopes and issuer for the protected endpoint.
  • •Rejects requests lacking a valid token with a 401 Unauthorized response.

BEST FOR

  • •Developers learning how to add Entra ID OAuth2 authentication to an MCP server.
  • •Teams wanting a runnable FastAPI and FastMCP server as a starting point for secure tool endpoints.
  • •Users connecting an authenticated MCP server to GitHub Copilot Agent mode in VS Code.

ABOUT MCP-AUTHENTICATION-SAMPLES

Sample authenticated MCP server built with FastAPI and FastMCP is cataloged as an MCP server attributed to flowsoft-org. A sample MCP server that uses OAuth2 Bearer tokens from Microsoft Entra ID (Azure AD) to protect its endpoint, runnable locally with FastAPI and FastMCP. It is categorized under auth security. See the capability inspector for recorded interfaces and their independent review status; consult upstream documentation for the current interface.

HOW TO INSTALL

Installation configuration is not reviewed. No executable setup is offered for this entry; inspect the source repository before proceeding.

LICENSE

Catalog license label: Not specified. Check the source repository's current license and terms before using, modifying or distributing this software.

能力检查器

能力定义尚未审核。未核验的采集内容不会作为可信接口展示。

Tools (0)

暂无可展示的已审核记录。这不表示上游不支持此能力。

Resources (0)

暂无可展示的已审核记录。这不表示上游不支持此能力。

Prompts (0)

暂无可展示的已审核记录。这不表示上游不支持此能力。

NEWSLETTER - COMING LATER

Newsletter subscriptions are not open yet

Email delivery is not connected. This page does not collect email addresses or create subscriptions.

Browse the registry for current listings instead.

Community Reviews

Coming later

Reviews for Sample authenticated MCP server built with FastAPI and FastMCP are not available yet

Review publishing and storage are not connected. This page does not collect or publish ratings or comments, including after sign-in.

FREQUENTLY ASKED QUESTIONS

How does the sample authenticate requests to the MCP server?

It uses OAuth2 Bearer tokens from Microsoft Entra ID (Azure AD) to protect the MCP server.

What happens if a request is made without a valid token?

Requests with no or an invalid token receive a 401 Unauthorized response.

上游原版 README

在 GitHub 查看同一版本原文

README.md · 62ca4e56fa73 · 采集于 2026-11-13 13:54:19 UTC

保留上游原文,不做 AI 改写。为安全起见过滤脚本、表单和不安全链接。

当前显示最后一次成功采集的文档快照,请以来源页面为准。

MCP Authentication Samples 🚀

This repository contains sample code for building Model Context Protocol (MCP) servers with authentication using FastAPI and FastMCP.

Running the Server 🖥️

  1. Open this folder in VS Code
  2. (If using devcontainer) Click "Reopen in Container" if prompted
  3. Install dependencies:
    pip install -r requirements.txt
    
  4. Start the server:
    python server.py
    

The server will start on http://localhost:8000

Authentication with Microsoft Entra ID (Azure AD) 🔐

This sample demonstrates how to protect your MCP server using OAuth2 Bearer tokens from Microsoft Entra ID (Azure AD).

Required Entra ID Application Setup 🛠️

  1. Register an Application in Microsoft Entra ID (Azure AD) via the Azure Portal.
  2. Expose an API:
    • Go to "Expose an API" in your app registration.
    • Set the Application ID URI (e.g., api://<APPUUID>).
    • Add a scope (e.g., mcp.tools).
  3. Configure Authentication:
    • Add a redirect URI if needed for your client.
  4. Get the following values for your app:
    • Tenant ID
    • Application (client) ID
    • Application ID URI
    • Scope name

Update Your Code and Resource Metadata ✏️

  • Update BearerAuthProvider in server.py:

    • Replace <ENTRATENANTID> with your Entra tenant ID.
    • Replace <APPUUID> with your Application (client) ID or Application ID URI.
    • Set the correct jwks_uri, issuer, audience, and required_scopes.

    Example:

    auth = BearerAuthProvider(
        jwks_uri="https://login.microsoftonline.com/<ENTRATENANTID>/discovery/v2.0/keys",
        issuer="https://sts.windows.net/<ENTRATENANTID>/",
        algorithm="RS256",
        audience="api://<APPUUID>",
        required_scopes=["mcp.tools"]
    )
    
  • Update oauth-protected-resource.json:

    • Ensure this file matches your application's metadata, including resource ID, scopes, and issuer.

Example: oauth-protected-resource.json 📄

{
  "resource": "api://<APPUUID>",
  "issuer": "https://sts.windows.net/<ENTRATENANTID>/",
  "scopes": ["mcp.tools"]
}

Replace placeholders with your actual values.

GitHub Copilot Agent Mode 🤖

This MCP server can also be used in GitHub Copilot Agent mode in VS Code. To enable this:

  1. Ensure the server is running.
  2. Use the mcp.json file to configure the MCP server for GitHub Copilot.
  3. Start the server from the mcp.json configuration.

Testing 🧪

You can test the protected endpoint using curl:

curl -H "Authorization: Bearer <token>" http://localhost:8000/mcp

If no or an invalid token is provided, you will receive a 401 Unauthorized response.

License 📜

See LICENSE.

Install configuration

Are you the maintainer?

Claim this server with your GitHub account to request manual ownership verification.

README Embed Badge
Markdown

Link to the catalog listing for Sample authenticated MCP server built with FastAPI and FastMCP from your README. This badge does not certify ownership, compatibility or security.

[![MCP catalog listing](https://img.shields.io/badge/MCP-awesome--mcp-orange?style=flat-square)](https://awesome-mcp.com/servers/mcp-authentication-samples)

REPOSITORY STATS

GitHub StarsUnavailable
ForksUnavailable

Public repository statistics could not be verified. Check the configured source address; unavailable counts are not zero.

下载与拉取统计

来源、范围和时段分别列出;不相加,不代表安装人数、活跃用户或安全审核。

尚无已审核的包 / 镜像标识,暂不展示下载统计。

Related auth security MCP Servers

Alternative and complementary servers in the same category

View all in auth security →

A modular FastMCP server for interacting with Microsoft Graph API, supporting advanced queries for users, sign-in logs, MFA status, and privileged users.

Repository stats unavailable
Security & Secrets
Keycloak MCP Server
keycloak-mcp-server•sshaaf

A Model Context Protocol (MCP) server that provides programmatic access to Keycloak administration functionality.

Repository stats unavailable
Security & Secrets

An MCP server for LLM-driven penetration testing that wraps Kali tools and adds scope enforcement, engagement tracking, and structured output.

Repository stats unavailable
Security & Secrets