AWS Labs Code Documentation Generation MCP Server
A Model Context Protocol (MCP) server that automatically analyzes repository structure and generates comprehensive documentation for code projects. This server uses repomix to extract project structure and creates tailored documentation based on project type.
Architecture
How the Server Works
The code-doc-gen-mcp-server follows this workflow:
- prepare_repository:
- Uses RepomixManager to analyze a project directory
- Runs
repomix
to generate an XML representation of the repo - Extracts directory structure from this XML
-
Returns a ProjectAnalysis with the directory structure
-
create_context:
-
Creates a DocumentationContext with the ProjectAnalysis
-
plan_documentation:
- Uses the directory structure from DocumentationContext
-
Creates a DocumentationPlan with document structure and sections
-
generate_documentation:
- Generates document templates based on the plan
Key Components
- RepomixManager: Manages the execution of repomix and parses its XML output to extract directory structure
- DocumentationContext: Central state container that tracks project info and documentation progress
- ProjectAnalysis: Data structure containing analyzed project metadata (languages, dependencies, etc.)
- DocumentationPlan: Structured plan for document generation with section outlines
- DocumentGenerator: Creates actual document templates based on the plan
Features
- Project Structure Analysis: Uses repomix to analyze repository structure and extract key components
- Content Organization: Creates appropriately structured documentation based on project type
- Multiple Document Types: Supports README, API docs, backend docs, frontend docs, and more
- Integration with Other MCP Servers: Works with AWS Diagram MCP server
- Custom Document Templates: Templates for different document types with appropriate sections
Prerequisites
- Install
uv
from Astral or the GitHub README - Install Python using
uv python install 3.10
- Install
repomix
usingpip install repomix>=0.2.6
Installation
This MCP server can be added to your AWS AI assistants via the appropriate MCP configuration file:
{
"mcpServers": {
"awslabs.code-doc-gen-mcp-server": {
"command": "uvx",
"args": ["awslabs.code-doc-gen-mcp-server@latest"],
"env": {
"FASTMCP_LOG_LEVEL": "ERROR"
},
"disabled": false,
"autoApprove": []
}
}
}
Core Concepts
DocumentationContext
The DocumentationContext
class maintains the state of the documentation process throughout its lifecycle:
project_name
: Name of the project being documentedworking_dir
: Working directory for the project (source code location)repomix_path
: Path where documentation files will be generatedstatus
: Current status of the documentation processcurrent_step
: Current step in the documentation workflowanalysis_result
: Contains the ProjectAnalysis with project metadata
ProjectAnalysis
The ProjectAnalysis
class contains detailed information about the project:
project_type
: Type of project (e.g., "Web Application", "CLI Tool")features
: Key capabilities and functions of the projectfile_structure
: Project organization with directory structuredependencies
: Project dependencies with versionsprimary_languages
: Programming languages used in the projectapis
(optional): API endpoint detailsbackend
(optional): Backend implementation detailsfrontend
(optional): Frontend implementation details
Tools
prepare_repository
async def prepare_repository(
project_root: str = Field(..., description='Path to the code repository'),
ctx: Context = None,
) -> ProjectAnalysis
This tool: 1. Extracts directory structure from the repository using repomix 2. Returns a ProjectAnalysis template for the MCP client to fill 3. Provides directory structure in file_structure["directory_structure"]
The MCP client then: 1. Reviews the directory structure 2. Uses read_file to examine key files 3. Fills out the ProjectAnalysis fields 4. Sets has_infrastructure_as_code=True if CDK/Terraform code is detected
create_context
async def create_context(
project_root: str = Field(..., description='Path to the code repository'),
analysis: ProjectAnalysis = Field(..., description='Completed ProjectAnalysis'),
ctx: Context = None,
) -> DocumentationContext
Creates a DocumentationContext from the completed ProjectAnalysis.
plan_documentation
async def plan_documentation(
doc_context: DocumentationContext,
ctx: Context,
) -> DocumentationPlan
Creates a documentation plan based on the project analysis, determining what document types are needed and creating appropriate document structures.
generate_documentation
async def generate_documentation(
plan: DocumentationPlan,
doc_context: DocumentationContext,
ctx: Context,
) -> List[GeneratedDocument]
Generates document structures with sections for the MCP client to fill with content.
Integration with Other MCP Servers
This MCP server is designed to work with:
- AWS Diagram MCP Server: For generating architecture diagrams
- AWS CDK MCP Server: For documenting CDK infrastructure code
License
This project is licensed under the Apache License, Version 2.0. See the LICENSE file for details.