Skip to main content
Glama
noqtar

Universal MCP OAuth Gateway

by noqtar
README.md
# Universal MCP OAuth Gateway (with Excalidraw & Proxy Support)

A deployable, serverless **Universal Model Context Protocol (MCP) OAuth Gateway & Proxy** built on Next.js 14. 

This project allows you to attach **OAuth 2.0 authentication** to **Excalidraw OR ANY external MCP server** so enterprise clients like **Google Spark** & **Gemini Agents** can connect seamlessly without OAuth rejection errors.

---

## How It Works

```text
[Google Spark Client] ──(OAuth 2.0 Auth + Discovery)──> [Universal MCP OAuth Gateway on Vercel]
                                                                  │
                                       ┌──────────────────────────┴──────────────────────────┐
                                       ▼                                                     ▼
                     [Built-in Tools: Excalidraw, SVG, Mindmaps]      [Proxy Mode: Any External Remote MCP Server]
```

---

## Features

- 🔐 **Universal OAuth 2.0 Auth Server**: Implements `/.well-known/oauth-authorization-server` and `/.well-known/openid-configuration` with RFC 7591 dynamic client registration.
- 🌐 **MCP Server & Proxy Gateway**:
  - **Mode 1 (Built-in)**: Excalidraw tools (`create_diagram`, `generate_flowchart`, `generate_mindmap`, `export_svg`, `view_diagram`) & web utilities.
  - **Mode 2 (Universal Proxy)**: Proxies JSON-RPC 2.0 requests to any unauthenticated remote MCP server specified via `UPSTREAM_MCP_URL` or `X-MCP-Target-URL`.
- 🖼️ **Interactive Web Viewer**: Embedded viewer at `/view/[id]` allowing users & AI agents to inspect, copy, and download rendered Excalidraw diagrams as SVG.
- ⚡ **100% Vercel Native**: Uses stateless JWT tokens—no database setup required.

---

## Google Spark Connection & Deployment Instructions

### Step 1: Deploy to Vercel

1. Push this repository to GitHub.
2. Import the project into [Vercel](https://vercel.com/new).
3. *(Optional for Proxy Mode)*: If you want to proxy another unauthenticated MCP server, add an Environment Variable in Vercel:
   ```text
   UPSTREAM_MCP_URL = https://your-other-mcp-server.com/api/mcp
   ```
4. Click **Deploy**. Vercel will assign a public domain, e.g.:
   `https://your-mcp-gateway.vercel.app`

### Step 2: Connect to Google Spark / Gemini

1. In Google Spark, select **Add Remote MCP Server**.
2. Enter your deployed MCP Endpoint URL:
   ```text
   https://your-mcp-gateway.vercel.app/api/mcp
   ```
3. Google Spark automatically discovers the OAuth endpoints at:
   ```text
   https://your-mcp-gateway.vercel.app/.well-known/oauth-authorization-server
   ```
4. Complete the one-click authorization prompt. Google Spark can now invoke tools from Excalidraw or your proxied MCP server!

---

## API Endpoints

| Endpoint | Description |
|---|---|
| `GET /.well-known/oauth-authorization-server` | OAuth 2.0 Server Discovery Metadata (RFC 8414) |
| `GET /.well-known/openid-configuration` | OpenID Connect Discovery Metadata |
| `POST /api/auth/register` | RFC 7591 Dynamic Client Registration |
| `GET /api/auth/authorize` | OAuth Authorization endpoint |
| `POST /api/auth/token` | OAuth Token Exchange endpoint |
| `POST /api/mcp` | MCP HTTP JSON-RPC 2.0 Tool Execution / Proxy Endpoint |
| `GET /api/mcp/sse` | MCP Server-Sent Events Transport |
| `GET /view/[id]` | Interactive Excalidraw Canvas Viewer |