feat(mcp): add MCP JSON renderer and CLI support, update tests accordingly

- Add MCPRenderer to generate MCP-native JSON bundles (index.json, nav.json, modules/*.json)
- Expose MCPRenderer via public API and CLI (`generate-mcp` command)
- Replace Markdown-based MCP output with structured JSON resources
- Update MCP renderer type stubs to match new JSON-based implementation
- Refactor MCP tests to validate JSON content, bundle structure, and navigation
- Fix MCP module coverage test to use explicit project_root for reliable discovery
This commit is contained in:
2026-01-21 16:43:21 +05:30
parent ce2eafac85
commit 5370a7faa2
8 changed files with 180 additions and 74 deletions

View File

@@ -1,31 +1,26 @@
from pathlib import Path
from typing import Iterable
from typing import Dict, List
from docforge.models import Project, Module, DocObject
class MCPRenderer:
"""
Renderer that emits MCP-compatible documentation resources.
"""
"""Renderer that emits MCP-native JSON resources from docforge models."""
name: str
def generate_sources(self, project: Project, out_dir: Path) -> None:
"""Generate MCP resources for the given project."""
"""Generate MCP-compatible JSON resources and navigation for the project."""
def _write_module(self, module: Module, out_dir: Path) -> None:
"""Write a single module as an MCP resource."""
def _write_module(self, module: Module, modules_dir: Path) -> None:
"""Serialize a module into an MCP JSON resource."""
def _render_module(self, module: Module) -> str:
"""Render a module and its contents into a text document."""
def _render_module(self, module: Module) -> Dict:
"""Render a Module into MCP-friendly structured data."""
def _render_object(
self,
obj: DocObject,
level: int,
) -> Iterable[str]:
"""Recursively render a documented object and its members."""
def _render_object(self, obj: DocObject) -> Dict:
"""Recursively render a DocObject into structured MCP data."""
def _module_resource_path(self, module: Module) -> Path:
"""Compute the MCP resource path for a module."""
@staticmethod
def _json(data: Dict) -> str:
"""Serialize structured data to formatted JSON."""