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.

Capability inspector

Capability definitions are not reviewed. Unreviewed imports are not exposed as trusted interfaces.

Tools (0)

No reviewed records to display. This does not establish that upstream lacks this capability.

Resources (0)

No reviewed records to display. This does not establish that upstream lacks this capability.

Prompts (0)

No reviewed records to display. This does not establish that upstream lacks this capability.

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.

Upstream README

View this exact version on GitHub

README.md · 62ca4e56fa73 · Fetched 2026-11-13 13:54:19 UTC

Original upstream text, without AI rewriting. Scripts, forms and unsafe links are filtered for safety.

Showing the last retrieved documentation snapshot; check the source for current changes.

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.

Downloads and pulls

Separate sources, scopes and periods. Never combined or treated as installations, active users or security reviews.

No reviewed package or image identity; download statistics are not listed yet.

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