list_templates
Access and browse coding style templates grouped by type and language to enforce consistent standards across Java, Python, and React projects.
Instructions
List all available templates grouped by type and language
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- server.py:32-58 (handler)The handler function for the 'list_templates' tool. It scans the 'templates' directory, categorizes Markdown files by language and type (style_guides or best_practices) using get_template_info, sorts the lists, and returns a structured dictionary or error.@mcp.tool() def list_templates() -> Dict[str, Dict[str, List[str]]]: """List all available templates grouped by type and language""" template_dir = os.path.join(os.path.dirname(__file__), "templates") templates = { "style_guides": {"languages": [], "files": []}, "best_practices": {"languages": [], "files": []} } try: for filename in os.listdir(template_dir): if filename.endswith('.md'): template_info = get_template_info(filename) if template_info: template_type = template_info["type"] templates[template_type]["languages"].append(template_info["language"]) templates[template_type]["files"].append(filename) # Sort the lists for consistent output for template_type in templates: templates[template_type]["languages"].sort() templates[template_type]["files"].sort() return templates except Exception as e: return {"error": f"Failed to list templates: {str(e)}"}
- server.py:9-19 (helper)Helper function used by list_templates to parse filename and determine the language and type (style_guides or best_practices) using a regex pattern.def get_template_info(filename: str) -> Optional[Dict[str, str]]: """Extract template type and language from filename""" pattern = r"^(\w+)_(style_guide|best_practices)\.md$" match = re.match(pattern, filename) if match: language, template_type = match.groups() return { "language": language, "type": "style_guides" if template_type == "style_guide" else "best_practices" } return None
- server.py:32-32 (registration)The @mcp.tool() decorator registers the list_templates function as an MCP tool.@mcp.tool()