Create AM Script
createScriptCreates a new script for Scripted Decision Nodes to define custom authentication logic in PingOne journeys.
Instructions
Create a new Scripted Decision Node script for use in authentication journeys. Use getScriptedDecisionNodeBindings to see available variables and allowed imports before writing the script.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| realm | Yes | The realm to create the script in | |
| name | Yes | The name of the script | |
| description | No | Optional description of the script | |
| script | Yes | The JavaScript source code for the script |
Implementation Reference
- src/tools/am/createScript.ts:8-65 (handler)The main tool definition and handler function for 'createScript'. Defines the tool's name, title, description, scopes, input schema (realm, name, description, script), and the toolFunction that makes an authenticated POST request to AM to create a script.
export const createScriptTool = { name: 'createScript', title: 'Create AM Script', description: 'Create a new Scripted Decision Node script for use in authentication journeys. Use getScriptedDecisionNodeBindings to see available variables and allowed imports before writing the script.', scopes: SCOPES, annotations: { destructiveHint: false, openWorldHint: true }, inputSchema: { realm: z.enum(REALMS).describe('The realm to create the script in'), name: z.string().min(1).describe('The name of the script'), description: z.string().optional().describe('Optional description of the script'), script: z.string().min(1).describe('The JavaScript source code for the script') }, async toolFunction({ realm, name, description, script }: { realm: string; name: string; description?: string; script: string; }) { try { const url = `${buildAMRealmUrl(realm, 'scripts')}?_action=create`; const payload = { context: 'AUTHENTICATION_TREE_DECISION_NODE', name, description: description || '', language: 'JAVASCRIPT', script: encodeBase64(script), evaluatorVersion: '2.0' }; const { data, response } = await makeAuthenticatedRequest(url, SCOPES, { method: 'POST', headers: AM_SCRIPT_HEADERS_V2, body: JSON.stringify(payload) }); const scriptData = data as { _id: string; name: string }; const transactionId = response.headers.get('x-forgerock-transactionid') || 'unknown'; return createToolResponse( `Script "${scriptData.name}" created successfully.\n` + `Script ID: ${scriptData._id}\n` + `Transaction ID: ${transactionId}` ); } catch (error: any) { return createToolResponse(`Failed to create script "${name}" in realm "${realm}": ${error.message}`); } } }; - src/tools/am/createScript.ts:18-23 (schema)Input schema for createScript using Zod: realm (enum from REALMS), name (string), description (optional string), script (string - the JavaScript source code).
inputSchema: { realm: z.enum(REALMS).describe('The realm to create the script in'), name: z.string().min(1).describe('The name of the script'), description: z.string().optional().describe('Optional description of the script'), script: z.string().min(1).describe('The JavaScript source code for the script') }, - src/index.ts:27-44 (registration)Generic tool registration loop: allTools.forEach calls server.registerTool with the tool's name, config, and toolFunction. createScript is registered here as part of the AM tools collection.
allTools.forEach((tool) => { const toolConfig: ToolConfig = { title: tool.title, description: tool.description }; // Only add inputSchema if it exists (some tools like getLogSources don't have one) if ('inputSchema' in tool && tool.inputSchema) { toolConfig.inputSchema = tool.inputSchema; } // Add annotations if present if ('annotations' in tool && tool.annotations) { toolConfig.annotations = tool.annotations; } server.registerTool(tool.name, toolConfig, tool.toolFunction as any); }); - src/utils/toolHelpers.ts:15-33 (registration)getAllTools collects all tools including AM tools (via amTools) that contains createScriptTool. AM tools are conditionally included only in non-Docker mode.
export function getAllTools(): Tool[] { const isDockerMode = process.env.DOCKER_CONTAINER === 'true'; const tools: Tool[] = [ ...(Object.values(managedObjectTools) as Tool[]), ...(Object.values(logTools) as Tool[]), ...(Object.values(themeTools) as Tool[]), ...(Object.values(esvTools) as Tool[]), ...(Object.values(featureManagementTools) as Tool[]) ]; // Only include AM tools in non-Docker mode (requires browser-based PKCE auth) if (!isDockerMode) { tools.push(...(Object.values(amTools) as Tool[])); tools.push(...(Object.values(applicationTools) as Tool[])); } return tools; } - src/tools/am/createScript.ts:36-50 (helper)Uses helper utilities: buildAMRealmUrl to construct the URL, AM_SCRIPT_HEADERS_V2 for request headers, encodeBase64 to encode the script content, and makeAuthenticatedRequest to perform the API call.
const url = `${buildAMRealmUrl(realm, 'scripts')}?_action=create`; const payload = { context: 'AUTHENTICATION_TREE_DECISION_NODE', name, description: description || '', language: 'JAVASCRIPT', script: encodeBase64(script), evaluatorVersion: '2.0' }; const { data, response } = await makeAuthenticatedRequest(url, SCOPES, { method: 'POST', headers: AM_SCRIPT_HEADERS_V2, body: JSON.stringify(payload)