UNPKG

aem-mcp-server

Version:

AEM MCP server. Chat with your AEM instance for content, component, and asset operations.

2 lines (1 loc) 2.06 kB
"use strict";import{LOGGER as a}from"../utils/logger.js";const i=[{key:"components",name:"AEM Components",description:"All components (name, resourceType, title, group)"},{key:"sites",name:"AEM Sites",description:"Site roots and language structure under /content"},{key:"templates",name:"AEM Templates",description:"Available page templates (path, title)"},{key:"workflow-models",name:"AEM Workflow Models",description:"Workflow models (ID, title, description)"}];export function getResourceDefinitions(n){return i.map(o=>({uri:`aem://${n}/${o.key}`,name:`${o.name} [${n}]`,description:o.description,mimeType:"application/json"}))}function m(n,o){const s=n?.data??n;switch(o){case"components":{const t=s?.components??[];return{totalCount:t.length,components:t.map(e=>({name:e.name,title:e.title,resourceType:e.resourceType,group:e.componentGroup||e.group}))}}case"sites":{const t=s?.sites??[];return{totalCount:t.length,sites:t.map(e=>({name:e.name,path:e.path,title:e.title}))}}case"templates":{const t=s?.templates??[];return{totalCount:t.length,templates:t.map(e=>({name:e.name,path:e.path,title:e.title}))}}case"workflow-models":{const t=s?.models??s?.commonWorkflows??[];return{totalCount:t.length,models:t.map(e=>({modelId:e.modelId,uri:e.uri,description:e.description}))}}default:return s}}export async function readResource(n,o){const s=n.match(/^aem:\/\/([^/]+)\/(.+)$/);if(!s)return{uri:n,mimeType:"application/json",text:JSON.stringify({error:`Invalid resource URI: ${n}`})};const[,,t]=s;try{let e;switch(t){case"components":e=await o.getComponents();break;case"sites":e=await o.fetchSites();break;case"templates":e=await o.getTemplates();break;case"workflow-models":e=await o.listWorkflowModels();break;default:return{uri:n,mimeType:"application/json",text:JSON.stringify({error:`Unknown resource: ${t}`})}}const r=m(e,t);return{uri:n,mimeType:"application/json",text:JSON.stringify(r,null,2)}}catch(e){return a.error(`Resource read failed for ${n}:`,e.message),{uri:n,mimeType:"application/json",text:JSON.stringify({error:e.message,uri:n})}}}