Skip to main content
Glama
sonisoft-cnanda

now-sdk-ext-mcp

Execute Background Script

execute_script
Destructive

Run server-side JavaScript on ServiceNow with full GlideSystem API access. Use for automation, data queries, or admin tasks; output via gs.print().

Instructions

Execute JavaScript on a ServiceNow instance using Scripts - Background (the /sys.scripts.do endpoint). The script runs server-side with full GlideSystem API access (gs, GlideRecord, GlideAggregate, GlideDateTime, GlideUser, etc.). Use gs.print() or gs.info() to produce output.

SCOPE BEHAVIOR: Scripts execute within the specified application scope. When running in a scoped app (e.g., scope: 'x_myapp_custom'), you can reference that scope's Script Includes and classes directly by name (e.g., MyUtil.doSomething()) without fully-qualifying them. When running in global scope, scoped classes must be fully-qualified (e.g., x_myapp_custom.MyUtil.doSomething()).

IMPORTANT: This executes code directly on the ServiceNow instance. Always review scripts before execution and prefer read-only operations unless modification is explicitly intended.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
scopeNoThe application scope to execute the script in. Accepts either: - A scope name (e.g., "global", "x_myapp_custom", "x_snc_app") — automatically resolved to the corresponding sys_id via the sys_scope table. - A sys_id directly (32-character hex string) if already known. Defaults to "global". Set this to the target app scope when you need to access scoped Script Includes, Business Rules, or other scoped artifacts by their unqualified names.global
paramsNoOptional key-value pairs for parameter substitution in the script. Every occurrence of {paramName} in the script text will be replaced with the corresponding value before execution. Useful for safely injecting dynamic values without string concatenation in the script. Example: { "table": "incident", "field": "priority" } replaces {table} and {field} in the script.
scriptYesThe JavaScript code to execute on the ServiceNow instance. Use gs.print() or gs.info() to output results — these are the only ways to capture output from background scripts. The script runs in the server-side Rhino engine with access to all ServiceNow server-side APIs: GlideRecord, GlideAggregate, GlideDateTime, GlideUser, gs.getUser(), gs.now(), GlideSysAttachment, and more. Scripts execute with the permissions of the authenticated user.
instanceNoThe ServiceNow instance auth alias to execute the script on. This is the alias configured via `now-sdk auth --add` (e.g., "myinstance", "prod", "test"). The user will typically refer to this by name when saying things like "on my myinstance instance". If not provided, falls back to the SN_AUTH_ALIAS environment variable.
Behavior5/5

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

The description goes well beyond the annotations by explaining server-side execution with full GlideSystem API access, output via gs.print()/gs.info(), scope resolution nuances, and an explicit safety warning about executing code directly on the instance. These details add valuable behavioral context that annotations alone do not convey.

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 structured in three focused paragraphs: an initial overview, a detailed scope behavior explanation, and a safety reminder. Each sentence serves a clear purpose, and the most critical information is front-loaded. There is no redundant text, making it highly efficient for its 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?

Given the tool's complexity and the absence of an output schema, the description is remarkably complete: it covers the target endpoint, available APIs, output capture methods, scope behavior, and safety precautions. The schema and annotations further fill in parameter and safety details, leaving no major contextual gaps.

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

Parameters3/5

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

The input schema provides 100% coverage with rich descriptions for all four parameters (script, scope, params, instance), including syntax, defaults, and usage examples. The description itself adds little to parameter semantics; the schema already handles this dimension thoroughly, so the baseline score of 3 is appropriate.

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 specifies the verb 'Execute' and the resource 'JavaScript on a ServiceNow instance using Scripts - Background (the /sys.scripts.do endpoint)'. This distinguishes it from sibling tools like execute_subflow or execute_action, which target predefined workflows rather than arbitrary code.

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

Usage Guidelines3/5

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

The description offers implicit usage context by detailing scope behavior and warning to 'prefer read-only operations unless modification is explicitly intended,' but it does not explicitly state when to choose this tool over alternatives like execute_subflow or execute_flow. No direct comparisons or exclusions are provided, so guidance remains implied rather than explicit.

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

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/sonisoft-cnanda/now-sdk-ext-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server