createComponent
Add a new component to an Adobe Experience Manager page by specifying the page path, component type, and resource type.
Instructions
Create a new component on a page
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| pagePath | Yes | ||
| componentType | Yes | ||
| resourceType | Yes | ||
| properties | No | ||
| name | No |
Implementation Reference
- Core handler function that executes the createComponent tool logic: validates inputs, constructs component path, performs HTTP POST to AEM instance to create the unstructured node with specified resourceType and properties.async createComponent(request: CreateComponentRequest): Promise<ComponentResponse> { return safeExecute<ComponentResponse>(async () => { const { pagePath, componentType, resourceType, properties = {}, name } = request; if (!isValidContentPath(pagePath)) { throw createAEMError( AEM_ERROR_CODES.INVALID_PARAMETERS, `Invalid page path: ${String(pagePath)}`, { pagePath } ); } if (!isValidComponentType(componentType)) { throw createAEMError( AEM_ERROR_CODES.INVALID_PARAMETERS, `Invalid component type: ${componentType}`, { componentType } ); } const componentName = name || `${componentType}_${Date.now()}`; const componentPath = `${pagePath}/jcr:content/${componentName}`; await this.httpClient.post(componentPath, { 'jcr:primaryType': 'nt:unstructured', 'sling:resourceType': resourceType, ...properties, ':operation': 'import', ':contentType': 'json', ':replace': 'true', }); return createSuccessResponse({ success: true, componentPath, componentType, resourceType, properties, timestamp: new Date().toISOString(), }, 'createComponent') as ComponentResponse; }, 'createComponent'); }
- src/mcp-server.ts:294-307 (registration)MCP tool registration in the server tools list, defining the name, description, and input schema for the createComponent tool.{ name: 'createComponent', description: 'Create a new component on a page', inputSchema: { type: 'object', properties: { pagePath: { type: 'string' }, componentType: { type: 'string' }, resourceType: { type: 'string' }, properties: { type: 'object' }, name: { type: 'string' }, }, required: ['pagePath', 'componentType', 'resourceType'], },
- src/mcp-server.ts:713-715 (handler)Top-level MCP server handler case that receives tool call, delegates to AEMConnector.createComponent, and formats response.case 'createComponent': { const result = await aemConnector.createComponent(args); return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
- src/aem-connector-new.ts:86-120 (schema)Delegation handler in AEMConnector that forwards the request to ComponentOperations module.async listPages(siteRoot: string, depth?: number, limit?: number) { return this.pageOps.listPages(siteRoot, depth, limit); } async getPageContent(pagePath: string) { return this.pageOps.getPageContent(pagePath); } async getPageProperties(pagePath: string) { return this.pageOps.getPageProperties(pagePath); } async activatePage(request: any) { return this.pageOps.activatePage(request); } async deactivatePage(request: any) { return this.pageOps.deactivatePage(request); } async getAllTextContent(pagePath: string) { return this.pageOps.getAllTextContent(pagePath); } async getPageTextContent(pagePath: string) { return this.pageOps.getPageTextContent(pagePath); } async getPageImages(pagePath: string) { return this.pageOps.getPageImages(pagePath); } // Component Operations async createComponent(request: any) {
- src/interfaces/index.ts:246-255 (schema)TypeScript interface defining the input parameters for createComponent (note: approximate lines based on search; actual may vary slightly).export interface CreateComponentRequest { pagePath: string; componentType: string; resourceType: string; properties?: Record<string, unknown>; name?: string; } export interface UpdateComponentRequest { componentPath: string;