UNPKG

aem-mcp-server

Version:
2 lines (1 loc) 1.39 kB
"use strict";import{CallToolRequestSchema as u,ListToolsRequestSchema as R,InitializeRequestSchema as p,LATEST_PROTOCOL_VERSION as d,SUPPORTED_PROTOCOL_VERSIONS as v}from"@modelcontextprotocol/sdk/types.js";import{Server as S}from"@modelcontextprotocol/sdk/server/index.js";import{tools as c}from"./mcp.tools.js";import{MCPRequestHandler as E}from"./mcp.aem-handler.js";import{LOGGER as n}from"../utils/logger.js";export const createMCPServer=l=>{const m=new E(l),a={name:"aem-mcp-server",version:"1.0.0"},i={capabilities:{resources:{},tools:{}},instructions:"This is an AEM MCP server that provides tools for managing AEM components and content."},t=new S(a,i);return t.setRequestHandler(p,e=>{const o=e.params.protocolVersion,r=v.includes(o)?o:d;return n.log("1. Received InitializeRequest",e,"response:",{protocolVersion:r}),{protocolVersion:r,...i,serverInfo:a}}),t.setRequestHandler(R,async()=>(n.log("2. Received ListToolsRequest",c),{tools:c})),t.setRequestHandler(u,async e=>{const{name:o,arguments:r}=e.params;if(n.log("3. Received CallToolRequestSchema",e.params),!r)return{content:[{type:"text",text:"Error: No arguments provided"}],isError:!0};try{const s=await m.handleRequest(o,r);return{content:[{type:"text",text:JSON.stringify(s,null,2)}]}}catch(s){return n.error("ERROR CallToolRequestSchema",s.message),{content:[{type:"text",text:`Error: ${s.message}`}],isError:!0}}}),t};