#!/usr/bin/env python3 """ Fetch BIND9 grammar files using Gitea MCP integration. This script demonstrates how to use mcp_gitea-mcp tools to fetch grammar files. Since we can't directly call MCP tools from Python, this serves as documentation for the manual fetching process that should be done through the MCP interface. Usage: The actual fetching should be done through MCP tool calls: 1. List available tags: mcp_gitea-mcp_list_tags(owner="Mirrors", repo="bind9") 2. Get directory listing: mcp_gitea-mcp_get_dir_content(owner="Mirrors", repo="bind9", ref="v9.18.44", filePath="doc/misc") 3. Fetch each grammar file: mcp_gitea-mcp_get_file_content(owner="Mirrors", repo="bind9", ref="v9.18.44", filePath="doc/misc/options") """ import json from pathlib import Path from typing import Dict, List # Target versions VERSIONS = { "9.18": "v9.18.44", "9.20": "v9.20.18", } # Grammar files to fetch GRAMMAR_FILES = [ "options", "forward.zoneopt", "hint.zoneopt", "in-view.zoneopt", "mirror.zoneopt", "primary.zoneopt", "redirect.zoneopt", "secondary.zoneopt", "static-stub.zoneopt", "stub.zoneopt", "delegation-only.zoneopt", "rndc.grammar", ] SUPPORT_FILES = [ "parsegrammar.py", "checkgrammar.py", ] def generate_fetch_commands() -> List[Dict]: """Generate MCP tool call commands for fetching grammar files.""" commands = [] for version_name, tag in VERSIONS.items(): # List directory command commands.append({ "tool": "mcp_gitea-mcp_get_dir_content", "params": { "owner": "Mirrors", "repo": "bind9", "ref": tag, "filePath": "doc/misc" }, "description": f"List grammar files for {version_name} ({tag})" }) # File fetch commands for grammar_file in GRAMMAR_FILES + SUPPORT_FILES: commands.append({ "tool": "mcp_gitea-mcp_get_file_content", "params": { "owner": "Mirrors", "repo": "bind9", "ref": tag, "filePath": f"doc/misc/{grammar_file}" }, "save_to": f"bind9-grammar/upstream/{tag}/grammar/{grammar_file}", "description": f"Fetch {grammar_file} for {version_name}" }) return commands def save_file_structure() -> Dict: """Generate expected file structure after fetching.""" structure = { "bind9-grammar": { "upstream": {} } } for version_name, tag in VERSIONS.items(): structure["bind9-grammar"]["upstream"][tag] = { "grammar": { "files": GRAMMAR_FILES + SUPPORT_FILES }, "metadata.json": { "version": tag, "version_name": version_name, "repository": "Mirrors/bind9", "fetched_files": len(GRAMMAR_FILES) + len(SUPPORT_FILES) } } return structure def main(): """Generate instructions and commands for grammar fetching.""" print("=" * 70) print("BIND9 Grammar Fetcher - MCP Integration Guide") print("=" * 70) print("\nTarget Versions:") for version_name, tag in VERSIONS.items(): print(f" - BIND {version_name}: {tag}") print(f"\nFiles to fetch per version: {len(GRAMMAR_FILES)} grammar files + {len(SUPPORT_FILES)} support files") print("\n" + "=" * 70) print("MCP TOOL CALL SEQUENCE") print("=" * 70) commands = generate_fetch_commands() for i, cmd in enumerate(commands, 1): print(f"\n[{i}/{len(commands)}] {cmd['description']}") print(f"Tool: {cmd['tool']}") print(f"Parameters:") for key, value in cmd['params'].items(): print(f" - {key}: {value}") if 'save_to' in cmd: print(f"Save to: {cmd['save_to']}") print("\n" + "=" * 70) print("EXPECTED FILE STRUCTURE") print("=" * 70) structure = save_file_structure() print(json.dumps(structure, indent=2)) # Save command list output_dir = Path("bind9-grammar/upstream") output_dir.mkdir(parents=True, exist_ok=True) commands_file = output_dir / "fetch_commands.json" with open(commands_file, 'w') as f: json.dump(commands, f, indent=2) print(f"\nCommand list saved to: {commands_file}") print("\nNote: These commands should be executed through the MCP interface,") print(" not directly from this Python script.") if __name__ == "__main__": main()