ActivateMetadataExtension
Activates a CDS metadata extension that remains inactive after creation or update.
Instructions
Activate a CDS metadata extension. Use after CreateMetadataExtension or UpdateMetadataExtension if the object remains inactive.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | Metadata extension name (e.g., ZC_MY_EXTENSION). | |
| session_id | No | Session ID from GetSession. If not provided, a new session will be created. | |
| session_state | No | Session state from GetSession (cookies, csrf_token, cookie_store). Required if session_id is provided. |
Implementation Reference
- Main handler function that activates an ABAP metadata extension using AdtClient.activateMetadataExtension. Validates input, restores session state, calls the ADT client, parses the activation response, and returns success/error details including messages, warnings, and errors.
export async function handleActivateMetadataExtension( context: HandlerContext, args: ActivateMetadataExtensionArgs, ) { const { connection, logger } = context; try { const { name, session_id, session_state } = args as ActivateMetadataExtensionArgs; // Validation if (!name) { return return_error(new Error('name is required')); } const client = createAdtClient(connection, logger); // Restore session state if provided if (session_id && session_state) { await restoreSessionInConnection(connection, session_id, session_state); } else { // Ensure connection is established } const metadataExtensionName = name.toUpperCase(); logger?.info( `Starting metadata extension activation: ${metadataExtensionName}`, ); try { // Activate metadata extension const activateState = await client .getMetadataExtension() .activate({ name: metadataExtensionName }); const response = activateState.activateResult; if (!response) { throw new Error( `Activation did not return a response for metadata extension ${metadataExtensionName}`, ); } // Parse activation response const activationResult = parseActivationResponse(response.data); const success = activationResult.activated && activationResult.checked; // Get updated session state after activation logger?.info( `✅ ActivateMetadataExtension completed: ${metadataExtensionName}`, ); logger?.debug( `Activated: ${activationResult.activated}, Checked: ${activationResult.checked}, Messages: ${activationResult.messages.length}`, ); return return_response({ data: JSON.stringify( { success, name: metadataExtensionName, activation: { activated: activationResult.activated, checked: activationResult.checked, generated: activationResult.generated, }, messages: activationResult.messages, warnings: activationResult.messages.filter( (m) => m.type === 'warning' || m.type === 'W', ), errors: activationResult.messages.filter( (m) => m.type === 'error' || m.type === 'E', ), session_id: session_id || null, session_state: null, // Session state management is now handled by auth-broker, message: success ? `Metadata extension ${metadataExtensionName} activated successfully` : `Metadata extension ${metadataExtensionName} activation completed with ${activationResult.messages.length} message(s)`, }, null, 2, ), } as AxiosResponse); } catch (error: any) { logger?.error( `Error activating metadata extension ${metadataExtensionName}: ${error?.message || error}`, ); // Parse error message let errorMessage = `Failed to activate metadata extension: ${error.message || String(error)}`; if (error.response?.status === 404) { errorMessage = `Metadata extension ${metadataExtensionName} not found.`; } else if ( error.response?.data && typeof error.response.data === 'string' ) { try { const { XMLParser } = require('fast-xml-parser'); const parser = new XMLParser({ ignoreAttributes: false, attributeNamePrefix: '@_', }); const errorData = parser.parse(error.response.data); const errorMsg = errorData['exc:exception']?.message?.['#text'] || errorData['exc:exception']?.message; if (errorMsg) { errorMessage = `SAP Error: ${errorMsg}`; } } catch (_parseError) { // Ignore parse errors } } return return_error(new Error(errorMessage)); } } catch (error: any) { return return_error(error); } } - TOOL_DEFINITION constant defining the tool's name ('ActivateMetadataExtensionLow'), description, and inputSchema. The inputSchema specifies 'name' (required string), plus optional 'session_id' and 'session_state'.
export const TOOL_DEFINITION = { name: 'ActivateMetadataExtensionLow', available_in: ['onprem', 'cloud'] as const, description: 'Operation: Activate, Create, Update. Subject: MetadataExtension. Will be useful for activating, creating, or updating metadata extension. [low-level] Activate an ABAP metadata extension. Returns activation status and any warnings/errors. Can use session_id and session_state from GetSession to maintain the same session.', inputSchema: { type: 'object', properties: { name: { type: 'string', description: 'Metadata extension name (e.g., ZC_MY_EXTENSION).', }, session_id: { type: 'string', description: 'Session ID from GetSession. If not provided, a new session will be created.', }, session_state: { type: 'object', description: 'Session state from GetSession (cookies, csrf_token, cookie_store). Required if session_id is provided.', properties: { cookies: { type: 'string' }, csrf_token: { type: 'string' }, cookie_store: { type: 'object' }, }, }, }, required: ['name'], }, } as const; - TypeScript interface ActivateMetadataExtensionArgs defining the shape of the handler arguments (name, session_id, session_state).
interface ActivateMetadataExtensionArgs { name: string; session_id?: string; session_state?: { cookies?: string; csrf_token?: string; cookie_store?: Record<string, string>; }; } - src/lib/handlers/groups/HighLevelHandlersGroup.ts:602-610 (registration)Registration of the tool as 'ActivateMetadataExtension' in the HighLevelHandlersGroup. It takes the TOOL_DEFINITION from the low-level handler, overrides the name to 'ActivateMetadataExtension', adds a high-level description, and wires it to handleActivateMetadataExtension wrapped with context.
{ toolDefinition: { ...ActivateMetadataExtension_Tool, name: 'ActivateMetadataExtension', description: 'Activate a CDS metadata extension. Use after CreateMetadataExtension or UpdateMetadataExtension if the object remains inactive.', }, handler: withContext(handleActivateMetadataExtension), }, - src/lib/handlers/groups/HighLevelHandlersGroup.ts:154-157 (registration)Import of the TOOL_DEFINITION (aliased as ActivateMetadataExtension_Tool) and handleActivateMetadataExtension from the low-level handler file.
import { TOOL_DEFINITION as ActivateMetadataExtension_Tool, handleActivateMetadataExtension, } from '../../../handlers/ddlx/low/handleActivateMetadataExtension';