Buckets:
| import os | |
| import json | |
| from mcp.server.fastmcp import FastMCP | |
| from modules import scaffold, components, styling, knowledge | |
| # Initialize FastMCP server | |
| mcp = FastMCP("Website Builder") | |
| PROJECTS_FILE = "data/projects.json" | |
| def load_projects(): | |
| if not os.path.exists(PROJECTS_FILE): return {} | |
| try: | |
| with open(PROJECTS_FILE, "r") as f: | |
| content = f.read() | |
| return json.loads(content) if content else {} | |
| except: return {} | |
| def save_project(name, metadata): | |
| projects = load_projects() | |
| projects[name] = metadata | |
| with open(PROJECTS_FILE, "w") as f: | |
| json.dump(projects, f, indent=2) | |
| def init_website_project(name: str, framework: str = "Tailwind CDN") -> str: | |
| """Initializes a new website project directory.""" | |
| res = scaffold.init_project(name, framework) | |
| save_project(name, {"framework": framework, "pages": ["index.html"], "components": []}) | |
| return res | |
| def generate_ui_component(type: str, title: str = None, text: str = None) -> str: | |
| """Generates code for common UI components.""" | |
| details = {"title": title, "text": text} | |
| return components.generate_component(type, details=details) | |
| def add_component_to_page(project_name: str, component_type: str, section_id: str, title: str = None, text: str = None) -> str: | |
| """Injects a component into index.html.""" | |
| projects = load_projects() | |
| if project_name not in projects: return f"Error: Project '{project_name}' not found." | |
| code = components.generate_component(component_type, details={"title": title, "text": text}) | |
| path = os.path.join(os.getcwd(), "web_projects", project_name, "index.html") | |
| if not os.path.exists(path): return f"Error: index.html not found." | |
| with open(path, "r") as f: content = f.read() | |
| placeholder = f'<div id="{section_id}"></div>' | |
| if placeholder in content: | |
| new_content = content.replace(placeholder, f'<div id="{section_id}">{code}</div>') | |
| with open(path, "w") as f: f.write(new_content) | |
| return f"Successfully added {component_type} to {project_name}." | |
| return f"Error: Placeholder '{placeholder}' not found." | |
| def generate_full_landing_page(project_name: str, title: str, sections: list) -> str: | |
| """Assembles a complete landing page with multiple sections.""" | |
| init_website_project(project_name) | |
| for section in sections: | |
| add_component_to_page(project_name, section, section, title=f"{title} {section.capitalize()}") | |
| return f"Landing page for '{project_name}' assembled." | |
| def add_custom_css(project_name: str, css_code: str) -> str: | |
| """Appends custom CSS to the project.""" | |
| path = os.path.join(os.getcwd(), "web_projects", project_name, "index.html") | |
| if not os.path.exists(path): return "Error: Project not found." | |
| with open(path, "r") as f: content = f.read() | |
| if "</head>" in content: | |
| style_tag = f"<style>\n{css_code}\n</style>\n</head>" | |
| new_content = content.replace("</head>", style_tag) | |
| with open(path, "w") as f: f.write(new_content) | |
| return f"Custom CSS added to {project_name}." | |
| return "Error: Could not find </head> tag." | |
| # Knowledge Base Tools | |
| def get_ux_design_checklist(): | |
| """Returns an expert checklist for modern UX design.""" | |
| return knowledge.get_ux_checklist() | |
| def get_on_page_seo_basics(): | |
| """Returns foundational rules for on-page SEO optimization.""" | |
| return knowledge.get_seo_basics() | |
| def list_site_design_patterns(site_type: str = "Landing"): | |
| """Returns standard layout patterns for Landing pages, Dashboards, or Blogs.""" | |
| return knowledge.list_design_patterns(site_type) | |
| def apply_theme_colors(project_name: str, primary: str, secondary: str) -> str: | |
| """Applies brand colors to the site.""" | |
| script = styling.generate_theme_script(primary, secondary) | |
| path = os.path.join(os.getcwd(), "web_projects", project_name, "index.html") | |
| with open(path, "r") as f: content = f.read() | |
| if "</head>" in content: | |
| new_content = content.replace("</head>", f"{script}\n</head>") | |
| with open(path, "w") as f: f.write(new_content) | |
| return f"Theme colors applied." | |
| return "Error: tag missing." | |
| def list_projects() -> list: | |
| return list(load_projects().keys()) | |
| if __name__ == "__main__": | |
| mcp.run() | |
Xet Storage Details
- Size:
- 4.4 kB
- Xet hash:
- fe4fbfe275ed08a4f8ea75af32f3d9cec6fab1e1d3a563eacaad7d7e1e6ef087
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.