from pathlib import Path import click from docforge.loaders import GriffeLoader, discover_module_paths from docforge.renderers import MCPRenderer from docforge.servers import MCPServer def generate_resources(module: str, project_name: str | None, out_dir: Path) -> None: """ Generate MCP-compatible documentation resources. Args: module: The dotted path of the primary module to document. project_name: Optional override for the project name. out_dir: Directory where the MCP JSON resources and nav will be written. """ loader = GriffeLoader() discovered_paths = discover_module_paths(module) project = loader.load_project(discovered_paths, project_name) renderer = MCPRenderer() renderer.generate_sources(project, out_dir) def serve(module: str, mcp_root: Path) -> None: """ Serve MCP documentation from a pre-built bundle. Args: module: The dotted path of the primary module to serve. mcp_root: Path to the directory containing index.json, nav.json, and modules/. """ if not mcp_root.exists(): raise click.ClickException(f"mcp_docs directory not found: {mcp_root}") required = [ mcp_root / "index.json", mcp_root / "nav.json", mcp_root / "modules", ] for path in required: if not path.exists(): raise click.ClickException(f"Invalid MCP bundle, missing: {path.name}") server = MCPServer( mcp_root=mcp_root, name=f"{module}-mcp", ) server.run()