|
| 1 | +# Simple MCP Server with GitHub OAuth Authentication |
| 2 | + |
| 3 | +This is a simple example of an MCP server with GitHub OAuth authentication. It demonstrates the essential components needed for OAuth integration with just a single tool. |
| 4 | + |
| 5 | +This is just an example of a server that uses auth, an official GitHub mcp server is [here](https://github.com/github/github-mcp-server) |
| 6 | + |
| 7 | +## Overview |
| 8 | + |
| 9 | +This simple demo to show to set up a server with: |
| 10 | +- GitHub OAuth2 authorization flow |
| 11 | +- Single tool: `get_user_profile` to retrieve GitHub user information |
| 12 | + |
| 13 | + |
| 14 | +## Prerequisites |
| 15 | + |
| 16 | +1. Create a GitHub OAuth App: |
| 17 | + - Go to GitHub Settings > Developer settings > OAuth Apps > New OAuth App |
| 18 | + - Application name: Any name (e.g., "Simple MCP Auth Demo") |
| 19 | + - Homepage URL: `http://localhost:8000` |
| 20 | + - Authorization callback URL: `http://localhost:8000/github/callback` |
| 21 | + - Click "Register application" |
| 22 | + - Note down your Client ID and Client Secret |
| 23 | + |
| 24 | +## Required Environment Variables |
| 25 | + |
| 26 | +You MUST set these environment variables before running the server: |
| 27 | + |
| 28 | +```bash |
| 29 | +export MCP_GITHUB_GITHUB_CLIENT_ID="your_client_id_here" |
| 30 | +export MCP_GITHUB_GITHUB_CLIENT_SECRET="your_client_secret_here" |
| 31 | +``` |
| 32 | + |
| 33 | +The server will not start without these environment variables properly set. |
| 34 | + |
| 35 | + |
| 36 | +## Running the Server |
| 37 | + |
| 38 | +```bash |
| 39 | +# Set environment variables first (see above) |
| 40 | + |
| 41 | +# Run the server |
| 42 | +uv run mcp-simple-auth |
| 43 | +``` |
| 44 | + |
| 45 | +The server will start on `http://localhost:8000`. |
| 46 | + |
| 47 | +## Available Tool |
| 48 | + |
| 49 | +### get_user_profile |
| 50 | + |
| 51 | +The only tool in this simple example. Returns the authenticated user's GitHub profile information. |
| 52 | + |
| 53 | +**Required scope**: `user` |
| 54 | + |
| 55 | +**Returns**: GitHub user profile data including username, email, bio, etc. |
| 56 | + |
| 57 | + |
| 58 | +## Troubleshooting |
| 59 | + |
| 60 | +If the server fails to start, check: |
| 61 | +1. Environment variables `MCP_GITHUB_GITHUB_CLIENT_ID` and `MCP_GITHUB_GITHUB_CLIENT_SECRET` are set |
| 62 | +2. The GitHub OAuth app callback URL matches `http://localhost:8000/github/callback` |
| 63 | +3. No other service is using port 8000 |
| 64 | + |
| 65 | +You can use [Inspector](https://github.com/modelcontextprotocol/inspector) to test Auth |
0 commit comments