ServiceNow MCP Server

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.

Category
访问服务器

README

ServiceNow MCP Server

Node 22+ TypeScript MCP OAuth 2.0 CI

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 wiring
  • src/server.ts — HTTP app + MCP routes/session lifecycle
  • src/auth/* — OAuth callback, encryption, token store, token refresh, reconnect tokens
  • src/tools/* — tool implementations by domain
  • src/middleware/* — rate limiting, error normalization
  • src/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

  1. Go to System OAuth > Application Registry
  2. Create OAuth API endpoint for external clients
  3. Set redirect URI (example): https://<host>:8080/oauth/callback
  4. 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_incidents
  • get_incident
  • create_incident
  • update_incident
  • add_work_note

Users and Groups

  • lookup_user
  • lookup_group
  • get_my_profile

Knowledge

  • search_knowledge
  • get_article

Tasks and Approvals

  • get_my_tasks
  • get_my_approvals
  • approve_or_reject

Update Sets

  • change_update_set
  • create_update_set

Service Catalog

  • search_catalog_items
  • get_catalog_item
  • submit_catalog_request

🔒 Security Guarantees

Server-side protections include:

  • create_incident: caller identity is server-controlled
  • update_incident: protected audit/system fields are stripped
  • submit_catalog_request: requester identity is server-controlled
  • approve_or_reject: approval ownership is verified

Also enforced:

  • sys_id and 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

  1. Complete OAuth as normal
  2. Generate a reconnect token:
    curl -X POST https://host:8080/oauth/reconnect-token \
      -H "Content-Type: application/json" \
      -d '{"user_sys_id": "..."}'
    
  3. Update your MCP client URL to include the token:
    { "url": "https://host:8080/mcp?token=<hex>" }
    
  4. 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-token with {"user_sys_id": "...", "reconnect_token": "..."}
  • Revoke all tokens for a user: DELETE /oauth/reconnect-token with {"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/callback returns 500
  • logs show token exchange failure or invalid_grant

Checks

  • OAUTH_REDIRECT_URI exactly 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

  • /health returns unhealthy
  • startup logs show Redis connection errors

Checks

  • Redis is running and reachable
  • REDIS_URL is 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/authorize if 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.md
  • CLAUDE.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

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选