MCP OAuth Server

MCP OAuth Server

A Node.js MCP server with custom OAuth 2.1 + PKCE authentication, enabling secure remote connections to LLMs like Claude and ChatGPT.

Category
访问服务器

README

MCP Server real (SDK oficial) + OAuth 2.1 propio — Node.js

Servidor MCP funcional usando @modelcontextprotocol/sdk, protegido con OAuth 2.1 + PKCE implementado desde cero (sin Auth0/Okta/terceros).

Instalar y correr

npm install
node server.js

Corre en http://localhost:3000 por defecto. El endpoint MCP está en /mcp.

Probar sin conectar a un LLM todavía

node test-mcp-client.js

Esto usa el Client oficial del SDK de MCP: hace OAuth completo, se conecta, lista tools y las ejecuta. Si esto corre OK, tu servidor está listo para conectarse a un LLM real.

Conectar esto a Claude (Claude.ai / Claude Desktop)

Opción A: probar localmente con un túnel (recomendado para pruebas rápidas)

Claude.ai necesita una URL pública con HTTPS para conectores remotos. Para probar sin desplegar nada, usa un túnel:

# instala ngrok (https://ngrok.com) o usa cloudflared
ngrok http 3000

Esto te da una URL tipo https://abc123.ngrok-free.app. IMPORTANTE: actualiza las variables de entorno antes de arrancar el server para que el OAuth use esa URL pública en vez de localhost:

PUBLIC_BASE_URL=https://abc123.ngrok-free.app node server.js

(en Windows PowerShell: $env:PUBLIC_BASE_URL="https://abc123.ngrok-free.app"; node server.js)

Luego en Claude.ai:

  1. Ajustes → Connectors (o "Conectores") → Add custom connector
  2. Pega la URL: https://abc123.ngrok-free.app/mcp
  3. Claude detecta automáticamente que requiere OAuth (vía el 401 + WWW-Authenticate que devuelve tu servidor), te redirige a tu pantalla de login (/authorize), apruebas, y Claude queda conectado.
  4. Ahora puedes pedirle a Claude que use las tools whoami o sumar.

Opción B: desplegar en un hosting real

Cualquier servicio que soporte Node.js sirve (Render, Railway, Fly.io, un VPS con nginx + certbot, etc). Solo necesitas:

  • HTTPS válido (obligatorio, OAuth 2.1 no permite HTTP excepto en localhost)
  • Variable PUBLIC_BASE_URL apuntando a tu dominio real
  • Variable JWT_SECRET definida explícitamente (no uses la generada al azar)

Conectar a ChatGPT

ChatGPT soporta MCP remoto vía "Connectors" (en configuración de la cuenta, o dentro de un GPT personalizado, según el plan). El proceso de descubrimiento OAuth es el mismo: ChatGPT también lee /.well-known/oauth-protected-resource automáticamente al recibir el 401 inicial. Pega la misma URL https://tu-dominio/mcp.

Estructura

  • server.js — MCP server con el SDK oficial + rutas OAuth montadas
  • test-mcp-client.js — cliente de prueba con el SDK (sin necesidad de un LLM)
  • oauth/ — Authorization Server + Resource Server (igual que en el ejemplo anterior)

Notas sobre las tools de ejemplo

  • whoami — devuelve la identidad inyectada por el OAuth (userId, clientId, scope). Útil para confirmar que la autenticación está llegando correctamente a tus tools.
  • sumar — tool trivial con input, para ver el patrón estándar de definición de herramientas con Zod.

Reemplaza estas dos por las tools reales que necesites. El patrón con server.registerTool(nombre, { title, description, inputSchema }, handler) es el que debes seguir para cualquier tool nueva.

Antes de producción (recordatorio, igual que el ejemplo anterior)

  1. Reemplaza el almacenamiento en memoria (oauth/store.js) por una DB real.
  2. Define JWT_SECRET explícitamente.
  3. HTTPS obligatorio.
  4. Reemplaza el login demo en /authorize por tu sistema real de usuarios.
  5. Agrega rate limiting a /token y /authorize.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选