← All changes
|
assets/js/packages/elementor-capabilities-mcp/elementor-capabilities-mcp.js
+195
-388
4.2.0-dev2
→
trunk
View file →
| @@ -1,198 +1,70 @@ | ||
| 1 | -/******/ (function() { // webpackBootstrap | |
| 2 | -/******/ "use strict"; | |
| 3 | -/******/ var __webpack_modules__ = ({ | |
| 1 | +(function(_elementor_editor_mcp, _elementor_elementor_mcp_common, _elementor_schema) { | |
| 4 | 2 | |
| 5 | -/***/ "./packages/apps/elementor-capabilities-mcp/src/elementor-capabilities-mcp-server.ts": | |
| 6 | -/*!*******************************************************************************************!*\ | |
| 7 | - !*** ./packages/apps/elementor-capabilities-mcp/src/elementor-capabilities-mcp-server.ts ***! | |
| 8 | - \*******************************************************************************************/ | |
| 9 | -/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) { | |
| 3 | +//#region \0rolldown/runtime.js | |
| 4 | + var __defProp = Object.defineProperty; | |
| 5 | + var __name = (target, value) => __defProp(target, "name", { | |
| 6 | + value, | |
| 7 | + configurable: true | |
| 8 | + }); | |
| 9 | + var __exportAll = (all, no_symbols) => { | |
| 10 | + let target = {}; | |
| 11 | + for (var name in all) { | |
| 12 | + __defProp(target, name, { | |
| 13 | + get: all[name], | |
| 14 | + enumerable: true | |
| 15 | + }); | |
| 16 | + } | |
| 17 | + if (!no_symbols) { | |
| 18 | + __defProp(target, Symbol.toStringTag, { value: "Module" }); | |
| 19 | + } | |
| 20 | + return target; | |
| 21 | + }; | |
| 10 | 22 | |
| 11 | -__webpack_require__.r(__webpack_exports__); | |
| 12 | -/* harmony export */ __webpack_require__.d(__webpack_exports__, { | |
| 13 | -/* harmony export */ createElementorCapabilitiesServer: function() { return /* binding */ createElementorCapabilitiesServer; }, | |
| 14 | -/* harmony export */ getSafeOrigin: function() { return /* binding */ getSafeOrigin; }, | |
| 15 | -/* harmony export */ safeNavigateAfterResponse: function() { return /* binding */ safeNavigateAfterResponse; } | |
| 16 | -/* harmony export */ }); | |
| 17 | -/* harmony import */ var _elementor_editor_mcp__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @elementor/editor-mcp */ "@elementor/editor-mcp"); | |
| 18 | -/* harmony import */ var _elementor_editor_mcp__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_elementor_editor_mcp__WEBPACK_IMPORTED_MODULE_0__); | |
| 19 | -/* harmony import */ var _elementor_elementor_mcp_common__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @elementor/elementor-mcp-common */ "@elementor/elementor-mcp-common"); | |
| 20 | -/* harmony import */ var _elementor_elementor_mcp_common__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_elementor_elementor_mcp_common__WEBPACK_IMPORTED_MODULE_1__); | |
| 21 | -/* harmony import */ var _elementor_schema__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @elementor/schema */ "@elementor/schema"); | |
| 22 | -/* harmony import */ var _elementor_schema__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_elementor_schema__WEBPACK_IMPORTED_MODULE_2__); | |
| 23 | -/* harmony import */ var _mcp_description_resource__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./mcp-description-resource */ "./packages/apps/elementor-capabilities-mcp/src/mcp-description-resource.ts"); | |
| 24 | -/* harmony import */ var _pages_list_resource__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./pages-list-resource */ "./packages/apps/elementor-capabilities-mcp/src/pages-list-resource.ts"); | |
| 23 | +//#endregion | |
| 25 | 24 | |
| 25 | +//#region packages/apps/elementor-capabilities-mcp/src/pages-list-resource.ts | |
| 26 | + var PAGES_LIST_RESOURCE_URI = "wp://pages/list"; | |
| 27 | + function addPagesListResource(server) { | |
| 28 | + server.registerResource("wp-pages-list", PAGES_LIST_RESOURCE_URI, { | |
| 29 | + title: "List of wordpress pages", | |
| 30 | + description: "List of all WordPress pages with their IDs, titles, status, and metadata. Use this to get available pages before navigation or editing." | |
| 31 | + }, async (uri) => { | |
| 32 | + try { | |
| 33 | + const pages = (await (0, _elementor_elementor_mcp_common.callWpApi)("/wp/v2/pages?per_page=100&orderby=modified&order=desc", "GET")).data; | |
| 34 | + if (!Array.isArray(pages)) throw new Error("Invalid response format from wordpress pages API"); | |
| 35 | + const pagesList = pages.map((page) => ({ | |
| 36 | + id: page.id, | |
| 37 | + title: page.title.rendered, | |
| 38 | + status: page.status, | |
| 39 | + link: page.link, | |
| 40 | + modified: page.modified, | |
| 41 | + type: page.type | |
| 42 | + })); | |
| 43 | + return { contents: [{ | |
| 44 | + uri: uri.href, | |
| 45 | + mimeType: "application/json", | |
| 46 | + text: JSON.stringify({ | |
| 47 | + pages: pagesList, | |
| 48 | + total: pagesList.length, | |
| 49 | + message: "List of all available wordpress pages" | |
| 50 | + }, null, 2) | |
| 51 | + }] }; | |
| 52 | + } catch (error) { | |
| 53 | + throw new Error(`Failed to fetch pages list: ${error.message}`); | |
| 54 | + } | |
| 55 | + }); | |
| 56 | + } | |
| 26 | 57 | |
| 58 | +//#endregion | |
| 59 | +//#region packages/apps/elementor-capabilities-mcp/src/mcp-description-resource.ts | |
| 60 | + var CAPABILITIES_DESCRIPTION_URI = "elementor://capabilities/server-description"; | |
| 61 | + var CAPABILITIES_DESCRIPTION = `## Elementor Page Builder - Available When In Editor | |
| 27 | 62 | |
| 28 | - | |
| 29 | - | |
| 30 | -// Constants | |
| 31 | -const ANGIE_REQUIRED_RESOURCES = 'angie/requiredResources'; | |
| 32 | -const WP_PAGES_ENDPOINT = '/wp/v2/pages'; | |
| 33 | -const ELEMENTOR_EDIT_MODE = 'builder'; | |
| 34 | -const DEFAULT_PAGE_TITLE = 'New Page'; | |
| 35 | -const ELEMENTOR_EDIT_ACTION = 'elementor'; | |
| 36 | -const getSafeOrigin = () => { | |
| 37 | - if (typeof window === 'undefined') { | |
| 38 | - return ''; | |
| 39 | - } | |
| 40 | - const url = new URL(window.location.href); | |
| 41 | - const originParam = `${url.protocol}://${url.host}`; | |
| 42 | - return originParam || ''; | |
| 43 | -}; | |
| 44 | -function safeNavigateAfterResponse(url) { | |
| 45 | - try { | |
| 46 | - const angieIframe = (0,_elementor_editor_mcp__WEBPACK_IMPORTED_MODULE_0__.getAngieIframe)(); | |
| 47 | - | |
| 48 | - // @ts-ignore: It's not null | |
| 49 | - angieIframe.contentWindow.postMessage({ | |
| 50 | - type: _elementor_editor_mcp__WEBPACK_IMPORTED_MODULE_0__.AngieMessageEvenetType.ANGIE_NAVIGATE_AFTER_RESPONSE, | |
| 51 | - payload: { | |
| 52 | - url | |
| 53 | - } | |
| 54 | - }, getSafeOrigin()); | |
| 55 | - } finally { | |
| 56 | - setTimeout(() => { | |
| 57 | - window.location.replace(url); | |
| 58 | - }, 50); | |
| 59 | - } | |
| 60 | -} | |
| 61 | - | |
| 62 | -/** | |
| 63 | - * Creates an MCP server that exposes Elementor capabilities when NOT in the editor | |
| 64 | - * This helps Angie understand what Elementor can do and navigate users to the editor | |
| 65 | - */ | |
| 66 | -function createElementorCapabilitiesServer() { | |
| 67 | - const server = new _elementor_elementor_mcp_common__WEBPACK_IMPORTED_MODULE_1__.McpServer({ | |
| 68 | - name: 'elementor-capabilities-server', | |
| 69 | - version: '1.0.0', | |
| 70 | - title: 'Elementor Capabilities' | |
| 71 | - }, { | |
| 72 | - instructions: `Provides Elementor page-building capabilities and navigates users to the editor.`, | |
| 73 | - capabilities: { | |
| 74 | - resources: { | |
| 75 | - subscribe: true | |
| 76 | - } | |
| 77 | - } | |
| 78 | - }); | |
| 79 | - (0,_pages_list_resource__WEBPACK_IMPORTED_MODULE_4__.addPagesListResource)(server); | |
| 80 | - (0,_mcp_description_resource__WEBPACK_IMPORTED_MODULE_3__.addCapabilitiesDescriptionResource)(server); | |
| 81 | - server.registerTool('navigate-to-elementor-editor', { | |
| 82 | - description: `Navigate the user to the Elementor editor. Causes a full page reload — editor-related tools become available afterward. | |
| 83 | - | |
| 84 | -Workflow: choose from the pages list resource → set pageId (edit) OR createNew=true (new page) with confirmationMessage.`, | |
| 85 | - inputSchema: { | |
| 86 | - pageId: _elementor_schema__WEBPACK_IMPORTED_MODULE_2__.z.number().optional().describe('The ID of the page to navigate to. Only provide after user has explicitly selected a page from the available pages list. When provided, confirmationMessage is REQUIRED.'), | |
| 87 | - createNew: _elementor_schema__WEBPACK_IMPORTED_MODULE_2__.z.boolean().optional().describe('Set to true ONLY when user explicitly requests to create a new page. When true, confirmationMessage is REQUIRED. Default is false.'), | |
| 88 | - newPageTitle: _elementor_schema__WEBPACK_IMPORTED_MODULE_2__.z.string().optional().describe('Title for the new page when createNew is true. Use what the user specified or default to "New Page".'), | |
| 89 | - confirmationMessage: _elementor_schema__WEBPACK_IMPORTED_MODULE_2__.z.string().optional().describe("REQUIRED when pageId or createNew is provided. A clear message shown to user before navigation. Example: \"I'll open the 'Homepage' in Elementor editor so you can add a form widget. Ready to proceed?\" Omit when just fetching available pages.") | |
| 90 | - }, | |
| 91 | - annotations: { | |
| 92 | - title: 'Navigate to Elementor Editor', | |
| 93 | - destructiveHint: true | |
| 94 | - }, | |
| 95 | - _meta: { | |
| 96 | - [ANGIE_REQUIRED_RESOURCES]: [{ | |
| 97 | - uri: _mcp_description_resource__WEBPACK_IMPORTED_MODULE_3__.CAPABILITIES_DESCRIPTION_URI, | |
| 98 | - whenToUse: 'Read first for full capabilities and limitations guide' | |
| 99 | - }, { | |
| 100 | - uri: _pages_list_resource__WEBPACK_IMPORTED_MODULE_4__.PAGES_LIST_RESOURCE_URI, | |
| 101 | - whenToUse: 'Always use this resource first to understand what pages are available before asking the user which page to edit' | |
| 102 | - }] | |
| 103 | - } | |
| 104 | - }, async params => { | |
| 105 | - try { | |
| 106 | - if ((params.pageId || params.createNew) && !params.confirmationMessage) { | |
| 107 | - throw new Error('confirmationMessage is required when navigating to a page (pageId or createNew provided)'); | |
| 108 | - } | |
| 109 | - if (params.createNew) { | |
| 110 | - return await handleCreateAndNavigate(params); | |
| 111 | - } | |
| 112 | - if (params.pageId) { | |
| 113 | - return await handleNavigateToPage(params.pageId); | |
| 114 | - } | |
| 115 | - throw new Error('Either pageId or createNew must be provided. The pages list is available in the wp-pages-list resource.'); | |
| 116 | - } catch (error) { | |
| 117 | - // eslint-disable-next-line no-console | |
| 118 | - console.error('[Elementor Capabilities Server] navigation error:', error); | |
| 119 | - throw new Error(`Error navigating to Elementor editor: ${error.message}`); | |
| 120 | - } | |
| 121 | - }); | |
| 122 | - return server; | |
| 123 | -} | |
| 124 | -async function handleCreateAndNavigate(params) { | |
| 125 | - const title = params.newPageTitle || DEFAULT_PAGE_TITLE; | |
| 126 | - const response = await (0,_elementor_elementor_mcp_common__WEBPACK_IMPORTED_MODULE_1__.callWpApi)(WP_PAGES_ENDPOINT, 'POST', { | |
| 127 | - title, | |
| 128 | - status: 'draft', | |
| 129 | - meta: { | |
| 130 | - _elementor_edit_mode: ELEMENTOR_EDIT_MODE | |
| 131 | - } | |
| 132 | - }); | |
| 133 | - const newPage = response.data; | |
| 134 | - if (!newPage || typeof newPage !== 'object' || !('id' in newPage)) { | |
| 135 | - throw new Error('Invalid response from page creation API'); | |
| 136 | - } | |
| 137 | - return await handleNavigateToPage(newPage.id); | |
| 138 | -} | |
| 139 | -async function handleNavigateToPage(pageId) { | |
| 140 | - if (!pageId || pageId <= 0) { | |
| 141 | - throw new Error('Invalid page ID'); | |
| 142 | - } | |
| 143 | - const response = await (0,_elementor_elementor_mcp_common__WEBPACK_IMPORTED_MODULE_1__.callWpApi)(`${WP_PAGES_ENDPOINT}/${pageId}`, 'GET'); | |
| 144 | - const page = response.data; | |
| 145 | - if (!page || typeof page !== 'object' || !('id' in page) || !('title' in page)) { | |
| 146 | - throw new Error(`Invalid page data received for page ID ${pageId}`); | |
| 147 | - } | |
| 148 | - const editUrl = generateElementorEditUrl(pageId); | |
| 149 | - if (!editUrl.startsWith(window.location.origin)) { | |
| 150 | - throw new Error('Invalid navigation URL'); | |
| 151 | - } | |
| 152 | - safeNavigateAfterResponse(editUrl); | |
| 153 | - return { | |
| 154 | - content: [{ | |
| 155 | - type: 'text', | |
| 156 | - text: JSON.stringify({ | |
| 157 | - success: true, | |
| 158 | - message: `Navigating to Elementor editor for page: ${page.title.rendered}`, | |
| 159 | - pageId: page.id, | |
| 160 | - pageTitle: page.title.rendered, | |
| 161 | - editUrl, | |
| 162 | - nextSteps: 'Once in the Elementor editor, you can use Elementor MCP tools for page settings, UI navigation, AI content generation, custom styling, and dynamic content.' | |
| 163 | - }, null, 2) | |
| 164 | - }] | |
| 165 | - }; | |
| 166 | -} | |
| 167 | -function generateElementorEditUrl(pageId) { | |
| 168 | - const baseUrl = window.location.origin; | |
| 169 | - return `${baseUrl}/wp-admin/post.php?post=${pageId}&action=${ELEMENTOR_EDIT_ACTION}`; | |
| 170 | -} | |
| 171 | - | |
| 172 | -/***/ }), | |
| 173 | - | |
| 174 | -/***/ "./packages/apps/elementor-capabilities-mcp/src/mcp-description-resource.ts": | |
| 175 | -/*!**********************************************************************************!*\ | |
| 176 | - !*** ./packages/apps/elementor-capabilities-mcp/src/mcp-description-resource.ts ***! | |
| 177 | - \**********************************************************************************/ | |
| 178 | -/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) { | |
| 179 | - | |
| 180 | -__webpack_require__.r(__webpack_exports__); | |
| 181 | -/* harmony export */ __webpack_require__.d(__webpack_exports__, { | |
| 182 | -/* harmony export */ CAPABILITIES_DESCRIPTION: function() { return /* binding */ CAPABILITIES_DESCRIPTION; }, | |
| 183 | -/* harmony export */ CAPABILITIES_DESCRIPTION_URI: function() { return /* binding */ CAPABILITIES_DESCRIPTION_URI; }, | |
| 184 | -/* harmony export */ addCapabilitiesDescriptionResource: function() { return /* binding */ addCapabilitiesDescriptionResource; } | |
| 185 | -/* harmony export */ }); | |
| 186 | -/* harmony import */ var _pages_list_resource__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./pages-list-resource */ "./packages/apps/elementor-capabilities-mcp/src/pages-list-resource.ts"); | |
| 187 | - | |
| 188 | -const CAPABILITIES_DESCRIPTION_URI = 'elementor://capabilities/server-description'; | |
| 189 | -const CAPABILITIES_DESCRIPTION = `## Elementor Page Builder - Available When In Editor | |
| 190 | - | |
| 191 | 63 | This MCP provides information about Elementor's page building capabilities. When users ask about Elementor features, you should navigate them to the Elementor editor where full capabilities are available. |
| 192 | 64 | |
| 193 | 65 | ### Available Resources: |
| 194 | -**Pages List Resource** (\`${_pages_list_resource__WEBPACK_IMPORTED_MODULE_0__.PAGES_LIST_RESOURCE_URI}\`): | |
| 66 | +**Pages List Resource** (\`${PAGES_LIST_RESOURCE_URI}\`): | |
| 195 | 67 | - Lists all WordPress pages with IDs, titles, status, and metadata |
| 196 | 68 | - Use this to see what pages are available before navigation |
| 197 | 69 | - Updated automatically when pages are created or modified |
| 198 | 70 | - Useful for suggesting pages to edit or checking if a page exists |
| @@ -254,17 +126,17 @@ | ||
| 254 | 126 | **When users ask about Elementor features:** |
| 255 | 127 | 1. Confirm what they want to accomplish |
| 256 | 128 | 2. Check if it's a supported capability (see lists above) |
| 257 | 129 | 3. **Get the page to edit:** |
| 258 | - - If user says "create new page" → Use createNew=true | |
| 259 | - - Otherwise → Call tool with no parameters to get page list | |
| 130 | + - If user says "create new page" \u2192 Use createNew=true | |
| 131 | + - Otherwise \u2192 Call tool with no parameters to get page list | |
| 260 | 132 | - Show pages to user: "Which page? Homepage, About, Contact..." |
| 261 | - - User chooses → Call tool again with that pageId | |
| 133 | + - User chooses \u2192 Call tool again with that pageId | |
| 262 | 134 | 4. Once in editor, full Elementor MCP tools will be available |
| 263 | 135 | |
| 264 | 136 | **Examples:** |
| 265 | -- User: "Edit homepage" → Get page list → Find "Homepage" → Ask to confirm → Navigate | |
| 266 | -- User: "Create new page" → createNew=true → Navigate | |
| 137 | +- User: "Edit homepage" \u2192 Get page list \u2192 Find "Homepage" \u2192 Ask to confirm \u2192 Navigate | |
| 138 | +- User: "Create new page" \u2192 createNew=true \u2192 Navigate | |
| 267 | 139 | |
| 268 | 140 | **Examples of when to navigate to editor:** |
| 269 | 141 | - "Edit my homepage with Elementor" |
| 270 | 142 | - "Apply custom CSS to my page" |
| @@ -290,208 +162,143 @@ | ||
| 290 | 162 | - Once in editor, the full 'elementor' MCP server with all tools becomes available |
| 291 | 163 | - Always verify if the requested feature is supported before navigating |
| 292 | 164 | |
| 293 | 165 | **Important**: When users ask "What can Angie do?" or similar questions about Angie's general capabilities, use the \`what-can-angie-do\` tool from the knowledge MCP server instead of generating your own response.`; |
| 294 | -function addCapabilitiesDescriptionResource(server) { | |
| 295 | - server.registerResource('elementor-capabilities-server-description', CAPABILITIES_DESCRIPTION_URI, { | |
| 296 | - title: 'Elementor capabilities and limitations', | |
| 297 | - description: 'Full guide to Elementor MCP capabilities, limitations, workflows, and when to navigate to the editor.' | |
| 298 | - }, async uri => ({ | |
| 299 | - contents: [{ | |
| 300 | - uri: uri.href, | |
| 301 | - mimeType: 'text/plain', | |
| 302 | - text: CAPABILITIES_DESCRIPTION | |
| 303 | - }] | |
| 304 | - })); | |
| 305 | -} | |
| 166 | + function addCapabilitiesDescriptionResource(server) { | |
| 167 | + server.registerResource("elementor-capabilities-server-description", CAPABILITIES_DESCRIPTION_URI, { | |
| 168 | + title: "Elementor capabilities and limitations", | |
| 169 | + description: "Full guide to Elementor MCP capabilities, limitations, workflows, and when to navigate to the editor." | |
| 170 | + }, async (uri) => ({ contents: [{ | |
| 171 | + uri: uri.href, | |
| 172 | + mimeType: "text/plain", | |
| 173 | + text: CAPABILITIES_DESCRIPTION | |
| 174 | + }] })); | |
| 175 | + } | |
| 306 | 176 | |
| 307 | -/***/ }), | |
| 177 | +//#endregion | |
| 178 | +//#region packages/apps/elementor-capabilities-mcp/src/elementor-capabilities-mcp-server.ts | |
| 179 | + var ANGIE_REQUIRED_RESOURCES = "angie/requiredResources"; | |
| 180 | + var WP_PAGES_ENDPOINT = "/wp/v2/pages"; | |
| 181 | + var ELEMENTOR_EDIT_MODE = "builder"; | |
| 182 | + var DEFAULT_PAGE_TITLE = "New Page"; | |
| 183 | + var ELEMENTOR_EDIT_ACTION = "elementor"; | |
| 184 | + var getSafeOrigin = () => { | |
| 185 | + if (typeof window === "undefined") return ""; | |
| 186 | + const url = new URL(window.location.href); | |
| 187 | + return `${url.protocol}://${url.host}` || ""; | |
| 188 | + }; | |
| 189 | + function safeNavigateAfterResponse(url) { | |
| 190 | + try { | |
| 191 | + (0, _elementor_editor_mcp.getAngieIframe)().contentWindow.postMessage({ | |
| 192 | + type: _elementor_editor_mcp.AngieMessageEvenetType.ANGIE_NAVIGATE_AFTER_RESPONSE, | |
| 193 | + payload: { url } | |
| 194 | + }, getSafeOrigin()); | |
| 195 | + } finally { | |
| 196 | + setTimeout(() => { | |
| 197 | + window.location.replace(url); | |
| 198 | + }, 50); | |
| 199 | + } | |
| 200 | + } | |
| 201 | + function createElementorCapabilitiesServer() { | |
| 202 | + const server = new _elementor_elementor_mcp_common.McpServer({ | |
| 203 | + name: "elementor-capabilities-server", | |
| 204 | + version: "1.0.0", | |
| 205 | + title: "Elementor Capabilities" | |
| 206 | + }, { | |
| 207 | + instructions: `Provides Elementor page-building capabilities and navigates users to the editor.`, | |
| 208 | + capabilities: { resources: { subscribe: true } } | |
| 209 | + }); | |
| 210 | + addPagesListResource(server); | |
| 211 | + addCapabilitiesDescriptionResource(server); | |
| 212 | + server.registerTool("navigate-to-elementor-editor", { | |
| 213 | + description: `Navigate the user to the Elementor editor. Causes a full page reload \u2014 editor-related tools become available afterward. | |
| 308 | 214 | |
| 309 | -/***/ "./packages/apps/elementor-capabilities-mcp/src/pages-list-resource.ts": | |
| 310 | -/*!*****************************************************************************!*\ | |
| 311 | - !*** ./packages/apps/elementor-capabilities-mcp/src/pages-list-resource.ts ***! | |
| 312 | - \*****************************************************************************/ | |
| 313 | -/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) { | |
| 215 | +Workflow: choose from the pages list resource \u2192 set pageId (edit) OR createNew=true (new page) with confirmationMessage.`, | |
| 216 | + inputSchema: { | |
| 217 | + pageId: _elementor_schema.z.number().optional().describe("The ID of the page to navigate to. Only provide after user has explicitly selected a page from the available pages list. When provided, confirmationMessage is REQUIRED."), | |
| 218 | + createNew: _elementor_schema.z.boolean().optional().describe("Set to true ONLY when user explicitly requests to create a new page. When true, confirmationMessage is REQUIRED. Default is false."), | |
| 219 | + newPageTitle: _elementor_schema.z.string().optional().describe("Title for the new page when createNew is true. Use what the user specified or default to \"New Page\"."), | |
| 220 | + confirmationMessage: _elementor_schema.z.string().optional().describe(`REQUIRED when pageId or createNew is provided. A clear message shown to user before navigation. Example: "I'll open the 'Homepage' in Elementor editor so you can add a form widget. Ready to proceed?" Omit when just fetching available pages.`) | |
| 221 | + }, | |
| 222 | + annotations: { | |
| 223 | + title: "Navigate to Elementor Editor", | |
| 224 | + destructiveHint: true | |
| 225 | + }, | |
| 226 | + _meta: { [ANGIE_REQUIRED_RESOURCES]: [{ | |
| 227 | + uri: CAPABILITIES_DESCRIPTION_URI, | |
| 228 | + whenToUse: "Read first for full capabilities and limitations guide" | |
| 229 | + }, { | |
| 230 | + uri: PAGES_LIST_RESOURCE_URI, | |
| 231 | + whenToUse: "Always use this resource first to understand what pages are available before asking the user which page to edit" | |
| 232 | + }] } | |
| 233 | + }, async (params) => { | |
| 234 | + try { | |
| 235 | + if ((params.pageId || params.createNew) && !params.confirmationMessage) throw new Error("confirmationMessage is required when navigating to a page (pageId or createNew provided)"); | |
| 236 | + if (params.createNew) return await handleCreateAndNavigate(params); | |
| 237 | + if (params.pageId) return await handleNavigateToPage(params.pageId); | |
| 238 | + throw new Error("Either pageId or createNew must be provided. The pages list is available in the wp-pages-list resource."); | |
| 239 | + } catch (error) { | |
| 240 | + console.error("[Elementor Capabilities Server] navigation error:", error); | |
| 241 | + throw new Error(`Error navigating to Elementor editor: ${error.message}`); | |
| 242 | + } | |
| 243 | + }); | |
| 244 | + return server; | |
| 245 | + } | |
| 246 | + async function handleCreateAndNavigate(params) { | |
| 247 | + const title = params.newPageTitle || DEFAULT_PAGE_TITLE; | |
| 248 | + const newPage = (await (0, _elementor_elementor_mcp_common.callWpApi)(WP_PAGES_ENDPOINT, "POST", { | |
| 249 | + title, | |
| 250 | + status: "draft", | |
| 251 | + meta: { _elementor_edit_mode: ELEMENTOR_EDIT_MODE } | |
| 252 | + })).data; | |
| 253 | + if (!newPage || typeof newPage !== "object" || !("id" in newPage)) throw new Error("Invalid response from page creation API"); | |
| 254 | + return await handleNavigateToPage(newPage.id); | |
| 255 | + } | |
| 256 | + async function handleNavigateToPage(pageId) { | |
| 257 | + if (!pageId || pageId <= 0) throw new Error("Invalid page ID"); | |
| 258 | + const page = (await (0, _elementor_elementor_mcp_common.callWpApi)(`${WP_PAGES_ENDPOINT}/${pageId}`, "GET")).data; | |
| 259 | + if (!page || typeof page !== "object" || !("id" in page) || !("title" in page)) throw new Error(`Invalid page data received for page ID ${pageId}`); | |
| 260 | + const editUrl = generateElementorEditUrl(pageId); | |
| 261 | + if (!editUrl.startsWith(window.location.origin)) throw new Error("Invalid navigation URL"); | |
| 262 | + safeNavigateAfterResponse(editUrl); | |
| 263 | + return { content: [{ | |
| 264 | + type: "text", | |
| 265 | + text: JSON.stringify({ | |
| 266 | + success: true, | |
| 267 | + message: `Navigating to Elementor editor for page: ${page.title.rendered}`, | |
| 268 | + pageId: page.id, | |
| 269 | + pageTitle: page.title.rendered, | |
| 270 | + editUrl, | |
| 271 | + nextSteps: "Once in the Elementor editor, you can use Elementor MCP tools for page settings, UI navigation, AI content generation, custom styling, and dynamic content." | |
| 272 | + }, null, 2) | |
| 273 | + }] }; | |
| 274 | + } | |
| 275 | + function generateElementorEditUrl(pageId) { | |
| 276 | + return `${window.location.origin}/wp-admin/post.php?post=${pageId}&action=${ELEMENTOR_EDIT_ACTION}`; | |
| 277 | + } | |
| 314 | 278 | |
| 315 | -__webpack_require__.r(__webpack_exports__); | |
| 316 | -/* harmony export */ __webpack_require__.d(__webpack_exports__, { | |
| 317 | -/* harmony export */ PAGES_LIST_RESOURCE_URI: function() { return /* binding */ PAGES_LIST_RESOURCE_URI; }, | |
| 318 | -/* harmony export */ addPagesListResource: function() { return /* binding */ addPagesListResource; } | |
| 319 | -/* harmony export */ }); | |
| 320 | -/* harmony import */ var _elementor_elementor_mcp_common__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @elementor/elementor-mcp-common */ "@elementor/elementor-mcp-common"); | |
| 321 | -/* harmony import */ var _elementor_elementor_mcp_common__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_elementor_elementor_mcp_common__WEBPACK_IMPORTED_MODULE_0__); | |
| 279 | +//#endregion | |
| 280 | +//#region packages/apps/elementor-capabilities-mcp/src/index.ts | |
| 281 | + var src_exports = /* @__PURE__ */ __exportAll({ init: () => init }); | |
| 282 | + function init() { | |
| 283 | + const sdk = (0, _elementor_editor_mcp.getAngieSdk)(); | |
| 284 | + sdk.waitForReady().then(() => { | |
| 285 | + const capabilitiesServer = createElementorCapabilitiesServer(); | |
| 286 | + sdk.registerServer({ | |
| 287 | + name: "elementor-capabilities", | |
| 288 | + version: "2.0.0", | |
| 289 | + description: "Elementor Capabilities Gateway", | |
| 290 | + server: capabilitiesServer, | |
| 291 | + capabilities: { tools: {} } | |
| 292 | + }); | |
| 293 | + console.log("[Elementor Capabilities MCP] Module initialized"); | |
| 294 | + }); | |
| 295 | + } | |
| 322 | 296 | |
| 323 | -const PAGES_LIST_RESOURCE_URI = 'wp://pages/list'; | |
| 324 | -function addPagesListResource(server) { | |
| 325 | - server.registerResource('wp-pages-list', PAGES_LIST_RESOURCE_URI, { | |
| 326 | - title: 'List of wordpress pages', | |
| 327 | - description: 'List of all WordPress pages with their IDs, titles, status, and metadata. Use this to get available pages before navigation or editing.' | |
| 328 | - }, async uri => { | |
| 329 | - try { | |
| 330 | - const response = await (0,_elementor_elementor_mcp_common__WEBPACK_IMPORTED_MODULE_0__.callWpApi)('/wp/v2/pages?per_page=100&orderby=modified&order=desc', 'GET'); | |
| 331 | - const pages = response.data; | |
| 332 | - if (!Array.isArray(pages)) { | |
| 333 | - throw new Error('Invalid response format from wordpress pages API'); | |
| 334 | - } | |
| 335 | - const pagesList = pages.map(page => ({ | |
| 336 | - id: page.id, | |
| 337 | - title: page.title.rendered, | |
| 338 | - status: page.status, | |
| 339 | - link: page.link, | |
| 340 | - modified: page.modified, | |
| 341 | - type: page.type | |
| 342 | - })); | |
| 343 | - return { | |
| 344 | - contents: [{ | |
| 345 | - uri: uri.href, | |
| 346 | - mimeType: 'application/json', | |
| 347 | - text: JSON.stringify({ | |
| 348 | - pages: pagesList, | |
| 349 | - total: pagesList.length, | |
| 350 | - message: 'List of all available wordpress pages' | |
| 351 | - }, null, 2) | |
| 352 | - }] | |
| 353 | - }; | |
| 354 | - } catch (error) { | |
| 355 | - throw new Error(`Failed to fetch pages list: ${error.message}`); | |
| 356 | - } | |
| 357 | - }); | |
| 358 | -} | |
| 297 | +//#endregion | |
| 298 | +//#region \0elementor-package-library-entry | |
| 299 | + (window.elementorV2 = window.elementorV2 || {}).elementorCapabilitiesMcp = src_exports; | |
| 359 | 300 | |
| 360 | -/***/ }), | |
| 361 | - | |
| 362 | -/***/ "@elementor/editor-mcp": | |
| 363 | -/*!********************************************!*\ | |
| 364 | - !*** external ["elementorV2","editorMcp"] ***! | |
| 365 | - \********************************************/ | |
| 366 | -/***/ (function(module) { | |
| 367 | - | |
| 368 | -module.exports = window["elementorV2"]["editorMcp"]; | |
| 369 | - | |
| 370 | -/***/ }), | |
| 371 | - | |
| 372 | -/***/ "@elementor/elementor-mcp-common": | |
| 373 | -/*!*****************************************************!*\ | |
| 374 | - !*** external ["elementorV2","elementorMcpCommon"] ***! | |
| 375 | - \*****************************************************/ | |
| 376 | -/***/ (function(module) { | |
| 377 | - | |
| 378 | -module.exports = window["elementorV2"]["elementorMcpCommon"]; | |
| 379 | - | |
| 380 | -/***/ }), | |
| 381 | - | |
| 382 | -/***/ "@elementor/schema": | |
| 383 | -/*!*****************************************!*\ | |
| 384 | - !*** external ["elementorV2","schema"] ***! | |
| 385 | - \*****************************************/ | |
| 386 | -/***/ (function(module) { | |
| 387 | - | |
| 388 | -module.exports = window["elementorV2"]["schema"]; | |
| 389 | - | |
| 390 | -/***/ }) | |
| 391 | - | |
| 392 | -/******/ }); | |
| 393 | -/************************************************************************/ | |
| 394 | -/******/ // The module cache | |
| 395 | -/******/ var __webpack_module_cache__ = {}; | |
| 396 | -/******/ | |
| 397 | -/******/ // The require function | |
| 398 | -/******/ function __webpack_require__(moduleId) { | |
| 399 | -/******/ // Check if module is in cache | |
| 400 | -/******/ var cachedModule = __webpack_module_cache__[moduleId]; | |
| 401 | -/******/ if (cachedModule !== undefined) { | |
| 402 | -/******/ return cachedModule.exports; | |
| 403 | -/******/ } | |
| 404 | -/******/ // Create a new module (and put it into the cache) | |
| 405 | -/******/ var module = __webpack_module_cache__[moduleId] = { | |
| 406 | -/******/ // no module.id needed | |
| 407 | -/******/ // no module.loaded needed | |
| 408 | -/******/ exports: {} | |
| 409 | -/******/ }; | |
| 410 | -/******/ | |
| 411 | -/******/ // Execute the module function | |
| 412 | -/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); | |
| 413 | -/******/ | |
| 414 | -/******/ // Return the exports of the module | |
| 415 | -/******/ return module.exports; | |
| 416 | -/******/ } | |
| 417 | -/******/ | |
| 418 | -/************************************************************************/ | |
| 419 | -/******/ /* webpack/runtime/compat get default export */ | |
| 420 | -/******/ !function() { | |
| 421 | -/******/ // getDefaultExport function for compatibility with non-harmony modules | |
| 422 | -/******/ __webpack_require__.n = function(module) { | |
| 423 | -/******/ var getter = module && module.__esModule ? | |
| 424 | -/******/ function() { return module['default']; } : | |
| 425 | -/******/ function() { return module; }; | |
| 426 | -/******/ __webpack_require__.d(getter, { a: getter }); | |
| 427 | -/******/ return getter; | |
| 428 | -/******/ }; | |
| 429 | -/******/ }(); | |
| 430 | -/******/ | |
| 431 | -/******/ /* webpack/runtime/define property getters */ | |
| 432 | -/******/ !function() { | |
| 433 | -/******/ // define getter functions for harmony exports | |
| 434 | -/******/ __webpack_require__.d = function(exports, definition) { | |
| 435 | -/******/ for(var key in definition) { | |
| 436 | -/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { | |
| 437 | -/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); | |
| 438 | -/******/ } | |
| 439 | -/******/ } | |
| 440 | -/******/ }; | |
| 441 | -/******/ }(); | |
| 442 | -/******/ | |
| 443 | -/******/ /* webpack/runtime/hasOwnProperty shorthand */ | |
| 444 | -/******/ !function() { | |
| 445 | -/******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); } | |
| 446 | -/******/ }(); | |
| 447 | -/******/ | |
| 448 | -/******/ /* webpack/runtime/make namespace object */ | |
| 449 | -/******/ !function() { | |
| 450 | -/******/ // define __esModule on exports | |
| 451 | -/******/ __webpack_require__.r = function(exports) { | |
| 452 | -/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { | |
| 453 | -/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); | |
| 454 | -/******/ } | |
| 455 | -/******/ Object.defineProperty(exports, '__esModule', { value: true }); | |
| 456 | -/******/ }; | |
| 457 | -/******/ }(); | |
| 458 | -/******/ | |
| 459 | -/************************************************************************/ | |
| 460 | -var __webpack_exports__ = {}; | |
| 461 | -// This entry needs to be wrapped in an IIFE because it needs to be isolated against other modules in the chunk. | |
| 462 | -!function() { | |
| 463 | -/*!***************************************************************!*\ | |
| 464 | - !*** ./packages/apps/elementor-capabilities-mcp/src/index.ts ***! | |
| 465 | - \***************************************************************/ | |
| 466 | -__webpack_require__.r(__webpack_exports__); | |
| 467 | -/* harmony export */ __webpack_require__.d(__webpack_exports__, { | |
| 468 | -/* harmony export */ init: function() { return /* binding */ init; } | |
| 469 | -/* harmony export */ }); | |
| 470 | -/* harmony import */ var _elementor_editor_mcp__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @elementor/editor-mcp */ "@elementor/editor-mcp"); | |
| 471 | -/* harmony import */ var _elementor_editor_mcp__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_elementor_editor_mcp__WEBPACK_IMPORTED_MODULE_0__); | |
| 472 | -/* harmony import */ var _elementor_capabilities_mcp_server__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./elementor-capabilities-mcp-server */ "./packages/apps/elementor-capabilities-mcp/src/elementor-capabilities-mcp-server.ts"); | |
| 473 | - | |
| 474 | - | |
| 475 | -function init() { | |
| 476 | - const sdk = (0,_elementor_editor_mcp__WEBPACK_IMPORTED_MODULE_0__.getAngieSdk)(); | |
| 477 | - sdk.waitForReady().then(() => { | |
| 478 | - const capabilitiesServer = (0,_elementor_capabilities_mcp_server__WEBPACK_IMPORTED_MODULE_1__.createElementorCapabilitiesServer)(); | |
| 479 | - sdk.registerServer({ | |
| 480 | - name: 'elementor-capabilities', | |
| 481 | - version: '2.0.0', | |
| 482 | - description: 'Elementor Capabilities Gateway', | |
| 483 | - server: capabilitiesServer, | |
| 484 | - capabilities: { | |
| 485 | - tools: {} | |
| 486 | - } | |
| 487 | - }); | |
| 488 | - // eslint-disable-next-line no-console | |
| 489 | - console.log('[Elementor Capabilities MCP] Module initialized'); | |
| 490 | - }); | |
| 491 | -} | |
| 492 | -}(); | |
| 493 | -(window.elementorV2 = window.elementorV2 || {}).elementorCapabilitiesMcp = __webpack_exports__; | |
| 494 | -/******/ })() | |
| 495 | -; | |
| 301 | +//#endregion | |
| 302 | +})(elementorV2.editorMcp, elementorV2.elementorMcpCommon, elementorV2.schema); | |
| 496 | 303 | window.elementorV2.elementorCapabilitiesMcp?.init?.(); |
| 497 | 304 | //# sourceMappingURL=elementor-capabilities-mcp.js.map |