scripts/scaffold_fastmcp.py
scripts/scaffold_fastmcp.pyBrowse 6 files
448 tokens
2,005 bytes
Token encoding: o200k_base
Snapshot 24fd22b
← Back to SKILL.md
1#!/usr/bin/env python32"""Copy a FastMCP starter template into a working file."""3 4from __future__ import annotations5 6import argparse7from pathlib import Path8 9 10SCRIPT_DIR = Path(__file__).resolve().parent11SKILL_DIR = SCRIPT_DIR.parent12TEMPLATE_DIR = SKILL_DIR / "templates"13PLACEHOLDER = "__SERVER_NAME__"14 15 16def list_templates() -> list[str]:17 return sorted(path.stem for path in TEMPLATE_DIR.glob("*.py"))18 19 20def render_template(template_name: str, server_name: str) -> str:21 template_path = TEMPLATE_DIR / f"{template_name}.py"22 if not template_path.exists():23 available = ", ".join(list_templates())24 raise SystemExit(f"Unknown template '{template_name}'. Available: {available}")25 return template_path.read_text(encoding="utf-8").replace(PLACEHOLDER, server_name)26 27 28def main() -> int:29 parser = argparse.ArgumentParser(description=__doc__)30 parser.add_argument("--template", help="Template name without .py suffix")31 parser.add_argument("--name", help="FastMCP server display name")32 parser.add_argument("--output", help="Destination Python file path")33 parser.add_argument("--force", action="store_true", help="Overwrite an existing output file")34 parser.add_argument("--list", action="store_true", help="List available templates and exit")35 args = parser.parse_args()36 37 if args.list:38 for name in list_templates():39 print(name)40 return 041 42 if not args.template or not args.name or not args.output:43 parser.error("--template, --name, and --output are required unless --list is used")44 45 output_path = Path(args.output).expanduser()46 if output_path.exists() and not args.force:47 raise SystemExit(f"Refusing to overwrite existing file: {output_path}")48 49 output_path.parent.mkdir(parents=True, exist_ok=True)50 output_path.write_text(render_template(args.template, args.name), encoding="utf-8")51 print(f"Wrote {output_path}")52 return 053 54 55if __name__ == "__main__":56 raise SystemExit(main())57