bricks-builder-mcp 3.1.0
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/README.md +70 -0
- package/package.json +33 -0
- package/server.js +512 -0
package/README.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# Bricks Builder MCP
|
|
2
|
+
|
|
3
|
+
Serveur **Model Context Protocol (MCP)** qui permet à Claude (Desktop, Cowork, Claude Code) de piloter **Bricks Builder** sur un site WordPress : lister les pages, lire/modifier le JSON Bricks, ajouter ou réorganiser des sections, etc.
|
|
4
|
+
|
|
5
|
+
## Architecture
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
Claude (Desktop / Cowork)
|
|
9
|
+
↓ MCP (stdio)
|
|
10
|
+
bricks-builder-mcp (ce package)
|
|
11
|
+
↓ HTTPS + X-API-Key
|
|
12
|
+
WordPress + plugin "Bricks Builder MCP Server"
|
|
13
|
+
↓
|
|
14
|
+
Pages Bricks Builder
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
### Prérequis côté WordPress
|
|
20
|
+
|
|
21
|
+
Le plugin compagnon **Bricks Builder MCP Server** doit être installé et activé sur le WordPress cible. Il expose les endpoints REST `/wp-json/bricks-mcp/v2/*` et permet de générer la clé API.
|
|
22
|
+
|
|
23
|
+
### Configuration côté Claude
|
|
24
|
+
|
|
25
|
+
Ajoute dans le fichier de configuration Claude (`claude_desktop_config.json` ou équivalent) :
|
|
26
|
+
|
|
27
|
+
```json
|
|
28
|
+
{
|
|
29
|
+
"mcpServers": {
|
|
30
|
+
"bricks-mcp": {
|
|
31
|
+
"command": "npx",
|
|
32
|
+
"args": ["-y", "bricks-builder-mcp"],
|
|
33
|
+
"env": {
|
|
34
|
+
"WORDPRESS_URL": "https://exemple-de-site.com",
|
|
35
|
+
"API_KEY": "bricks_xxxxxxxx"
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Redémarre Claude. C'est tout.
|
|
43
|
+
|
|
44
|
+
## Variables d'environnement
|
|
45
|
+
|
|
46
|
+
| Variable | Requis | Description |
|
|
47
|
+
|---|---|---|
|
|
48
|
+
| `WORDPRESS_URL` | oui | URL racine du site WordPress (ex : `https://exemple.com`) |
|
|
49
|
+
| `API_KEY` | oui | Clé API générée dans les réglages du plugin WordPress |
|
|
50
|
+
|
|
51
|
+
## Outils MCP exposés
|
|
52
|
+
|
|
53
|
+
| Outil | Description |
|
|
54
|
+
|---|---|
|
|
55
|
+
| `list_bricks_pages` | Liste toutes les pages Bricks |
|
|
56
|
+
| `get_page_json` | Récupère le JSON complet d'une page |
|
|
57
|
+
| `update_page_json` | Sauvegarde le JSON complet d'une page |
|
|
58
|
+
| `analyze_json_structure` | Analyse la structure d'un JSON Bricks |
|
|
59
|
+
| `get_page_structure` | Vue d'ensemble légère (économe en tokens) |
|
|
60
|
+
| `find_elements` | Recherche d'éléments par critères |
|
|
61
|
+
| `get_element` | Récupère un élément précis |
|
|
62
|
+
| `update_element` | Modifie un élément précis |
|
|
63
|
+
| `add_element` | Ajoute un élément |
|
|
64
|
+
| `batch_add` | Ajoute plusieurs éléments en une fois |
|
|
65
|
+
| `delete_element` | Supprime un élément |
|
|
66
|
+
| `reorder_sections` | Réorganise l'ordre des sections (header en haut, footer en bas) |
|
|
67
|
+
|
|
68
|
+
## Licence
|
|
69
|
+
|
|
70
|
+
MIT
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"type": "module",
|
|
3
|
+
"name": "bricks-builder-mcp",
|
|
4
|
+
"version": "3.1.0",
|
|
5
|
+
"description": "Serveur MCP pour piloter Bricks Builder (WordPress) depuis Claude — édition de pages, gestion d'éléments, réordonnancement des sections.",
|
|
6
|
+
"main": "server.js",
|
|
7
|
+
"bin": {
|
|
8
|
+
"bricks-builder-mcp": "./server.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"server.js",
|
|
12
|
+
"README.md"
|
|
13
|
+
],
|
|
14
|
+
"scripts": {
|
|
15
|
+
"start": "node server.js",
|
|
16
|
+
"test": "echo \"No tests yet\" && exit 0"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"mcp",
|
|
20
|
+
"bricks-builder",
|
|
21
|
+
"wordpress",
|
|
22
|
+
"claude",
|
|
23
|
+
"model-context-protocol"
|
|
24
|
+
],
|
|
25
|
+
"author": "Mathieu Maap <mathieu.maap@gmail.com>",
|
|
26
|
+
"license": "MIT",
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": ">=18"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@modelcontextprotocol/sdk": "^1.23.0"
|
|
32
|
+
}
|
|
33
|
+
}
|
package/server.js
ADDED
|
@@ -0,0 +1,512 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
4
|
+
import {
|
|
5
|
+
ListToolsRequestSchema,
|
|
6
|
+
CallToolRequestSchema,
|
|
7
|
+
} from "@modelcontextprotocol/sdk/types.js";
|
|
8
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
9
|
+
import fs from 'fs';
|
|
10
|
+
import { fileURLToPath } from 'url';
|
|
11
|
+
import { dirname, join } from 'path';
|
|
12
|
+
|
|
13
|
+
// Configuration du fichier de log
|
|
14
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
15
|
+
const __dirname = dirname(__filename);
|
|
16
|
+
const LOG_FILE = join(__dirname, 'bricks-mcp-debug.log');
|
|
17
|
+
|
|
18
|
+
function logToFile(message) {
|
|
19
|
+
const timestamp = new Date().toISOString();
|
|
20
|
+
const logMessage = `[${timestamp}] ${message}\n`;
|
|
21
|
+
try {
|
|
22
|
+
fs.appendFileSync(LOG_FILE, logMessage);
|
|
23
|
+
} catch (err) {
|
|
24
|
+
// Ignorer les erreurs de log
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Remplacer console.error
|
|
29
|
+
const originalConsoleError = console.error;
|
|
30
|
+
console.error = (...args) => {
|
|
31
|
+
const message = args.map(arg =>
|
|
32
|
+
typeof arg === 'object' ? JSON.stringify(arg, null, 2) : String(arg)
|
|
33
|
+
).join(' ');
|
|
34
|
+
logToFile(message);
|
|
35
|
+
originalConsoleError(...args);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
logToFile('========================================');
|
|
39
|
+
logToFile('DÉMARRAGE BRICKS MCP SERVER v3.0');
|
|
40
|
+
logToFile('========================================');
|
|
41
|
+
|
|
42
|
+
// Configuration WordPress
|
|
43
|
+
// Priorité : variables d'environnement > valeurs par défaut (ancien site, pour compatibilité)
|
|
44
|
+
const WORDPRESS_URL = process.env.WORDPRESS_URL || "https://aidetravauxfibre0002.live-website.com";
|
|
45
|
+
const API_KEY = process.env.API_KEY || "bricks_syectnbripq";
|
|
46
|
+
const API_ENDPOINT = `${WORDPRESS_URL}/wp-json/bricks-mcp/v2`;
|
|
47
|
+
|
|
48
|
+
logToFile(`[CONFIG] WORDPRESS_URL = ${WORDPRESS_URL}`);
|
|
49
|
+
logToFile(`[CONFIG] API_KEY = ${API_KEY ? API_KEY.substring(0, 10) + '...' : 'NON DÉFINIE'}`);
|
|
50
|
+
|
|
51
|
+
if (!process.env.WORDPRESS_URL || !process.env.API_KEY) {
|
|
52
|
+
logToFile('[WARN] WORDPRESS_URL ou API_KEY non définies dans l\'environnement, utilisation des valeurs par défaut');
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const mcpServer = new Server(
|
|
56
|
+
{
|
|
57
|
+
name: "bricks-mcp-v3",
|
|
58
|
+
version: "3.0.0",
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
capabilities: {
|
|
62
|
+
tools: {},
|
|
63
|
+
},
|
|
64
|
+
}
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
// Fonction pour appeler l'API WordPress
|
|
68
|
+
async function callWordPressAPI(endpoint, method = "GET", body = null) {
|
|
69
|
+
const options = {
|
|
70
|
+
method,
|
|
71
|
+
headers: {
|
|
72
|
+
"Content-Type": "application/json",
|
|
73
|
+
"X-API-Key": API_KEY,
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
if (body) {
|
|
78
|
+
options.body = JSON.stringify(body);
|
|
79
|
+
console.error(`[LOG] Envoi vers ${endpoint}:`, JSON.stringify(body, null, 2));
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
try {
|
|
83
|
+
const response = await fetch(`${API_ENDPOINT}${endpoint}`, options);
|
|
84
|
+
console.error(`[LOG] Réponse status: ${response.status}`);
|
|
85
|
+
|
|
86
|
+
if (!response.ok) {
|
|
87
|
+
const errorText = await response.text();
|
|
88
|
+
console.error(`[LOG] Erreur API: ${errorText}`);
|
|
89
|
+
throw new Error(`API Error: ${response.statusText}`);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const data = await response.json();
|
|
93
|
+
console.error(`[LOG] Réponse reçue:`, JSON.stringify(data, null, 2));
|
|
94
|
+
return data;
|
|
95
|
+
} catch (error) {
|
|
96
|
+
console.error(`[LOG] Exception:`, error.message);
|
|
97
|
+
throw new Error(`Erreur API: ${error.message}`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Définir les tools disponibles
|
|
102
|
+
mcpServer.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
103
|
+
return {
|
|
104
|
+
tools: [
|
|
105
|
+
// ===== OUTILS EXISTANTS (compatibilité) =====
|
|
106
|
+
{
|
|
107
|
+
name: "list_bricks_pages",
|
|
108
|
+
description: "Liste toutes les pages Bricks Builder du site.",
|
|
109
|
+
inputSchema: {
|
|
110
|
+
type: "object",
|
|
111
|
+
properties: {},
|
|
112
|
+
required: [],
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
name: "get_page_json",
|
|
117
|
+
description: "Récupère le JSON COMPLET d'une page. Utilise ceci pour les gros travaux ou refonte complète.",
|
|
118
|
+
inputSchema: {
|
|
119
|
+
type: "object",
|
|
120
|
+
properties: {
|
|
121
|
+
pageId: {
|
|
122
|
+
type: "number",
|
|
123
|
+
description: "L'ID de la page WordPress",
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
required: ["pageId"],
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
name: "update_page_json",
|
|
131
|
+
description: "Sauvegarde le JSON COMPLET d'une page. Utilise ceci après get_page_json pour grosse refonte.",
|
|
132
|
+
inputSchema: {
|
|
133
|
+
type: "object",
|
|
134
|
+
properties: {
|
|
135
|
+
pageId: {
|
|
136
|
+
type: "number",
|
|
137
|
+
description: "L'ID de la page",
|
|
138
|
+
},
|
|
139
|
+
newJsonData: {
|
|
140
|
+
type: "array",
|
|
141
|
+
description: "Le JSON complet (TABLEAU)",
|
|
142
|
+
items: {
|
|
143
|
+
type: "object",
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
},
|
|
147
|
+
required: ["pageId", "newJsonData"],
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
name: "analyze_json_structure",
|
|
152
|
+
description: "Analyse la structure d'un JSON Bricks.",
|
|
153
|
+
inputSchema: {
|
|
154
|
+
type: "object",
|
|
155
|
+
properties: {
|
|
156
|
+
jsonData: {
|
|
157
|
+
type: ["object", "array", "string"],
|
|
158
|
+
description: "Le JSON à analyser",
|
|
159
|
+
},
|
|
160
|
+
},
|
|
161
|
+
required: ["jsonData"],
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
|
|
165
|
+
// ===== OUTILS v2.0 (OPTIMISÉS) =====
|
|
166
|
+
|
|
167
|
+
{
|
|
168
|
+
name: "get_page_structure",
|
|
169
|
+
description: "Récupère une VUE D'ENSEMBLE LÉGÈRE de la page (juste id, name, parent, children, aperçu texte). Économise 80% de tokens vs get_page_json. Utilise pour comprendre la structure sans charger tous les détails.",
|
|
170
|
+
inputSchema: {
|
|
171
|
+
type: "object",
|
|
172
|
+
properties: {
|
|
173
|
+
pageId: {
|
|
174
|
+
type: "number",
|
|
175
|
+
description: "L'ID de la page",
|
|
176
|
+
},
|
|
177
|
+
},
|
|
178
|
+
required: ["pageId"],
|
|
179
|
+
},
|
|
180
|
+
},
|
|
181
|
+
|
|
182
|
+
{
|
|
183
|
+
name: "find_elements",
|
|
184
|
+
description: "Trouve des éléments par CRITÈRES sans charger toute la page. Très économe en tokens. Utilise pour chercher des boutons, headings, sections spécifiques, etc.",
|
|
185
|
+
inputSchema: {
|
|
186
|
+
type: "object",
|
|
187
|
+
properties: {
|
|
188
|
+
pageId: {
|
|
189
|
+
type: "number",
|
|
190
|
+
description: "L'ID de la page",
|
|
191
|
+
},
|
|
192
|
+
criteria: {
|
|
193
|
+
type: "object",
|
|
194
|
+
description: "Critères de recherche",
|
|
195
|
+
properties: {
|
|
196
|
+
type: {
|
|
197
|
+
type: "string",
|
|
198
|
+
description: "Type d'élément : heading, button, section, container, etc."
|
|
199
|
+
},
|
|
200
|
+
parent: {
|
|
201
|
+
type: "string",
|
|
202
|
+
description: "ID du parent"
|
|
203
|
+
},
|
|
204
|
+
hasText: {
|
|
205
|
+
type: "string",
|
|
206
|
+
description: "Texte contenu dans l'élément"
|
|
207
|
+
},
|
|
208
|
+
className: {
|
|
209
|
+
type: "string",
|
|
210
|
+
description: "Classe CSS de l'élément"
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
},
|
|
214
|
+
limit: {
|
|
215
|
+
type: "number",
|
|
216
|
+
description: "Nombre max de résultats (défaut: 100)",
|
|
217
|
+
},
|
|
218
|
+
},
|
|
219
|
+
required: ["pageId"],
|
|
220
|
+
},
|
|
221
|
+
},
|
|
222
|
+
|
|
223
|
+
{
|
|
224
|
+
name: "get_element",
|
|
225
|
+
description: "Récupère UN SEUL élément en détail. Utilise quand tu connais l'ID et veux les détails complets.",
|
|
226
|
+
inputSchema: {
|
|
227
|
+
type: "object",
|
|
228
|
+
properties: {
|
|
229
|
+
pageId: {
|
|
230
|
+
type: "number",
|
|
231
|
+
description: "L'ID de la page",
|
|
232
|
+
},
|
|
233
|
+
elementId: {
|
|
234
|
+
type: "string",
|
|
235
|
+
description: "L'ID de l'élément à récupérer",
|
|
236
|
+
},
|
|
237
|
+
},
|
|
238
|
+
required: ["pageId", "elementId"],
|
|
239
|
+
},
|
|
240
|
+
},
|
|
241
|
+
|
|
242
|
+
{
|
|
243
|
+
name: "update_element",
|
|
244
|
+
description: "Modifie UN SEUL élément sans recharger/renvoyer toute la page. Ultra économe en tokens. Utilise pour changer une couleur, un texte, etc.",
|
|
245
|
+
inputSchema: {
|
|
246
|
+
type: "object",
|
|
247
|
+
properties: {
|
|
248
|
+
pageId: {
|
|
249
|
+
type: "number",
|
|
250
|
+
description: "L'ID de la page",
|
|
251
|
+
},
|
|
252
|
+
elementId: {
|
|
253
|
+
type: "string",
|
|
254
|
+
description: "L'ID de l'élément à modifier",
|
|
255
|
+
},
|
|
256
|
+
newSettings: {
|
|
257
|
+
type: "object",
|
|
258
|
+
description: "Les nouveaux settings (fusionnés avec les anciens)",
|
|
259
|
+
},
|
|
260
|
+
},
|
|
261
|
+
required: ["pageId", "elementId", "newSettings"],
|
|
262
|
+
},
|
|
263
|
+
},
|
|
264
|
+
|
|
265
|
+
{
|
|
266
|
+
name: "add_element",
|
|
267
|
+
description: "Ajoute UN SEUL nouvel élément à la page. Utilise pour ajouter un bouton, un paragraphe, etc.",
|
|
268
|
+
inputSchema: {
|
|
269
|
+
type: "object",
|
|
270
|
+
properties: {
|
|
271
|
+
pageId: {
|
|
272
|
+
type: "number",
|
|
273
|
+
description: "L'ID de la page",
|
|
274
|
+
},
|
|
275
|
+
element: {
|
|
276
|
+
type: "object",
|
|
277
|
+
description: "L'élément complet à ajouter (avec id, name, parent, children, settings)",
|
|
278
|
+
},
|
|
279
|
+
position: {
|
|
280
|
+
type: "number",
|
|
281
|
+
description: "Position dans le tableau (optionnel, défaut: fin)",
|
|
282
|
+
},
|
|
283
|
+
},
|
|
284
|
+
required: ["pageId", "element"],
|
|
285
|
+
},
|
|
286
|
+
},
|
|
287
|
+
|
|
288
|
+
{
|
|
289
|
+
name: "batch_add",
|
|
290
|
+
description: "Ajoute PLUSIEURS éléments en UNE SEULE fois. Utilise pour créer une section complète (5-10 éléments). Plus efficace que add_element en boucle.",
|
|
291
|
+
inputSchema: {
|
|
292
|
+
type: "object",
|
|
293
|
+
properties: {
|
|
294
|
+
pageId: {
|
|
295
|
+
type: "number",
|
|
296
|
+
description: "L'ID de la page",
|
|
297
|
+
},
|
|
298
|
+
elements: {
|
|
299
|
+
type: "array",
|
|
300
|
+
description: "Tableau des éléments à ajouter",
|
|
301
|
+
items: {
|
|
302
|
+
type: "object"
|
|
303
|
+
}
|
|
304
|
+
},
|
|
305
|
+
},
|
|
306
|
+
required: ["pageId", "elements"],
|
|
307
|
+
},
|
|
308
|
+
},
|
|
309
|
+
|
|
310
|
+
{
|
|
311
|
+
name: "delete_element",
|
|
312
|
+
description: "Supprime UN élément et nettoie les références parent/enfant.",
|
|
313
|
+
inputSchema: {
|
|
314
|
+
type: "object",
|
|
315
|
+
properties: {
|
|
316
|
+
pageId: {
|
|
317
|
+
type: "number",
|
|
318
|
+
description: "L'ID de la page",
|
|
319
|
+
},
|
|
320
|
+
elementId: {
|
|
321
|
+
type: "string",
|
|
322
|
+
description: "L'ID de l'élément à supprimer",
|
|
323
|
+
},
|
|
324
|
+
},
|
|
325
|
+
required: ["pageId", "elementId"],
|
|
326
|
+
},
|
|
327
|
+
},
|
|
328
|
+
|
|
329
|
+
// ===== 🆕 NOUVEL OUTIL v3.0 : REORDER_SECTIONS =====
|
|
330
|
+
|
|
331
|
+
{
|
|
332
|
+
name: "reorder_sections",
|
|
333
|
+
description: "Réorganise l'ordre d'affichage des sections principales (parent: 0). CRITIQUE : Dans Bricks, l'ordre dans le tableau JSON détermine l'ordre de rendu. Utilise TOUJOURS cet outil après création d'un header/footer pour le placer correctement. Exemple : reorder_sections(9, ['header_pro', 'hero_section', 'services_section']) met le header en premier.",
|
|
334
|
+
inputSchema: {
|
|
335
|
+
type: "object",
|
|
336
|
+
properties: {
|
|
337
|
+
pageId: {
|
|
338
|
+
type: "number",
|
|
339
|
+
description: "L'ID de la page WordPress",
|
|
340
|
+
},
|
|
341
|
+
orderedIds: {
|
|
342
|
+
type: "array",
|
|
343
|
+
items: { type: "string" },
|
|
344
|
+
description: "Tableau des IDs des sections dans l'ordre souhaité (ex: ['header_pro', 'hero_section', 'services_section']). Les sections non listées seront placées à la fin.",
|
|
345
|
+
},
|
|
346
|
+
},
|
|
347
|
+
required: ["pageId", "orderedIds"],
|
|
348
|
+
},
|
|
349
|
+
},
|
|
350
|
+
],
|
|
351
|
+
};
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
// Gérer les appels de tools
|
|
355
|
+
mcpServer.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
356
|
+
const { name, arguments: args } = request.params;
|
|
357
|
+
|
|
358
|
+
console.error(`\n========================================`);
|
|
359
|
+
console.error(`[LOG] Tool appelé: ${name}`);
|
|
360
|
+
console.error(`[LOG] Arguments reçus:`, JSON.stringify(args, null, 2));
|
|
361
|
+
console.error(`========================================\n`);
|
|
362
|
+
|
|
363
|
+
try {
|
|
364
|
+
let result;
|
|
365
|
+
|
|
366
|
+
switch (name) {
|
|
367
|
+
// ===== OUTILS EXISTANTS =====
|
|
368
|
+
case "list_bricks_pages":
|
|
369
|
+
console.error(`[LOG] Exécution: list_bricks_pages`);
|
|
370
|
+
result = await callWordPressAPI("/list-pages");
|
|
371
|
+
break;
|
|
372
|
+
|
|
373
|
+
case "get_page_json":
|
|
374
|
+
console.error(`[LOG] Exécution: get_page_json avec pageId=${args.pageId}`);
|
|
375
|
+
result = await callWordPressAPI("/get-page-json", "POST", {
|
|
376
|
+
pageId: args.pageId,
|
|
377
|
+
});
|
|
378
|
+
break;
|
|
379
|
+
|
|
380
|
+
case "update_page_json":
|
|
381
|
+
console.error(`[LOG] Exécution: update_page_json`);
|
|
382
|
+
console.error(`[LOG] pageId: ${args.pageId}`);
|
|
383
|
+
console.error(`[LOG] newJsonData type:`, typeof args.newJsonData);
|
|
384
|
+
console.error(`[LOG] newJsonData est un array?`, Array.isArray(args.newJsonData));
|
|
385
|
+
result = await callWordPressAPI("/update-page-json", "POST", {
|
|
386
|
+
pageId: args.pageId,
|
|
387
|
+
newJsonData: args.newJsonData,
|
|
388
|
+
});
|
|
389
|
+
break;
|
|
390
|
+
|
|
391
|
+
case "analyze_json_structure":
|
|
392
|
+
console.error(`[LOG] Exécution: analyze_json_structure`);
|
|
393
|
+
result = await callWordPressAPI("/analyze-json", "POST", {
|
|
394
|
+
jsonData: args.jsonData,
|
|
395
|
+
});
|
|
396
|
+
break;
|
|
397
|
+
|
|
398
|
+
// ===== OUTILS v2.0 =====
|
|
399
|
+
|
|
400
|
+
case "get_page_structure":
|
|
401
|
+
console.error(`[LOG] Exécution: get_page_structure avec pageId=${args.pageId}`);
|
|
402
|
+
result = await callWordPressAPI("/get-page-structure", "POST", {
|
|
403
|
+
pageId: args.pageId,
|
|
404
|
+
});
|
|
405
|
+
break;
|
|
406
|
+
|
|
407
|
+
case "find_elements":
|
|
408
|
+
console.error(`[LOG] Exécution: find_elements`);
|
|
409
|
+
console.error(`[LOG] Critères:`, JSON.stringify(args.criteria, null, 2));
|
|
410
|
+
result = await callWordPressAPI("/find-elements", "POST", {
|
|
411
|
+
pageId: args.pageId,
|
|
412
|
+
criteria: args.criteria || {},
|
|
413
|
+
limit: args.limit || 100,
|
|
414
|
+
});
|
|
415
|
+
break;
|
|
416
|
+
|
|
417
|
+
case "get_element":
|
|
418
|
+
console.error(`[LOG] Exécution: get_element`);
|
|
419
|
+
console.error(`[LOG] pageId: ${args.pageId}, elementId: ${args.elementId}`);
|
|
420
|
+
result = await callWordPressAPI("/get-element", "POST", {
|
|
421
|
+
pageId: args.pageId,
|
|
422
|
+
elementId: args.elementId,
|
|
423
|
+
});
|
|
424
|
+
break;
|
|
425
|
+
|
|
426
|
+
case "update_element":
|
|
427
|
+
console.error(`[LOG] Exécution: update_element`);
|
|
428
|
+
console.error(`[LOG] Modification de l'élément ${args.elementId}`);
|
|
429
|
+
result = await callWordPressAPI("/update-element", "POST", {
|
|
430
|
+
pageId: args.pageId,
|
|
431
|
+
elementId: args.elementId,
|
|
432
|
+
newSettings: args.newSettings,
|
|
433
|
+
});
|
|
434
|
+
break;
|
|
435
|
+
|
|
436
|
+
case "add_element":
|
|
437
|
+
console.error(`[LOG] Exécution: add_element`);
|
|
438
|
+
console.error(`[LOG] Ajout de l'élément:`, JSON.stringify(args.element, null, 2));
|
|
439
|
+
result = await callWordPressAPI("/add-element", "POST", {
|
|
440
|
+
pageId: args.pageId,
|
|
441
|
+
element: args.element,
|
|
442
|
+
position: args.position,
|
|
443
|
+
});
|
|
444
|
+
break;
|
|
445
|
+
|
|
446
|
+
case "batch_add":
|
|
447
|
+
console.error(`[LOG] Exécution: batch_add`);
|
|
448
|
+
console.error(`[LOG] Ajout de ${args.elements.length} éléments`);
|
|
449
|
+
result = await callWordPressAPI("/batch-add", "POST", {
|
|
450
|
+
pageId: args.pageId,
|
|
451
|
+
elements: args.elements,
|
|
452
|
+
});
|
|
453
|
+
break;
|
|
454
|
+
|
|
455
|
+
case "delete_element":
|
|
456
|
+
console.error(`[LOG] Exécution: delete_element`);
|
|
457
|
+
console.error(`[LOG] Suppression de l'élément ${args.elementId}`);
|
|
458
|
+
result = await callWordPressAPI("/delete-element", "POST", {
|
|
459
|
+
pageId: args.pageId,
|
|
460
|
+
elementId: args.elementId,
|
|
461
|
+
});
|
|
462
|
+
break;
|
|
463
|
+
|
|
464
|
+
// ===== 🆕 NOUVEL OUTIL v3.0 : REORDER_SECTIONS =====
|
|
465
|
+
|
|
466
|
+
case "reorder_sections":
|
|
467
|
+
console.error(`[LOG] Exécution: reorder_sections`);
|
|
468
|
+
console.error(`[LOG] pageId: ${args.pageId}`);
|
|
469
|
+
console.error(`[LOG] orderedIds:`, JSON.stringify(args.orderedIds, null, 2));
|
|
470
|
+
result = await callWordPressAPI("/reorder-sections", "POST", {
|
|
471
|
+
pageId: args.pageId,
|
|
472
|
+
orderedIds: args.orderedIds,
|
|
473
|
+
});
|
|
474
|
+
break;
|
|
475
|
+
|
|
476
|
+
default:
|
|
477
|
+
console.error(`[LOG] Tool inconnu: ${name}`);
|
|
478
|
+
result = { error: `Tool ${name} not found` };
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
console.error(`[LOG] Résultat:`, JSON.stringify(result, null, 2));
|
|
482
|
+
return {
|
|
483
|
+
content: [
|
|
484
|
+
{
|
|
485
|
+
type: "text",
|
|
486
|
+
text: JSON.stringify(result, null, 2),
|
|
487
|
+
},
|
|
488
|
+
],
|
|
489
|
+
};
|
|
490
|
+
} catch (error) {
|
|
491
|
+
console.error(`[LOG] ERREUR:`, error.message);
|
|
492
|
+
console.error(`[LOG] Stack:`, error.stack);
|
|
493
|
+
return {
|
|
494
|
+
content: [
|
|
495
|
+
{
|
|
496
|
+
type: "text",
|
|
497
|
+
text: `Erreur: ${error.message}`,
|
|
498
|
+
},
|
|
499
|
+
],
|
|
500
|
+
isError: true,
|
|
501
|
+
};
|
|
502
|
+
}
|
|
503
|
+
});
|
|
504
|
+
|
|
505
|
+
// Démarrer le serveur
|
|
506
|
+
async function main() {
|
|
507
|
+
const transport = new StdioServerTransport();
|
|
508
|
+
await mcpServer.connect(transport);
|
|
509
|
+
console.error("[READY] MCP Bricks Builder v3.0 démarré et connecté");
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
main().catch(console.error);
|