execute_groovy
Execute Groovy scripts in SAP Commerce Cloud to automate tasks, manage data, and configure system settings through the Hybris scripting console.
Instructions
Execute a Groovy script in the Hybris scripting console
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| script | Yes | Groovy script to execute | |
| commit | No | Whether to commit database changes (default: false) |
Implementation Reference
- src/hybris-client.ts:485-515 (handler)The core implementation of the Groovy script execution logic using the Hybris HAC API.
async executeGroovyScript(script: string, commit = false): Promise<{ output: string; result: unknown }> { const formData = new URLSearchParams({ script, scriptType: 'groovy', commit: commit.toString(), }); const response = await this.hacRequest<{ outputText?: string; executionResult?: unknown; stacktraceText?: string; }>( `${this.hacPrefix}/console/scripting/execute`, { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded', }, body: formData, } ); // Map HAC response fields to our expected format return { output: response.outputText || '', result: response.executionResult, }; } async importImpex(impexContent: string): Promise<ImpexResult> { // Use Groovy script for ImpEx import with ImportService - src/index.ts:212-225 (registration)Tool definition for 'execute_groovy' registered in the MCP tool list.
{ name: 'execute_groovy', description: 'Execute a Groovy script in the Hybris scripting console', inputSchema: { type: 'object', properties: { script: { type: 'string', description: 'Groovy script to execute', }, commit: { type: 'boolean', description: 'Whether to commit database changes (default: false)', }, - src/index.ts:423-427 (handler)The tool execution handler that processes requests by calling the hybrisClient.
case 'execute_groovy': result = await hybrisClient.executeGroovyScript( validateString(args, 'script', true), validateBoolean(args, 'commit', false) );