doc changes
This commit is contained in:
@@ -64,7 +64,11 @@ def tree(
|
||||
|
||||
def _print_object(obj, indent: str) -> None:
|
||||
"""
|
||||
Recursive helper to print doc objects.
|
||||
Recursive helper to print doc objects and their members to the console.
|
||||
|
||||
Args:
|
||||
obj: The DocObject to print.
|
||||
indent: The current line indentation string.
|
||||
"""
|
||||
click.echo(f"{indent}├── {obj.name}")
|
||||
for member in obj.get_all_members():
|
||||
@@ -262,7 +266,7 @@ def serve(mkdocs_yml: Path) -> None:
|
||||
|
||||
def main() -> None:
|
||||
"""
|
||||
CLI Entry point.
|
||||
CLI Entry point. Boots the click application.
|
||||
"""
|
||||
cli()
|
||||
|
||||
|
||||
@@ -134,6 +134,15 @@ class GriffeLoader:
|
||||
# -------------------------
|
||||
|
||||
def _convert_module(self, obj: Object) -> Module:
|
||||
"""
|
||||
Convert a Griffe Object (module) into a docforge Module.
|
||||
|
||||
Args:
|
||||
obj: The Griffe Object representing the module.
|
||||
|
||||
Returns:
|
||||
A populated Module instance.
|
||||
"""
|
||||
module = Module(
|
||||
path=obj.path,
|
||||
docstring=self._safe_docstring(obj),
|
||||
@@ -148,6 +157,15 @@ class GriffeLoader:
|
||||
return module
|
||||
|
||||
def _convert_object(self, obj: Object) -> DocObject:
|
||||
"""
|
||||
Recursively convert a Griffe Object into a DocObject hierarchy.
|
||||
|
||||
Args:
|
||||
obj: The Griffe Object to convert.
|
||||
|
||||
Returns:
|
||||
A DocObject instance.
|
||||
"""
|
||||
kind = obj.kind.value
|
||||
signature = self._safe_signature(obj)
|
||||
|
||||
@@ -174,12 +192,30 @@ class GriffeLoader:
|
||||
# -------------------------
|
||||
|
||||
def _safe_docstring(self, obj: Object) -> Optional[str]:
|
||||
"""
|
||||
Safely retrieve the docstring value from a Griffe object.
|
||||
|
||||
Args:
|
||||
obj: The Griffe Object to inspect.
|
||||
|
||||
Returns:
|
||||
The raw docstring string, or None if missing or unresolvable.
|
||||
"""
|
||||
try:
|
||||
return obj.docstring.value if obj.docstring else None
|
||||
except AliasResolutionError:
|
||||
return None
|
||||
|
||||
def _safe_signature(self, obj: Object) -> Optional[str]:
|
||||
"""
|
||||
Safely retrieve the signature string from a Griffe object.
|
||||
|
||||
Args:
|
||||
obj: The Griffe Object to inspect.
|
||||
|
||||
Returns:
|
||||
The string representation of the signature, or None.
|
||||
"""
|
||||
try:
|
||||
if hasattr(obj, "signature") and obj.signature:
|
||||
return str(obj.signature)
|
||||
|
||||
@@ -78,6 +78,18 @@ def resolve_nav(
|
||||
raise FileNotFoundError(docs_root)
|
||||
|
||||
def resolve_pattern(pattern: str) -> List[Path]:
|
||||
"""
|
||||
Resolve a single glob pattern relative to the docs_root.
|
||||
|
||||
Args:
|
||||
pattern: The glob pattern to resolve.
|
||||
|
||||
Returns:
|
||||
A sorted list of matching Path objects.
|
||||
|
||||
Raises:
|
||||
FileNotFoundError: If the pattern doesn't match any files.
|
||||
"""
|
||||
full = docs_root / pattern
|
||||
matches = sorted(
|
||||
Path(p) for p in glob.glob(str(full), recursive=True)
|
||||
|
||||
@@ -13,6 +13,13 @@ class MCPServer:
|
||||
"""
|
||||
|
||||
def __init__(self, mcp_root: Path, name: str) -> None:
|
||||
"""
|
||||
Initialize the MCPServer.
|
||||
|
||||
Args:
|
||||
mcp_root: Path to the directory containing pre-built MCP JSON resources.
|
||||
name: Name of the MCP server.
|
||||
"""
|
||||
self.mcp_root = mcp_root
|
||||
self.app = FastMCP(name)
|
||||
|
||||
@@ -24,6 +31,15 @@ class MCPServer:
|
||||
# ------------------------------------------------------------------
|
||||
|
||||
def _read_json(self, path: Path) -> Any:
|
||||
"""
|
||||
Read and parse a JSON file, returning diagnostic errors if missing.
|
||||
|
||||
Args:
|
||||
path: Path to the JSON file.
|
||||
|
||||
Returns:
|
||||
The parsed JSON data or an error dictionary.
|
||||
"""
|
||||
if not path.exists():
|
||||
return {
|
||||
"error": "not_found",
|
||||
@@ -36,6 +52,9 @@ class MCPServer:
|
||||
# ------------------------------------------------------------------
|
||||
|
||||
def _register_resources(self) -> None:
|
||||
"""
|
||||
Register MCP resources for index, nav, and individual modules.
|
||||
"""
|
||||
@self.app.resource("docs://index")
|
||||
def index():
|
||||
return self._read_json(self.mcp_root / "index.json")
|
||||
@@ -55,6 +74,9 @@ class MCPServer:
|
||||
# ------------------------------------------------------------------
|
||||
|
||||
def _register_tools(self) -> None:
|
||||
"""
|
||||
Register high-level MCP tools for diagnostics.
|
||||
"""
|
||||
@self.app.tool()
|
||||
def ping() -> str:
|
||||
return "pong"
|
||||
|
||||
Reference in New Issue
Block a user