standardize packaging, tooling, docs, CI, and licensing
This commit is contained in:
@@ -9,9 +9,8 @@ resources compatible with the Model Context Protocol (MCP).
|
||||
|
||||
import json
|
||||
from pathlib import Path
|
||||
from typing import Dict, List
|
||||
|
||||
from docforge.models import Project, Module, DocObject
|
||||
from docforge.models import DocObject, Module, Project
|
||||
|
||||
|
||||
class MCPRenderer:
|
||||
@@ -42,15 +41,17 @@ class MCPRenderer:
|
||||
modules_dir = out_dir / "modules"
|
||||
modules_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
nav: List[Dict[str, str]] = []
|
||||
nav: list[dict[str, str]] = []
|
||||
|
||||
for module in project.get_all_modules():
|
||||
self._write_module(module, modules_dir)
|
||||
|
||||
nav.append({
|
||||
"module": module.path,
|
||||
"resource": f"doc://modules/{module.path}",
|
||||
})
|
||||
nav.append(
|
||||
{
|
||||
"module": module.path,
|
||||
"resource": f"doc://modules/{module.path}",
|
||||
}
|
||||
)
|
||||
|
||||
# Write nav.json
|
||||
(out_dir / "nav.json").write_text(
|
||||
@@ -91,7 +92,7 @@ class MCPRenderer:
|
||||
out.parent.mkdir(parents=True, exist_ok=True)
|
||||
out.write_text(self._json(payload), encoding="utf-8")
|
||||
|
||||
def _render_module(self, module: Module) -> Dict:
|
||||
def _render_module(self, module: Module) -> dict:
|
||||
"""
|
||||
Convert a Module model into MCP-compatible structured data.
|
||||
|
||||
@@ -103,7 +104,7 @@ class MCPRenderer:
|
||||
Dict:
|
||||
Dictionary representing the module and its documented objects.
|
||||
"""
|
||||
data: Dict = {
|
||||
data: dict = {
|
||||
"path": module.path,
|
||||
"docstring": module.docstring,
|
||||
"objects": {},
|
||||
@@ -114,7 +115,7 @@ class MCPRenderer:
|
||||
|
||||
return data
|
||||
|
||||
def _render_object(self, obj: DocObject) -> Dict:
|
||||
def _render_object(self, obj: DocObject) -> dict:
|
||||
"""
|
||||
Recursively convert a DocObject into structured MCP data.
|
||||
|
||||
@@ -126,7 +127,7 @@ class MCPRenderer:
|
||||
Dict:
|
||||
Dictionary describing the object and any nested members.
|
||||
"""
|
||||
data: Dict = {
|
||||
data: dict = {
|
||||
"name": obj.name,
|
||||
"kind": obj.kind,
|
||||
"path": obj.path,
|
||||
@@ -137,14 +138,13 @@ class MCPRenderer:
|
||||
members = list(obj.get_all_members())
|
||||
if members:
|
||||
data["members"] = {
|
||||
member.name: self._render_object(member)
|
||||
for member in members
|
||||
member.name: self._render_object(member) for member in members
|
||||
}
|
||||
|
||||
return data
|
||||
|
||||
@staticmethod
|
||||
def _json(data: Dict) -> str:
|
||||
def _json(data: dict) -> str:
|
||||
"""
|
||||
Serialize data to formatted JSON.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user