Skip to main content
Glama
matheuscalma

servicenow-mcp

by matheuscalma

servicenow-mcp

Небольшой MCP сервер, который позволяет ИИ-агентам создавать, искать и обновлять инциденты ServiceNow через Table API. Построен с использованием официального Python пакета mcp (декораторы в стиле FastMCP), httpx и python-dotenv. Работает через stdio.

Всё находится в одном файле: server.py.

Настройка

Требуется Python 3.12+ и uv.

uv sync

Создайте .env рядом с server.py (он игнорируется git) с учётными данными для базовой аутентификации для вашего экземпляра — подойдёт Personal Developer Instance:

SNOW_INSTANCE_URL=https://devXXXXXX.service-now.com
SNOW_USERNAME=admin
SNOW_PASSWORD=your-password
# optional, default 15
SNOW_TIMEOUT_SECONDS=15

Запустите сервер (он общается по MCP через stdin/stdout, поэтому ничего не видно — MCP клиент должен его запускать):

uv run server.py

Регистрация в MCP клиенте

Укажите клиенту на uv с директорией проекта, чтобы .venv и .env были найдены:

{
  "mcpServers": {
    "servicenow": {
      "command": "uv",
      "args": ["--directory", "/absolute/path/to/servicenow-mcp", "run", "server.py"]
    }
  }
}

Для Claude Code: claude mcp add servicenow -- uv --directory /absolute/path/to/servicenow-mcp run server.py.

Переменные окружения, уже установленные в окружении клиента, имеют приоритет над .env.

Related MCP server: sn-mcp-bridge

Инструменты

Инструмент

Параметры

Что делает

Возвращает

create_incident

short_description: str (обязательно) · description: str = "" · urgency: str = "3" ("1" Высокий, "2" Средний, "3" Низкий)

Создаёт новый инцидент.

{number, sys_id, short_description, state, urgency}

query_incidents

query_text: str = "" · state: str = "" · limit: int = 5 (1–100)

Выводит инциденты, начиная с самых новых. Если query_text похож на INC0010001, ищет точное совпадение по номеру; иначе выполняет поиск по ключевым словам ServiceNow (123TEXTQUERY321), с запасным вариантом поиска LIKE по short_description/description, чтобы находить только что созданные записи. state принимает код ("1"…"8") или название (New, In Progress, On Hold, Resolved, Closed, Canceled).

[{number, sys_id, short_description, state, state_code, urgency, created_on}, …]

update_incident

number: str (обязательно) · work_notes: str = "" · state: str = ""

Ищет инцидент по номеру, добавляет рабочую заметку и/или устанавливает состояние. Требуется хотя бы одно из полей work_notes/state.

{number, sys_id, changed: {…}, state}

Все инструменты возвращают читаемую ошибку инструмента (отображается агенту как isError) вместо трассировки стека, например:

  • Authentication failed (401): check SNOW_USERNAME and SNOW_PASSWORD. ServiceNow said: User is not authenticated …

  • Could not connect to https://…: [Errno 8] nodename nor servname provided … Check SNOW_INSTANCE_URL and your network connection.

  • Timed out after 15s talking to https://… The instance may be hibernating (PDI) or unreachable.

  • Incident 'INC9999999' was not found on https://….

  • Forbidden (403): the user lacks permission … or the update was rejected by a business rule. ServiceNow said: … (например, при разрешении инцидента без полей разрешения).

Заметки по дизайну

  • ServiceNowClient оборачивает один httpx.AsyncClient (базовая аутентификация, JSON заголовки, таймаут) и предоставляет create_record / query_records / get_record_by_number / update_record. Все ошибки преобразуются в ServiceNowError с понятным сообщением.

  • Инструменты получают клиента через get_client(); вызовите set_client(fake) в тестах, чтобы подменить на мок без обращения к сети.

  • Записи запрашиваются с sysparm_display_value=all, поэтому метки состояния/срочности берутся из самого экземпляра, а не из жёстко заданной карты (псевдонимы с понятными именами используются только для ввода).

  • mcp 2.x переименовал FastMCP в MCPServer; server.py импортирует то, что существует, поэтому работает как на 1.x, так и на 2.x.

Дымовой тест

Запустите на работающем экземпляре (создаст один инцидент):

uv run python -c "
import asyncio, server
async def main():
    c = await server.create_incident('MCP server smoke test', 'created by smoke test')
    print(c)
    print(await server.query_incidents(query_text='MCP server smoke test'))
    print(await server.update_incident(c['number'], work_notes='hello from MCP'))
asyncio.run(main())
"

Available Tools

3 tools
create_incidentA

Create a new ServiceNow incident and return its number and sys_id.

Use this when a user reports a problem that should be tracked as a ticket.

Args:
    short_description: One-line summary of the issue (required, shown in lists).
    description: Longer free-text details, steps to reproduce, impact, etc.
    urgency: "1" (High), "2" (Medium) or "3" (Low). Defaults to "3".

Returns:
    {"number": "INC0010001", "sys_id": "...", "short_description": ..., "state": ..., "urgency": ...}
    The `number` is what humans reference; `sys_id` is the stable record id.
ParametersJSON Schema
NameRequiredDescriptionDefault
urgencyNo3
descriptionNo
short_descriptionYes

Output Schema

ParametersJSON Schema
NameRequiredDescription

No output parameters

TDQS

A4.7/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations provided, so description carries full burden. It discloses that the tool creates a record and returns specific fields. It could add potential side effects or permissions needed, but is adequate.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Well-structured, front-loaded with clear purpose and usage. Each sentence adds value, no fluff. Parameters and return value explained efficiently.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Tool has 3 parameters and output schema exists. Description covers parameter semantics, return format, and usage context. No gaps given complexity.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 0%, so description must compensate. It does so by explaining each parameter's purpose and format (e.g., urgency values, description use). Adds meaning beyond schema (e.g., 'shown in lists'). Could note default for short_description.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool creates a ServiceNow incident and returns its number and sys_id. It distinguishes itself from siblings by specifying creation, not querying or updating.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Explicitly states when to use this tool: 'when a user reports a problem that should be tracked as a ticket.' No exclusion of siblings but clear context for usage, and siblings are named for differentiation.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

query_incidentsA

List ServiceNow incidents, newest first, optionally filtered by text and/or state.

Use this to find existing tickets before creating a new one, to check on a
ticket by number, or to answer "what incidents are open about X?".

Args:
    query_text: What to search for. An incident number ("INC0010001") matches
        exactly; anything else runs ServiceNow's keyword search over the
        incident's text fields, falling back to a substring match on
        short_description/description. Leave empty to list the most recent incidents.
    state: Filter by state. Accepts a numeric code ("1".."8") or a name such as
        "New", "In Progress", "On Hold", "Resolved", "Closed", "Canceled".
        Leave empty for any state.
    limit: Maximum number of incidents to return (1-100). Defaults to 5.

Returns:
    A list of {"number", "sys_id", "short_description", "state", "state_code",
    "urgency", "created_on"}; an empty list means nothing matched.
ParametersJSON Schema
NameRequiredDescriptionDefault
limitNo
stateNo
query_textNo

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

A4.8/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description fully discloses behavioral details: search semantics (exact number matching vs. keyword search with substring fallback), state filter format (numeric or name), limit behavior with default, and return format. It also explains the meaning of an empty list. This is comprehensive and goes beyond a simple 'lists incidents.'

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is organized into clear sections: a one-line summary, usage guidance, parameter details, and return format. Every sentence serves a purpose, from explaining search fallback to specifying defaults. It is appropriately sized given the behavioral complexity.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

The description is complete for a read-only query tool: it defines input semantics, output structure, and edge cases (empty list, empty query). The presence of an output schema is complemented by a human-readable description of the return fields. Given the sibling tools, it clearly fits into the workflow as the search/read operation. No gaps are apparent.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must fully explain parameters. The 'Args' section does exactly that: query_text, state, and limit are each described with accepted formats, defaults, and special behavior (e.g., prefix matching for incident numbers, state code ranges). This adds significant meaning beyond the raw schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states 'List ServiceNow incidents, newest first, optionally filtered by text and/or state.' This uses a specific verb, names the resource (ServiceNow incidents), and distinguishes it from sibling tools like create_incident and update_incident by focusing on listing/querying.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description explicitly provides use cases: 'Use this to find existing tickets before creating a new one, to check on a ticket by number, or to answer "what incidents are open about X?".' This gives clear when-to-use guidance. It implies when-not-to-use (e.g., before creating) but does not explicitly name alternatives or exclude other tools, so it stops short of a 5.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

update_incidentA

Update an existing incident by number: append a work note and/or change its state.

Use this to record progress on a ticket or move it through its lifecycle.
At least one of `work_notes` or `state` must be provided.

Args:
    number: The incident number, e.g. "INC0010001".
    work_notes: Text to append to the (internal) work notes journal.
    state: New state as a numeric code ("1".."8") or a name such as "In Progress",
        "On Hold", "Resolved", "Closed". Note: resolving/closing on most instances
        also requires resolution fields and will be rejected by ServiceNow if missing.

Returns:
    {"number", "sys_id", "changed": {field: new value, ...}, "state": <current state>}
    describing exactly what was applied.
ParametersJSON Schema
NameRequiredDescriptionDefault
stateNo
numberYes
work_notesNo

Output Schema

ParametersJSON Schema
NameRequiredDescription

No output parameters

TDQS

A4.5/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description bears full responsibility for behavioral disclosure. It clearly states that this is a mutating operation (update), explains the effect of each parameter, and warns that resolving/closing may be rejected by the backend. It does not mention idempotency, error handling for missing incidents, or authentication requirements, but the provided details are sufficient for safe invocation.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is concise and well-structured. It starts with a one-sentence summary of the action, then a one-sentence usage context, then a constraint, then a clear Args/Returns section. Every sentence adds unique information; there is no redundancy.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

The description covers all parameters, provides a return format, and includes a key behavioral caveat (rejection on missing resolution fields). It is almost complete for a mutation tool with no annotations, but it does not specify what happens if the incident number does not exist or whether the operation is idempotent.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 0%, so the description must fully explain each parameter. It does so: number is given an example ('INC0010001'), work_notes is described as 'append to the (internal) work notes journal', and state is documented with both numeric codes and names, plus a note about additional fields required by ServiceNow. This adds significant semantic value beyond the bare schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description specifies a clear verb ('update'), resource ('existing incident'), and method ('by number'). It explicitly lists the two possible actions (append work notes and/or change state), which distinguishes it from siblings create_incident and query_incidents.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description advises when to use the tool ('record progress on a ticket or move it through its lifecycle') and states a critical constraint ('at least one of work_notes or state must be provided'). It also warns about potential rejection when resolving/closing if resolution fields are missing. However, it does not explicitly contrast with alternatives like create_incident or query_incidents.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

  1. 3 tool updatesv0.1.0
    • First observedcreate_incident
    • First observedquery_incidents
    • First observedupdate_incident

TDQS

A4.5/5.0

Scored across 3 tools

Disambiguation5/5

Each tool targets a distinct operation: create, query (list/search), and update. There is no overlap in purpose; an agent can clearly differentiate when to use each.

Naming Consistency5/5

All tools follow a consistent verb_noun pattern using snake_case (create_incident, query_incidents, update_incident), with plural nouns for collection queries and singular for single-item operations, which is predictable.

Tool Count4/5

With 3 tools, the set is minimal but covers the core incident lifecycle (create, read/search, update). It is slightly thin—missing a dedicated get_incident or delete_incident—but still well-scoped for a focused incident-only server.

Completeness3/5

The tools cover create, list/search, and update, but lack an explicit 'get by ID' tool (though query_incidents can filter by number) and a delete/close operation. The update tool warns about missing resolution fields for closing, indicating gaps in full lifecycle support.

Maintenance

ActivityMaintained
ResponsivenessSyncing

Related MCP Connectors

Related MCP Servers

  • A
    license
    A
    quality
    D
    maintenance
    An MCP server for interacting with a ServiceNow instance via its Table API, enabling CRUD operations on incident, request, and requested item tables, as well as generic operations on any table by name.
    22
    MIT