MCPController
Enables an admin to grant ChatGPT scoped access to manage doctor records via MongoDB, with OAuth 2.1 PKCE consent and per-tool permission checks.
README
MCPController
MCPController is a single-admin doctor-management MCP application. ChatGPT connects through OAuth 2.1 with PKCE, the Admin logs in, chooses which doctor permissions to grant, and the MCP server exposes doctor tools backed by MongoDB.
Architecture
ChatGPT
↓
OAuth
↓
Admin Login
↓
Admin Consent
↓
Granted Permissions
↓
MCP Access Token
↓
MCP /mcp
↓
Permission Check
↓
Doctor Tools
↓
MongoDB
What This App Does
- One Admin owns the whole system.
- There is no public registration and no multi-user account switching.
- The Admin authenticates with credentials from environment variables.
- The consent screen lets the Admin approve
doctor:read,doctor:write, anddoctor:delete. - The MCP server checks the approved scopes again on every tool call.
- Doctor data is stored in MongoDB through a simple Mongoose model.
Authentication
The browser session is separate from the MCP bearer token.
- Browser session: HTTP-only cookie used for the Admin UI and consent screen.
- MCP access token: Bearer token used by ChatGPT against
/mcp. - OAuth uses authorization code flow with PKCE.
- Authorization codes are single-use and short-lived.
- Access tokens and refresh tokens are hashed before storage.
The Admin login uses ADMIN_EMAIL and ADMIN_PASSWORD from .env.
Doctor Management
The domain model is intentionally small:
name- required stringspecialization- required stringcreatedAt/updatedAt- managed by Mongoose timestamps
Doctor CRUD is implemented in a service layer and reused by both the REST admin API and the MCP tool layer.
OAuth Flow
- ChatGPT opens the authorization endpoint.
- If the Admin is not authenticated, the browser goes to
/login. - The Admin logs in.
- The consent page shows the requested doctor permissions.
- The Admin approves a subset or denies the request.
- The authorization code is exchanged for an access token.
- ChatGPT uses that token on
/mcp.
Permission Flow
Requested scopes map to MCP tools like this:
doctor:read→list_doctors,get_doctordoctor:write→add_doctor,update_doctordoctor:delete→delete_doctor
The backend enforces permissions twice:
- OAuth only writes approved scopes into the authorization code and token.
- Each MCP tool checks the token scopes before it touches MongoDB.
MCP Tools
| Tool | Scope | Behavior |
|---|---|---|
list_doctors |
doctor:read |
Returns all doctors |
get_doctor |
doctor:read |
Returns one doctor by doctorId |
add_doctor |
doctor:write |
Creates a doctor with name and specialization |
update_doctor |
doctor:write |
Updates a doctor by doctorId |
delete_doctor |
doctor:delete |
Deletes a doctor by doctorId |
Environment Variables
Use a root .env file. The application loads it from the project root.
Required values for local npm run dev (Vite on 5173, API on 3000):
NODE_ENV=development
PORT=3000
APP_URL=http://localhost:5173
API_URL=http://localhost:3000
MONGODB_URI=mongodb://127.0.0.1:27017/mcpcontroller
ADMIN_EMAIL=admin@example.com
ADMIN_PASSWORD=change-this-password
JWT_SECRET=change-this-to-a-long-random-secret
MCP_SERVER_NAME=MCPController
MCP_SERVER_VERSION=1.0.0
The code also supports token/session lifetime variables with safe defaults:
JWT_EXPIRES_INAUTH_CODE_TTL_SECONDSACCESS_TOKEN_TTL_SECONDSREFRESH_TOKEN_TTL_SECONDS
On Vercel, APP_URL and API_URL must both be the public HTTPS origin (see Deployment below).
Local Setup
- Install dependencies:
npm install
-
Start MongoDB locally.
-
Seed sample data:
npm run seed
- Start the app:
npm run dev
In development, the React client runs through Vite and proxies API requests to the backend.
Testing
Run the automated checks with:
npm test
Run the client build with:
npm run build
The current test suite covers:
- admin login
- registration disabled
- doctor model and CRUD service
- OAuth scope approval
- MCP tool permission enforcement
- token revocation
Connecting ChatGPT
Use the authorization URL exposed by the server:
/.well-known/oauth-authorization-server/.well-known/oauth-protected-resource/oauth/token/mcp
Typical flow:
- ChatGPT discovers the OAuth metadata.
- ChatGPT requests authorization for the MCP resource.
- The browser redirects to the Admin login screen.
- The Admin reviews permissions and clicks
Allow & Connect. - ChatGPT exchanges the code for tokens.
- ChatGPT calls the MCP tools using the bearer token.
Deployment
The app is a single origin: Express serves /api, /oauth, /mcp, OAuth discovery, and the React build.
Vercel
This repo already includes vercel.json and api/index.js. Vercel runs the Express app as one serverless function and rewrites every path to it.
1. MongoDB Atlas
- Create a cluster (free M0 is enough).
- Create a database user.
- Network Access: allow
0.0.0.0/0so Vercel can connect (or add Vercel IPs if you prefer). - Copy the connection string, for example:
mongodb+srv://USER:PASSWORD@cluster0.xxxxx.mongodb.net/mcpcontroller?retryWrites=true&w=majority
2. Deploy the project
- Push this repo to GitHub.
- In Vercel, Import the repository.
- Framework Preset: Other (leave it).
vercel.jsonsets install and build. - Root Directory: leave as the repo root (do not set it to
clientorserver). - Node.js version: 20.x or newer.
3. Environment variables in Vercel
Project → Settings → Environment Variables. Set them for Production (and Preview if you use preview URLs).
| Name | Example | Notes |
|---|---|---|
NODE_ENV |
production |
Vercel usually sets this automatically. |
APP_URL |
https://your-app.vercel.app |
No trailing slash. Must match the live origin. |
API_URL |
https://your-app.vercel.app |
Same value as APP_URL on Vercel. |
MONGODB_URI |
mongodb+srv://…/mcpcontroller |
Atlas URI. |
ADMIN_EMAIL |
your admin email | Used to log in to the consent UI. |
ADMIN_PASSWORD |
a strong password | Compared on login; never sent to the browser. |
JWT_SECRET |
long random string | Session cookie signing. Do not use the example values. |
JWT_EXPIRES_IN |
7d |
Optional. |
AUTH_CODE_TTL_SECONDS |
120 |
Optional. |
ACCESS_TOKEN_TTL_SECONDS |
3600 |
Optional. |
REFRESH_TOKEN_TTL_SECONDS |
2592000 |
Optional. |
MCP_SERVER_NAME |
MCPController |
Optional. |
MCP_SERVER_VERSION |
1.0.0 |
Optional. |
Do not put ADMIN_PASSWORD or JWT_SECRET in the React app. The client only talks to /api.
If you add a custom domain later, change APP_URL and API_URL to https://your-domain.com and redeploy.
Generate JWT_SECRET with:
node -e "console.log(require('crypto').randomBytes(48).toString('hex'))"
4. First deploy and seed
- Deploy.
- Open
https://your-app.vercel.app/api/health— you should see{ "ok": true, ... }. - Seed MongoDB from your machine, pointed at Atlas (not Vercel’s serverless function):
# In the project root, temporarily set MONGODB_URI to the Atlas URI in .env
npm run seed
Seed creates the Admin user row, sample doctors, and a local MCP Inspector client. After that, log in on the live site with ADMIN_EMAIL / ADMIN_PASSWORD.
5. Connect ChatGPT
Use the deployed origin:
https://your-app.vercel.app/.well-known/oauth-authorization-serverhttps://your-app.vercel.app/.well-known/oauth-protected-resourcehttps://your-app.vercel.app/mcp
In ChatGPT (or MCP Inspector), add that MCP URL. ChatGPT will open the login + consent screens on the same domain, then call /mcp with a Bearer token.
CLI deploy (optional)
npm i -g vercel
vercel login
vercel env pull # optional: sync env locally
vercel --prod
After the first production deploy, copy the URL into APP_URL and API_URL if you used a placeholder, then redeploy so OAuth metadata points at the real origin.
Security Notes
- Do not expose
ADMIN_PASSWORDorJWT_SECRETto the browser. - Keep OAuth tokens hashed in the database.
- Only approve the scopes the Admin actually wants ChatGPT to use.
- Revoke access when the connection should no longer be trusted.
- The admin login exists only to authorize ChatGPT and manage doctor data; there is no public signup flow.
Seed Data
The seed script creates:
- sample doctors
- a sample OAuth client for local inspector use
It does not create demo users or hardcode Admin credentials.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。