@yashwant.dharmdas/elementor-mcp 3.17.0 → 3.18.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +64 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3,6 +3,8 @@ import AjvModule from "ajv";
|
|
|
3
3
|
const Ajv = AjvModule.default || AjvModule;
|
|
4
4
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
5
5
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
6
|
+
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
|
|
7
|
+
import { createServer } from "node:http";
|
|
6
8
|
import { z } from "zod";
|
|
7
9
|
import axios from "axios";
|
|
8
10
|
import fs from "fs";
|
|
@@ -4105,7 +4107,66 @@ else {
|
|
|
4105
4107
|
console.error("No sites configured. Run first: npx elementor-mcp setup");
|
|
4106
4108
|
process.exit(1);
|
|
4107
4109
|
}
|
|
4108
|
-
|
|
4109
|
-
|
|
4110
|
-
|
|
4110
|
+
// Auto-detect transport:
|
|
4111
|
+
// • No TTY (spawned by Claude Desktop via pipe) → stdio, unless --http forces HTTP
|
|
4112
|
+
// • TTY present (user ran manually in terminal) → HTTP, unless --stdio forces stdio
|
|
4113
|
+
const forceStdio = process.argv.includes("--stdio");
|
|
4114
|
+
const forceHttp = process.argv.includes("--http");
|
|
4115
|
+
const hasTTY = Boolean(process.stdin.isTTY);
|
|
4116
|
+
const useHttp = forceHttp || (!forceStdio && hasTTY);
|
|
4117
|
+
if (!useHttp) {
|
|
4118
|
+
// ── Stdio mode — for Claude Desktop (or --stdio flag) ────────────────
|
|
4119
|
+
const server = createMcpServer(sites);
|
|
4120
|
+
const transport = new StdioServerTransport();
|
|
4121
|
+
await server.connect(transport);
|
|
4122
|
+
}
|
|
4123
|
+
else {
|
|
4124
|
+
// ── HTTP mode — for browser-based MCP testers (or --http flag) ───────
|
|
4125
|
+
const port = parseInt(process.env.PORT ?? "3001");
|
|
4126
|
+
const mcpServer = createMcpServer(sites);
|
|
4127
|
+
const transport = new StreamableHTTPServerTransport({ sessionIdGenerator: undefined });
|
|
4128
|
+
await mcpServer.connect(transport);
|
|
4129
|
+
const httpServer = createServer(async (req, res) => {
|
|
4130
|
+
// CORS — allow browser clients and Chrome Private Network Access
|
|
4131
|
+
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
4132
|
+
res.setHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, OPTIONS");
|
|
4133
|
+
res.setHeader("Access-Control-Allow-Headers", "Content-Type, mcp-session-id");
|
|
4134
|
+
res.setHeader("Access-Control-Allow-Private-Network", "true");
|
|
4135
|
+
if (req.method === "OPTIONS") {
|
|
4136
|
+
res.writeHead(204);
|
|
4137
|
+
res.end();
|
|
4138
|
+
return;
|
|
4139
|
+
}
|
|
4140
|
+
if (req.url === "/health") {
|
|
4141
|
+
res.writeHead(200, { "Content-Type": "application/json" });
|
|
4142
|
+
res.end(JSON.stringify({ status: "ok", sites: sites.map((s) => s.name) }));
|
|
4143
|
+
return;
|
|
4144
|
+
}
|
|
4145
|
+
if (req.url === "/mcp") {
|
|
4146
|
+
let body;
|
|
4147
|
+
if (req.method === "POST") {
|
|
4148
|
+
const chunks = [];
|
|
4149
|
+
await new Promise((resolve, reject) => {
|
|
4150
|
+
req.on("data", (c) => chunks.push(c));
|
|
4151
|
+
req.on("end", resolve);
|
|
4152
|
+
req.on("error", reject);
|
|
4153
|
+
});
|
|
4154
|
+
try {
|
|
4155
|
+
body = JSON.parse(Buffer.concat(chunks).toString());
|
|
4156
|
+
}
|
|
4157
|
+
catch { /* non-JSON body */ }
|
|
4158
|
+
}
|
|
4159
|
+
await transport.handleRequest(req, res, body);
|
|
4160
|
+
return;
|
|
4161
|
+
}
|
|
4162
|
+
res.writeHead(404);
|
|
4163
|
+
res.end("Not found");
|
|
4164
|
+
});
|
|
4165
|
+
httpServer.listen(port, () => {
|
|
4166
|
+
console.log(`Elementor MCP HTTP server listening on port ${port}`);
|
|
4167
|
+
console.log(`MCP endpoint: http://localhost:${port}/mcp`);
|
|
4168
|
+
console.log(`Health check: http://localhost:${port}/health`);
|
|
4169
|
+
console.log(`Sites loaded: ${sites.map((s) => s.name).join(", ")}`);
|
|
4170
|
+
});
|
|
4171
|
+
}
|
|
4111
4172
|
}
|
package/package.json
CHANGED