UNPKG

aem-mcp-server

Version:
2 lines (1 loc) 1.89 kB
"use strict";import r from"express";import d from"cors";import{handleRequest as l}from"../mcp/mcp.server-handler.js";import{AEMConnector as h}from"../aem/aem.connector.js";import{config as c}from"../config.js";import{LOGGER as n}from"../utils/logger.js";const u=(s={})=>{const e=r();e.use(d({origin:"*",exposedHeaders:["Mcp-Session-Id"]})),e.use(r.json()),e.use(r.json({limit:"10mb"})),e.use(r.urlencoded({extended:!0}));const i=new h(s);return e.get("/health",async(o,t)=>{try{const{aem:a,auth:p}=await i.testConnection(),m={status:"healthy",aem:a?"connected":"disconnected",auth:p?"authorized":"not authorized",mcp:"ready",timestamp:new Date().toISOString(),version:c.APP_VERSION||"1.0.0"};t.json(m)}catch(a){t.status(500).json({status:"unhealthy",error:a.message,timestamp:new Date().toISOString()})}}),e.post("/mcp",async(o,t)=>{await l(o,t,s)}),e.get("/mcp",async(o,t)=>{t.status(405).set("Allow","POST").send("Method Not Allowed")}),e.delete("/mcp",async(o,t)=>{n.log("Received DELETE MCP request"),t.writeHead(405).end(JSON.stringify({jsonrpc:"2.0",error:{code:-32e3,message:"Method not allowed."},id:null}))}),e.get("/",(o,t)=>{t.json({name:"AEM MCP Gateway Server",description:"A Model Context Protocol server for Adobe Experience Manager",version:c.APP_VERSION||"1.0.0",endpoints:{health:{method:"GET",path:"/health",description:"Health check for all services"},mcp:{method:"POST",path:"/mcp",description:"JSON-RPC endpoint for MCP calls"},mcpMethods:{method:"GET",path:"/mcp/methods",description:"List all available MCP methods"}},architecture:"MCP integration",timestamp:new Date().toISOString()})}),e};export const startServer=(s={})=>{const{mcpPort:e=8502}=s||{};u(s).listen(e,o=>{o&&(n.error("Failed to start server:",o),process.exit(1)),n.log(`0. AEM MCP Server listening on port ${e}`)})};process.on("SIGINT",async()=>{n.log("Shutting down server..."),process.exit(0)});