使用说明
WordPress主题生成器-ADK+MCP
使用谷歌代理开发工具包(ADK)和模型上下文协议(MCP)的高级WordPress主题生成系统。
建筑
该系统将视觉设计数据(Stitch JSON+截图)转换为与Elementor兼容的生产就绪WordPress主题。
组件
- MCP服务器 (
mcp_server/):通过模型上下文协议公开8个专用工具 - ADK代理 (
agent/):使用Gemini 2.5 Pro编排主题生成 - 跑者 (
runner/):执行代理管道(本地或云运行) - 模型 (
models/):用于验证的Pydantic模式
8-工具管线
parse_stitch_json-解析并验证Stitch JSON导出extract_layout_structure-提取响应网格布局generate_component_tree-映射到WordPress块generate_html_css-创建HTML模板和CSScreate_theme_json-生成theme.json(块主题模式)create_php_templates-使用Elementor支持创建PHP文件assemble_theme_folder-组装完整的文件夹结构zip_theme_folder-创建可下载的ZIP存档
安装
# Clone repository
git clone https://github.com/your-org/adk-mcp-theme-generator.git
cd adk-mcp-theme-generator
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Configure environment
cp .env.example .env
# Edit .env with your credentials
用法
本地开发
# Run theme generation
python runner/main.py
程序化使用
import asyncio
from runner.main import run_theme_generation
# Your Stitch JSON export
stitch_json = """
{
"version": "1.0",
"designTokens": {...},
"components": [...]
}
"""
# Generate theme
result = asyncio.run(run_theme_generation(
stitch_json=stitch_json,
theme_name="My Custom Theme"
))
# Save ZIP
import base64
zip_bytes = base64.b64decode(result['zip_base64'])
with open(result['zip_filename'], 'wb') as f:
f.write(zip_bytes)
云运行部署
# Build and deploy
gcloud run deploy adk-theme-generator \
--source . \
--region us-central1 \
--allow-unauthenticated \
--memory 4Gi \
--cpu 2 \
--timeout 3600
测试
# Run tests
pytest tests/
特性
- ✅ 多模式输入(屏幕截图+缝合JSON)
- ✅ WordPress块主题(FSE)生成
- ✅ 完全兼容Elementor
- ✅ 响应式设计(480、768、1024、1280px断点)
- ✅ CSS隔离(与Elementor无冲突)
- ✅ theme.json验证(WP 6.6模式)
- ✅ 生产就绪的PHP模板
- ✅ 云运行部署就绪
许可证
MIT许可证