cloudnautique
MCP Servercloudnautiquepublic

fastapi mcp test

一个基于 FastAPI 的轻量级 OAuth2 代理服务器,支持 GitHub 登录和 JWT 授权。

Repository Info

0
Stars
0
Forks
0
Watchers
0
Issues
Python
Language
-
License

About This Server

一个基于 FastAPI 的轻量级 OAuth2 代理服务器,支持 GitHub 登录和 JWT 授权。

Model Context Protocol (MCP) - This server can be integrated with AI applications to provide additional context and capabilities, enabling enhanced AI interactions and functionality.

Documentation

🚀 FastAPI GitHub OAuth2 Proxy for MCP

This project is a lightweight OAuth2 proxy server built with FastAPI that authenticates users via GitHub, issues JWTs, and provides an MCP-compatible interface for tool usage and secure messaging.

It supports:

  • GitHub OAuth2 login
  • MCP-compatible authorization metadata
  • JWT issuance for downstream API access
  • Protected API routes using Bearer tokens
  • GitHub repository listing per authenticated user

📦 Features

  • 🔐 GitHub OAuth2 login with PKCE + client secret support
  • ✅ Dynamic client registration endpoint (/oauth/register)
  • ⚒ OAuth server metadata at /.well-known/oauth-authorization-server
  • 🗒 JWT issuance using python-jose (or compatible) for user identification
  • 🔒 Protected API routes (/api/protected, /api/repos)
  • 🌐 MCP-compatible authorization flow via fastapi_mcp

🧰 Requirements

  • Python 3.9+
  • GitHub OAuth App (Client ID + Secret)
  • .env file configured (see below)

Install dependencies:

pip install -r requirements.txt

📂 .env Configuration

create an Oauth App on GitHub and provide the following in the .env file.

GITHUB_CLIENT_ID=your_github_client_id
GITHUB_CLIENT_SECRET=your_github_client_secret

⚒ Usage

python main.py

Use the MCP inspector connect to the server.

npx @modelcontextprotocol/inspector
http://localhost:8000/mcp

This will initiate the full GitHub OAuth2 login flow through MCP Inspector.


🔐 OAuth2 Endpoints

EndpointPurpose
/authorizeRedirects to GitHub for login
/callbackHandles GitHub OAuth2 redirect + token
/oauth/registerFake dynamic client registration
/.well-known/oauth-authorization-serverOAuth2 metadata (for MCP Inspector)

🥪 API Routes

MethodPathAuth RequiredDescription
GET/api/public❌ NoPublic test route
GET/api/protected✅ YesProtected route showing user info
GET/api/repos✅ YesList GitHub repos for logged-in user

Use the JWT returned by /callback like this:

Authorization: Bearer <your_token>

🧠 Developer Notes

  • Tokens and user data are stored in-memory (tokens_db).
  • Replace in-memory storage with a DB (e.g. Redis/Postgres) for production use.
  • Supports full CORS for localhost development tools like MCP Inspector.

🛄 MCP Integration

This server is compatible with the Model Context Protocol (MCP) and can be used as a remote authorization server. Clients can connect via:

{
  "authorization_endpoint": "/authorize",
  "token_endpoint": "/callback",
  "registration_endpoint": "/oauth/register"
}

Test it using the MCP Inspector and point it to your local server:

http://localhost:8000/mcp

📚 TODO / Enhancements

  • 🔄 Support for refresh tokens
  • 🔐 Encrypted GitHub token storage
  • 📁 Per-user repo caching
  • 🔐 Allow access only for pre-approved GitHub usernames

Quick Start

1

Clone the repository

git clone https://github.com/cloudnautique/fastapi-mcp-test
2

Install dependencies

cd fastapi-mcp-test
npm install
3

Follow the documentation

Check the repository's README.md file for specific installation and usage instructions.

Repository Details

Ownercloudnautique
Repofastapi-mcp-test
LanguagePython
License-
Last fetched8/10/2025

Recommended MCP Servers

💬

Discord MCP

Enable AI assistants to seamlessly interact with Discord servers, channels, and messages.

integrationsdiscordchat
🔗

Knit MCP

Connect AI agents to 200+ SaaS applications and automate workflows.

integrationsautomationsaas
🕷️

Apify MCP Server

Deploy and interact with Apify actors for web scraping and data extraction.

apifycrawlerdata
🌐

BrowserStack MCP

BrowserStack MCP Server for automated testing across multiple browsers.

testingqabrowsers

Zapier MCP

A Zapier server that provides automation capabilities for various apps.

zapierautomation