Run a script
run_scriptRun a JavaScript script (body of an async function: use top-level await and return) against the user's ZapX services, in a sandbox without network or file access. Use it for everything that READS, and for file changes (mutate_file): one script can call many tools, loop, filter and combine results, and return only the answer. API: await tools.(args) for the tools listed below; each returns the tool's parsed JSON result and throws an Error with the tool's message when it fails (try/catch per item when you loop). await searchTools(query, { limit? }) and await describeTool(name | names) return declarations inside the script. console.log(...) and the returned value form the output. Hand data back with return, not with throw: a thrown error marks the whole call as failed. Tools that exist for several products are one tool that takes the serviceId of any of them (read_file, list_files, get_service, read_logs, get_schedules, ...); arguments of another product are refused. Limits: 45 s, 50 tool calls (max 5 at once), output 24000 characters (return counts or the relevant lines, not whole files). Results are strict: reading a field a result does not have throws and lists the real fields. Other tools that change something are not available here; use call_tool for them. There are no timers (setTimeout, setInterval), fetch or require: you cannot wait inside a script; to wait for an operation, end the script and poll it with a later call (e.g. get_operation_status). Changes inside a script: tools.mutate_file(args) with confirm: true (the client asks the user to approve each script; tell the user beforehand which files the script changes). Read a file first and send its revision as expectedRevision when you write it. Calls run in order and nothing is rolled back: stop at the first error and return what was already changed. Core declarations: /** List all accessible services (gameservers, VPS, dedicated servers, TeamSpeak servers, Discord bots, and domains) in one normalized response. Prefer this for discovery. Pass a service's "id" to the tools of its type (gameserver ids to gameserver tools, VPS ids to vserver tools, ...). / tools.list_account_services(args?: {}): Promise<Array<{ id: string; name: string; status: string; // Type-specific summary: numericId plus e.g. game/primaryEndpoint (gameserver), template/primaryIp (vserver), port/defaultDomain (teamspeak), primaryIp/region (dedicated), template/primaryEndpoint/region (discord_bot), dnsMode/autoRenew/expiresAt (domain) summary: { [key: string]: unknown; }; type: "gameserver" | "vserver" | "teamspeak" | "dedicated" | "discord_bot" | "domain"; }>>; // Read-only: usable inside run_script. /* Poll the status of an async public API operation. */ tools.get_operation_status(args: { // @minLength 1 operationId: string; }): Promise<{ operation: { action: string; // ISO 8601 timestamp createdAt: string; error: string | null; // Operation id (use with get_operation_status) id: string; // Always null (internal job id is not exposed) jobId: null; // Always null (internal queue is not exposed) queue: null; serviceId: string | null; serviceType: string | null; // queued, running, succeeded or failed status: string; // ISO 8601 timestamp updatedAt: string; }; }>; // Read-only: usable inside run_script. Read-only tools (81): list_account_services, list_incidents, list_orderable_products, list_orderable_plans, list_orderable_product_regions, list_order_regions, list_orderable_games, list_vserver_order_isos, list_domain_tlds, check_domain_availability, search_domain_name, list_domain_contact_profiles, list_dedicated_platforms, list_dedicated_ready_builds, get_dedicated_platform_options, preview_order, get_order_status, get_payment_setup_status, recommend_plan, create_checkout_link, get_vserver_traffic, list_vserver_outgoing_ddos, get_vserver_dns, list_vserver_account_ssh_keys, list_vserver_ssh_keys, list_vserver_isos, get_vserver_metrics, get_vserver_firewall, get_dedicated_metrics, get_dedicated_hardware, get_dedicated_traffic, get_dedicated_traffic_quota, get_dedicated_traffic_history, get_dedicated_installation, get_dedicated_installation_progress, get_dedicated_installation_options, get_dedicated_remote_management, list_teamspeak_tokens, get_gameserver_container_status, list_gameserver_databases, get_gameserver_external_access, list_gameserver_savegames, list_gameserver_mods, check_gameserver_addon_updates, list_gameserver_plugins, get_gameserver_rust_framework, list_gameserver_modpacks, get_gameserver_workshop, list_vserver_snapshots, get_teamspeak_metrics, list_teamspeak_clients, list_teamspeak_bans, list_domains, get_domain, get_domain_dns_records, get_domain_nameservers, get_domain_renewal, get_operation_status, get_plan_change_status, list_services, get_service, get_service_activity, get_service_status, list_files, read_file, read_logs, get_config, get_schedules, list_backups, get_daily_backup, get_ddos_status, list_ddos_rules, list_ddos_incidents, get_ddos_bandwidth, get_reverse_dns, list_custom_isos, list_reinstall_templates, apps_catalog, apps_state, get_plan_change_options, preview_plan_change
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"code": "<code>"
},
"name": "run_script"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | JavaScript: body of an async function (top-level await, return the result). |