ServiceNow MCP Server
Enables authenticated interaction with ServiceNow via its REST API using per-user OAuth 2.0 tokens. It provides tools for managing incidents, tasks, knowledge articles, and service catalog requests while maintaining user-specific permissions.
README
ServiceNow MCP Server
Secure, enterprise-ready MCP server for ServiceNow where every action runs as the authenticated user.
No shared service accounts. No ACL bypass. Full audit-trail fidelity.
⚡ Why This Exists
Instead of funneling every request through a shared service account, this server executes actions as the actual human user.
Because it uses per-user OAuth tokens, ServiceNow still enforces:
- each user’s ACLs and roles,
- their approval authority,
- and native user-level audit logging.
Result: safer automation, cleaner compliance, fewer permission hacks.
🔥 Core Capabilities
- Per-user OAuth 2.0 Authorization Code flow + refresh
- AES-256-GCM encrypted token storage in Redis
- Streamable HTTP MCP transport with per-session lifecycle
- Tool-level identity protections for sensitive operations
- Optional reconnect tokens for session persistence across server restarts
- Per-user rate limiting via Redis token bucket
- Input validation + normalized error responses
- CI-enforced build + test + coverage gate
🧠 Architecture
flowchart LR
Client[MCP Client] --> MCP[ServiceNow MCP Server\nExpress + MCP SDK]
MCP --> Redis[(Redis\nEncrypted tokens + sessions)]
MCP --> SN[(ServiceNow REST APIs)]
MCP --> OAuth[OAuth 2.0\nPer-user delegation]
SN --> ACL[ACL + Role Enforcement]
SN --> Audit[Native Audit Trail]
Key modules:
src/index.ts— startup/shutdown wiringsrc/server.ts— HTTP app + MCP routes/session lifecyclesrc/auth/*— OAuth callback, encryption, token store, token refresh, reconnect tokenssrc/tools/*— tool implementations by domainsrc/middleware/*— rate limiting, error normalizationsrc/servicenow/*— API client + query helpers
🚀 Quick Start
Prerequisites
- Node.js 22+
- Redis
- ServiceNow instance with OAuth app configured
Local Setup
npm install
cp .env.example .env
npm run generate-key
# paste generated key into TOKEN_ENCRYPTION_KEY in .env
npm run dev
Health check:
curl -s http://localhost:8080/health
Docker
docker compose up -d --build
One-shot Linux VM setup is available via setup.sh.
🛠 ServiceNow Setup
- Go to System OAuth > Application Registry
- Create OAuth API endpoint for external clients
- Set redirect URI (example):
https://<host>:8080/oauth/callback - Copy client ID/secret into
.env
Required Role
Users should have snc_platform_rest_api_access for REST API access. Record-level ACLs still apply.
🧰 Tools (18)
Incidents
search_incidentsget_incidentcreate_incidentupdate_incidentadd_work_note
Users and Groups
lookup_userlookup_groupget_my_profile
Knowledge
search_knowledgeget_article
Tasks and Approvals
get_my_tasksget_my_approvalsapprove_or_reject
Update Sets
change_update_setcreate_update_set
Service Catalog
search_catalog_itemsget_catalog_itemsubmit_catalog_request
🔒 Security Guarantees
Server-side protections include:
create_incident: caller identity is server-controlledupdate_incident: protected audit/system fields are strippedsubmit_catalog_request: requester identity is server-controlledapprove_or_reject: approval ownership is verified
Also enforced:
sys_idand enum validation- payload sanitization
- normalized error responses
🔄 Reconnect Tokens
After a server restart, in-memory MCP sessions are lost. Normally this requires re-doing the full OAuth flow. Reconnect tokens let clients skip re-auth by auto-mapping a new session to existing Redis-stored OAuth credentials.
How It Works
- Complete OAuth as normal
- Generate a reconnect token:
curl -X POST https://host:8080/oauth/reconnect-token \ -H "Content-Type: application/json" \ -d '{"user_sys_id": "..."}' - Update your MCP client URL to include the token:
{ "url": "https://host:8080/mcp?token=<hex>" } - On server restart, the client reconnects and is automatically authenticated
Token Management
- Tokens default to 100-day TTL (configurable via
RECONNECT_TOKEN_TTL), refreshed on each successful use - Revoke a specific token:
DELETE /oauth/reconnect-tokenwith{"user_sys_id": "...", "reconnect_token": "..."} - Revoke all tokens for a user:
DELETE /oauth/reconnect-tokenwith{"user_sys_id": "...", "revoke_all": true} - If a token is invalid or expired, the session silently falls through to normal (unauthenticated) behavior
⚙️ Configuration
| Variable | Required | Description |
|---|---|---|
SERVICENOW_INSTANCE_URL |
Yes | ServiceNow base URL |
SERVICENOW_CLIENT_ID |
Yes | OAuth client ID |
SERVICENOW_CLIENT_SECRET |
Yes | OAuth client secret |
OAUTH_REDIRECT_URI |
Yes | OAuth callback URL |
TOKEN_ENCRYPTION_KEY |
Yes | Base64 32-byte AES key |
REDIS_URL |
No | Redis URL (default redis://localhost:6379) |
MCP_PORT |
No | Server port (default 8080) |
RATE_LIMIT_PER_USER |
No | Requests/minute/user (default 60) |
RECONNECT_TOKEN_TTL |
No | Reconnect token TTL in seconds (default 8640000 / 100 days) |
✅ Testing and Quality
npm run build
npm test
npm run test:coverage
- Coverage thresholds are configured in
vitest.config.ts - CI runs build + tests + coverage gate on PRs and
main
🧯 Troubleshooting
1) OAuth callback fails (TOKEN_EXCHANGE_FAILED)
Symptoms
/oauth/callbackreturns 500- logs show token exchange failure or
invalid_grant
Checks
OAUTH_REDIRECT_URIexactly matches the ServiceNow OAuth app redirect URI- client ID and secret are correct
- system clock is sane
Fix
- correct redirect/client credentials and restart server
- re-run auth flow from
/oauth/authorize
2) Auth works, but API calls return 403
Symptoms
- tool calls fail with insufficient permissions
Checks
- user has
snc_platform_rest_api_access - user has the needed table/record ACL permissions
Fix
- grant missing role or ACL permissions in ServiceNow
3) Redis connectivity issues
Symptoms
/healthreturns unhealthy- startup logs show Redis connection errors
Checks
- Redis is running and reachable
REDIS_URLis correct
Fix
- start Redis
- correct
REDIS_URL, then restart app
4) CI fails on coverage threshold
Symptoms
- GitHub Actions fails during
npm run test:coverage
Checks
- inspect uncovered lines in coverage output
- ensure changed logic has matching tests
Fix
- add targeted tests
- re-run locally with
npm run test:coverage
5) Reconnect token not working after restart
Symptoms
- Client connects with
?token=...but session is unauthenticated
Checks
- Token may be expired (default 100-day TTL)
- User's OAuth credentials may have been revoked or expired in Redis
- Token may have been explicitly revoked
Fix
- Generate a new reconnect token via
POST /oauth/reconnect-token - Re-authenticate via
/oauth/authorizeif OAuth credentials are gone
6) Tool says AUTH_REQUIRED after prior login
Symptoms
- tool requests re-auth unexpectedly
Checks
- refresh token may be expired/revoked
- session mapping may be missing/expired
Fix
- re-authenticate via
/oauth/authorize - confirm Redis persistence and restart behavior
Debug Command Cheat Sheet
# install + run
npm install
npm run dev
# quality gates
npm run build
npm test
npm run test:coverage
# health check
curl -s http://localhost:8080/health
# local redis quick check (when redis-cli is available)
redis-cli -u "$REDIS_URL" ping
# docker compose stack quick status
docker compose ps
docker compose logs -f
🤖 Agent Instruction Files
AGENTS.mdCLAUDE.md.github/copilot-instructions.md
Alignment workflow validates expected consistency.
🌐 Endpoints
| Path | Method | Purpose |
|---|---|---|
/health |
GET | Health status |
/oauth/authorize |
GET | Start OAuth flow |
/oauth/callback |
GET | OAuth callback/token exchange |
/oauth/reconnect-token |
POST | Generate a reconnect token |
/oauth/reconnect-token |
DELETE | Revoke reconnect token(s) |
/mcp |
POST | MCP initialize + tool calls |
/mcp?token=<hex> |
POST | MCP initialize with reconnect token |
/mcp |
GET | MCP notifications stream |
/mcp |
DELETE | Close MCP session |
Client Config Example (Claude Desktop)
{
"mcpServers": {
"servicenow": {
"type": "streamablehttp",
"url": "https://your-host:8080/mcp"
}
}
}
With a reconnect token for session persistence across restarts:
{
"mcpServers": {
"servicenow": {
"type": "streamablehttp",
"url": "https://your-host:8080/mcp?token=<your-reconnect-token>"
}
}
}
Built for secure, user-scoped AI operations in ServiceNow.
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。