bricks-builder-mcp 3.6.5 → 3.7.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/README.md +2 -0
- package/package.json +3 -2
- package/server.js +144 -0
package/README.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
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
4
|
|
|
5
|
+
💬 **Communauté Discord** : [https://discord.gg/rX22zHRzH](https://discord.gg/rX22zHRzH) — viens discuter Bricks + IA, partager tes builds et signaler des bugs.
|
|
6
|
+
|
|
5
7
|
## Architecture
|
|
6
8
|
|
|
7
9
|
```
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "bricks-builder-mcp",
|
|
4
|
-
"version": "3.
|
|
5
|
-
"description": "Serveur MCP pour piloter Bricks Builder (WordPress) depuis Claude — édition de pages, gestion d'éléments, réordonnancement des sections, vérification visuelle
|
|
4
|
+
"version": "3.7.1",
|
|
5
|
+
"description": "Serveur MCP pour piloter Bricks Builder (WordPress) depuis Claude — édition de pages, gestion d'éléments, réordonnancement des sections, vérification visuelle (verify_element), upload optimisé WebP. Communauté Discord : https://discord.gg/rX22zHRzH",
|
|
6
|
+
"homepage": "https://discord.gg/rX22zHRzH",
|
|
6
7
|
"main": "server.js",
|
|
7
8
|
"bin": {
|
|
8
9
|
"bricks-builder-mcp": "./server.js"
|
package/server.js
CHANGED
|
@@ -76,6 +76,49 @@ process.on('exit', () => {
|
|
|
76
76
|
try { _browser.close(); } catch {}
|
|
77
77
|
}
|
|
78
78
|
});
|
|
79
|
+
|
|
80
|
+
// ===== v3.7.0 — Helpers upload local =====
|
|
81
|
+
// Le MCP server tourne sur la machine user (lancé par Claude Desktop via stdio),
|
|
82
|
+
// donc il a accès direct au filesystem user. Il peut lire les fichiers et les
|
|
83
|
+
// encoder en base64 LOCALEMENT pour les envoyer au plugin sans jamais que les
|
|
84
|
+
// bytes passent dans le contexte de l'AI.
|
|
85
|
+
|
|
86
|
+
const MIME_BY_EXT = {
|
|
87
|
+
png: 'image/png',
|
|
88
|
+
jpg: 'image/jpeg',
|
|
89
|
+
jpeg: 'image/jpeg',
|
|
90
|
+
gif: 'image/gif',
|
|
91
|
+
webp: 'image/webp',
|
|
92
|
+
svg: 'image/svg+xml',
|
|
93
|
+
avif: 'image/avif',
|
|
94
|
+
mp4: 'video/mp4',
|
|
95
|
+
webm: 'video/webm',
|
|
96
|
+
mov: 'video/quicktime',
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
function readLocalFileAsDataUri(localPath) {
|
|
100
|
+
if (!fs.existsSync(localPath)) {
|
|
101
|
+
throw new Error(`Fichier introuvable : ${localPath}`);
|
|
102
|
+
}
|
|
103
|
+
const stat = fs.statSync(localPath);
|
|
104
|
+
if (!stat.isFile()) {
|
|
105
|
+
throw new Error(`Pas un fichier : ${localPath}`);
|
|
106
|
+
}
|
|
107
|
+
const ext = (localPath.split('.').pop() || '').toLowerCase();
|
|
108
|
+
const mime = MIME_BY_EXT[ext];
|
|
109
|
+
if (!mime) {
|
|
110
|
+
throw new Error(`Extension non supportée : ${ext} (formats: ${Object.keys(MIME_BY_EXT).join(', ')})`);
|
|
111
|
+
}
|
|
112
|
+
const bytes = fs.readFileSync(localPath);
|
|
113
|
+
const b64 = bytes.toString('base64');
|
|
114
|
+
return {
|
|
115
|
+
dataUri: `data:${mime};base64,${b64}`,
|
|
116
|
+
size: stat.size,
|
|
117
|
+
mime,
|
|
118
|
+
ext,
|
|
119
|
+
basename: localPath.split('/').pop(),
|
|
120
|
+
};
|
|
121
|
+
}
|
|
79
122
|
process.on('SIGINT', () => {
|
|
80
123
|
if (_browser) {
|
|
81
124
|
try { _browser.close(); } catch {}
|
|
@@ -1014,6 +1057,51 @@ mcpServer.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
|
1014
1057
|
},
|
|
1015
1058
|
},
|
|
1016
1059
|
|
|
1060
|
+
// ===== v3.7.0 — UPLOAD FROM LOCAL FILESYSTEM =====
|
|
1061
|
+
// Lit le fichier directement sur le disque (le MCP server tourne en local),
|
|
1062
|
+
// encode en base64 LOCALEMENT, et l'envoie au plugin via data URI.
|
|
1063
|
+
// L'AI ne voit JAMAIS les bytes — elle donne juste le path.
|
|
1064
|
+
{
|
|
1065
|
+
name: "upload_local_file",
|
|
1066
|
+
description: "⭐ UPLOAD OPTIMAL pour des fichiers locaux. L'AI donne juste le path, le MCP server lit le fichier en local et l'envoie au plugin. Aucun b64 ne transite par le contexte AI. Param `optimize: true` (recommandé) convertit en WebP qualité 80, redim à 2000px max, et renomme avec extension .webp. Idéal pour SEO + perf web. Retourne {success, id, url, filename, optimization: {originalSize, optimizedSize, savings}}.",
|
|
1067
|
+
inputSchema: {
|
|
1068
|
+
type: "object",
|
|
1069
|
+
properties: {
|
|
1070
|
+
localPath: { type: "string", description: "Chemin absolu du fichier local (ex: /Users/.../jt-assets/logo.png)" },
|
|
1071
|
+
title: { type: "string", description: "Titre WP (sert aussi de nom de fichier slugifié — utilisé pour SEO)" },
|
|
1072
|
+
alt: { type: "string", description: "Texte alternatif (OBLIGATOIRE pour SEO + accessibilité)" },
|
|
1073
|
+
caption: { type: "string", description: "Légende optionnelle" },
|
|
1074
|
+
optimize: { type: "boolean", description: "Convertit en WebP qualité 80, redim à 2000px max. Défaut: true (recommandé)." },
|
|
1075
|
+
},
|
|
1076
|
+
required: ["localPath"],
|
|
1077
|
+
},
|
|
1078
|
+
},
|
|
1079
|
+
{
|
|
1080
|
+
name: "upload_local_files_batch",
|
|
1081
|
+
description: "Upload plusieurs fichiers locaux en 1 appel. Même principe que upload_local_file mais en lot. Continue même si certains échouent. Recommandé pour intégrer un dossier d'assets (logos, photos, etc.) en 1 commande.",
|
|
1082
|
+
inputSchema: {
|
|
1083
|
+
type: "object",
|
|
1084
|
+
properties: {
|
|
1085
|
+
items: {
|
|
1086
|
+
type: "array",
|
|
1087
|
+
description: "Liste des fichiers à uploader",
|
|
1088
|
+
items: {
|
|
1089
|
+
type: "object",
|
|
1090
|
+
properties: {
|
|
1091
|
+
localPath: { type: "string", description: "Chemin absolu du fichier local" },
|
|
1092
|
+
title: { type: "string", description: "Titre WP (slugifié pour le nom de fichier)" },
|
|
1093
|
+
alt: { type: "string", description: "Alt SEO" },
|
|
1094
|
+
caption: { type: "string", description: "Légende" },
|
|
1095
|
+
},
|
|
1096
|
+
required: ["localPath"],
|
|
1097
|
+
},
|
|
1098
|
+
},
|
|
1099
|
+
optimize: { type: "boolean", description: "Convertit tous en WebP. Défaut: true." },
|
|
1100
|
+
},
|
|
1101
|
+
required: ["items"],
|
|
1102
|
+
},
|
|
1103
|
+
},
|
|
1104
|
+
|
|
1017
1105
|
// ===== v3.6.0 — UPLOAD MEDIA BATCH =====
|
|
1018
1106
|
{
|
|
1019
1107
|
name: "upload_media_batch",
|
|
@@ -1733,9 +1821,65 @@ mcpServer.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
|
1733
1821
|
case "upload_media_batch":
|
|
1734
1822
|
result = await callWordPressAPI("/upload-media-batch", "POST", {
|
|
1735
1823
|
items: args.items,
|
|
1824
|
+
optimize: args.optimize,
|
|
1736
1825
|
});
|
|
1737
1826
|
break;
|
|
1738
1827
|
|
|
1828
|
+
// ===== v3.7.0 — UPLOAD FROM LOCAL FILESYSTEM =====
|
|
1829
|
+
case "upload_local_file": {
|
|
1830
|
+
try {
|
|
1831
|
+
const fileData = readLocalFileAsDataUri(args.localPath);
|
|
1832
|
+
logToFile(`[upload_local_file] ${args.localPath} (${fileData.size} bytes ${fileData.mime})`);
|
|
1833
|
+
// Le b64 est généré ici, dans le MCP server. Il part vers le plugin
|
|
1834
|
+
// mais ne transite JAMAIS par le contexte AI.
|
|
1835
|
+
result = await callWordPressAPI("/upload-media", "POST", {
|
|
1836
|
+
sourceUrl: fileData.dataUri,
|
|
1837
|
+
title: args.title || fileData.basename.replace(/\.[^.]+$/, ''),
|
|
1838
|
+
alt: args.alt,
|
|
1839
|
+
caption: args.caption,
|
|
1840
|
+
optimize: args.optimize !== false, // défaut true
|
|
1841
|
+
});
|
|
1842
|
+
} catch (err) {
|
|
1843
|
+
result = { success: false, error: err.message, localPath: args.localPath };
|
|
1844
|
+
}
|
|
1845
|
+
break;
|
|
1846
|
+
}
|
|
1847
|
+
|
|
1848
|
+
case "upload_local_files_batch": {
|
|
1849
|
+
const batchItems = [];
|
|
1850
|
+
const readErrors = [];
|
|
1851
|
+
for (const item of (args.items || [])) {
|
|
1852
|
+
try {
|
|
1853
|
+
const fileData = readLocalFileAsDataUri(item.localPath);
|
|
1854
|
+
batchItems.push({
|
|
1855
|
+
sourceUrl: fileData.dataUri,
|
|
1856
|
+
title: item.title || fileData.basename.replace(/\.[^.]+$/, ''),
|
|
1857
|
+
alt: item.alt,
|
|
1858
|
+
caption: item.caption,
|
|
1859
|
+
});
|
|
1860
|
+
} catch (err) {
|
|
1861
|
+
readErrors.push({ localPath: item.localPath, error: err.message });
|
|
1862
|
+
}
|
|
1863
|
+
}
|
|
1864
|
+
if (batchItems.length === 0) {
|
|
1865
|
+
result = {
|
|
1866
|
+
success: false,
|
|
1867
|
+
error: "Aucun fichier lisible",
|
|
1868
|
+
readErrors,
|
|
1869
|
+
};
|
|
1870
|
+
break;
|
|
1871
|
+
}
|
|
1872
|
+
result = await callWordPressAPI("/upload-media-batch", "POST", {
|
|
1873
|
+
items: batchItems,
|
|
1874
|
+
optimize: args.optimize !== false, // défaut true
|
|
1875
|
+
});
|
|
1876
|
+
// Joindre les erreurs de lecture locales au résultat
|
|
1877
|
+
if (readErrors.length > 0) {
|
|
1878
|
+
result.localReadErrors = readErrors;
|
|
1879
|
+
}
|
|
1880
|
+
break;
|
|
1881
|
+
}
|
|
1882
|
+
|
|
1739
1883
|
default:
|
|
1740
1884
|
console.error(`[LOG] Tool inconnu: ${name}`);
|
|
1741
1885
|
result = { error: `Tool ${name} not found` };
|