execute_groovy
Execute Groovy scripts in SAP Commerce Cloud to automate tasks, manage data, and perform system administration 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/index.ts:415-420 (handler)MCP tool handler for 'execute_groovy': validates input arguments and delegates execution to HybrisClient.executeGroovyScript.case 'execute_groovy': result = await hybrisClient.executeGroovyScript( validateString(args, 'script', true), validateBoolean(args, 'commit', false) ); break;
- src/index.ts:215-228 (schema)Input schema for the 'execute_groovy' tool defining the expected parameters: required 'script' string and optional 'commit' boolean.inputSchema: { type: 'object', properties: { script: { type: 'string', description: 'Groovy script to execute', }, commit: { type: 'boolean', description: 'Whether to commit database changes (default: false)', }, }, required: ['script'], },
- src/index.ts:212-229 (registration)Registration of the 'execute_groovy' tool in the MCP tools list, including name, description, and input schema.{ 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)', }, }, required: ['script'], }, },
- src/hybris-client.ts:469-496 (helper)Core helper method implementing Groovy script execution by posting to Hybris HAC scripting endpoint and mapping the response.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, }; }