Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/Mats2208/MCP-Packet-Tracer/llms.txt

Use this file to discover all available pages before exploring further.

pt_generate_script turns a validated TopologyPlan (the JSON output of pt_plan_topology) into a ready-to-run JavaScript file for Cisco Packet Tracer’s PTBuilder Script Engine. The script places every device on the logical canvas, installs expansion modules, draws cables between interfaces, and — when include_configs is true — embeds the full IOS CLI configuration as /* */ block comments so you can review everything in one file before running it.

Parameters

plan_json
string
required
The TopologyPlan JSON produced by pt_plan_topology or pt_full_build. Must contain a non-empty devices array.
include_configs
boolean
default:"true"
When true, calls generate_full_script internally: the returned script appends all IOS CLI config blocks as /* --- DeviceName --- ... */ block comments after the structural calls. When false, calls generate_ptbuilder_script and returns only the lwAddDevice / addModule / lwAddLink lines with no configuration content.

Return value

script
string
A JavaScript string ready to paste into Packet Tracer via Extensions → Scripting, or to send directly to a running Packet Tracer instance via pt_live_deploy. Each PTBuilder function call occupies its own line.

Script structure

The generator follows a strict three-phase ordering that PTBuilder’s Script Engine requires: devices must exist before modules can be installed, and modules must be installed before any link can reference the ports they add.
// Phase 1 — place devices on the logical canvas
lwAddDevice("R1", 0, "2911", 100, 100);
lwAddDevice("SW1", 1, "2960-24TT", 100, 300);
lwAddDevice("PC1", 8, "PC-PT", 300, 300);

// Phase 2 — install expansion modules (only present when the plan includes modules)
addModule("R1", "0/0", "HWIC-2T");

// Phase 3 — draw cables (cable type passed as a numeric PT enum)
lwAddLink("R1", "GigabitEthernet0/0", "SW1", "GigabitEthernet0/1", 8100);
lwAddLink("SW1", "FastEthernet0/1", "PC1", "FastEthernet0", 8100);

// Phase 4 — IOS configs as block comments (include_configs=true only)
/* --- R1 ---
enable
configure terminal
hostname R1
...
*/ 
The script uses lwAddDevice and lwAddLink — logical-workspace helpers injected by the runtime patches — rather than the raw addDevice / addLink globals. The helpers write directly to the logical canvas so devices and cables appear immediately without requiring a save-and-reload cycle in Packet Tracer. Cable types are passed as numeric PT IPC enum values (e.g. 8100 for straight-through, 8107 for auto-detect) rather than string names.

Example script excerpt

The following excerpt shows what a two-device topology looks like after generation. When include_configs=true, CLI content appears as block comments at the end. When pt_live_deploy runs, it uses generate_executable_script internally, which replaces those comments with live configureIosDevice and configurePcIp calls.
lwAddDevice("R1", 0, "2911", 100, 100);
addModule("R1", "0/0", "HWIC-2T");
lwAddDevice("SW1", 1, "2960-24TT", 100, 300);
lwAddLink("R1", "GigabitEthernet0/0", "SW1", "GigabitEthernet0/1", 8100);
/* === Configuraciones CLI por dispositivo ===
Copiar y pegar en la CLI de cada dispositivo. */
/* --- R1 ---
enable
configure terminal
hostname R1
...
*/ 

Execution order requirement

PTBuilder’s Script Engine is sequential and stateful. Calling lwAddLink before both endpoint devices exist raises a runtime error. The generator enforces the required order automatically:
  1. lwAddDevice — creates the device on the logical canvas
  2. addModule — installs expansion modules (e.g. HWIC-2T for serial ports); must run after the device is placed and before any link references module-added ports
  3. lwAddLink — connects two interface ports with the specified cable type

Relationship to pt_live_deploy

pt_generate_script only produces the script string — it does not send anything to Packet Tracer. When you call pt_live_deploy, the server internally calls generate_executable_script (which combines structural calls with live configureIosDevice / configurePcIp calls instead of comments) and streams each line to the HTTP bridge on port 54321, where PTBuilder picks it up every 500 ms and executes it in the Script Engine. Use pt_generate_script when you want to inspect or manually paste the script. Use pt_live_deploy when you want fully automated, real-time deployment into a running Packet Tracer instance.
Pipe the output of pt_generate_script into pt_deploy to copy it to the Windows clipboard with step-by-step paste instructions — no bridge required.

Build docs developers (and LLMs) love