File size: 5,633 Bytes
c00f77a
d12bff5
 
 
 
c00f77a
 
 
 
 
 
d12bff5
 
 
 
c00f77a
 
 
d12bff5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
---
title: Agents MCP Hackathon
emoji: 🐠
colorFrom: indigo
colorTo: red
sdk: gradio
sdk_version: 5.33.1
app_file: app.py
pinned: false
license: mit
short_description: Automatic documentation generator for GitHub or zipped repos
tags:
    - mcp-server-track
    - gradio-app
    - hackathon
---

Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference

# πŸ€– AutoDocs – MCP Server for Automatic Code Documentation

Automatic documentation generator for GitHub or zipped repositories.

**AutoDocs** is a Gradio-based application that serves as an **MCP Server (Track 1)** for the Agents & MCP Hackathon.  
It automatically generates documentation, README files, and requirements.txt for any Python code repository provided via GitHub URL or ZIP file.

---

## πŸš€ Features

- πŸ“¦ Upload and process any ZIP file of a code repo.
- 🌐 Clone and process any GitHub repository.
- πŸ“„ Auto-generate:
  - Docstrings (Google style)
  - Typings
  - Inline code comments
  - `requirements.txt`
  - `README.md` + `index.md`
- 🧠 Integrated AI agent to ask questions about the code.

---

## πŸ› οΈ MCP Server Information

βœ… This Space is an **MCP Server (Track 1)** compliant with the MCP protocol.

MCP Metadata (`.well-known/mcp.yaml`)

## πŸ’» Usage (as MCP Client)

This server can be queried via Claude Desktop, Cursor, or Tiny Agents MCP clients.

Example with Tiny Agents: 

```bash
tiny-agents call --url https://huggingface.co/spaces/your-space-name
```

## Project Description

AutoDocs is a tool designed to automatically generate documentation, requirements files, and README files for Python projects. It leverages generative AI to add helpful comments and type annotations to your code, making it easier to understand and maintain.  It can process a local repository, a GitHub repository via URL, or a zipped source code directory.

## Installation

1.  **Clone the repository:**

    ```bash
    git clone <repository_url>
    cd <repository_name>
    ```

2.  **Create a virtual environment (recommended):**

    ```bash
    python3 -m venv venv
    source venv/bin/activate  # On Linux/macOS
    venv\Scripts\activate  # On Windows
    ```

3.  **Install the dependencies:**

    ```bash
    pip install -r requirements.txt
    ```

4.  **Set up the environment variables:**

    *   Create a `.env` file in the root directory of the project.
    *   Add your Google Gemini API key to the `.env` file:

        ```
        GOOGLE_API_KEY=<your_google_api_key>
        ```

        **Note:**  You will need a Google Gemini API key to use the documentation generation features. You can obtain one from the Google AI Studio.

## Usage

### Using the `app.py` module:

The `app.py` module contains the core logic for processing a repository and generating documentation.

```python
import gradio as gr
import os
import shutil
import tempfile
import zipfile
import subprocess
import uuid

from doc_generator import generate_documented_code, generate_requirements_txt
from readme_generator import generate_readme_from_zip


def process_repo(repo_path: str, zip_output_name: str = "AutoDocs") -> str:
    """Processes a repository to generate documentation, requirements, and a README.

    Args:
        repo_path: The path to the repository.
        zip_output_name: The name of the output zip file (default: "AutoDocs").

    Returns:
        The path to the generated zip file.
    """
    with tempfile.TemporaryDirectory() as temp_output_dir:
        # Iterate through all Python files in the repository and generate documented code.
        for root, _, files in os.walk(repo_path):
            for file in files:
                if file.endswith(".py"):
                    file_path = os.path.join(root, file)
                    generate_documented_code(file_path, file_path)


# Example Usage (not executable directly from this file, intended for integration):
# repo_path = "/path/to/your/repository"
# output_zip = process_repo(repo_path)
# print(f"Generated documentation zip file: {output_zip}")
```

### Using the FastAPI server (`mcp_server.py`):

The `mcp_server.py` module provides a FastAPI server with endpoints for generating documentation from a GitHub URL or a zip file upload.

1.  **Run the FastAPI server:**

    ```bash
    uvicorn mcp_server:app --reload
    ```

2.  **Access the endpoints:**

    *   **Generate documentation from a GitHub URL:**

        ```
        POST /generate_docs
        Content-Type: multipart/form-data

        github_url=<your_github_url>
        ```

    *   **Generate documentation from a zip file upload:**

        ```
        POST /generate_docs
        Content-Type: multipart/form-data

        zip_file=@<path_to_your_zip_file>
        ```

    *   **MCP Manifest (/.well-known/mcp.yaml):**

        ```
        GET /.well-known/mcp.yaml
        ```
        This endpoint serves the MCP manifest file.

## Features

*   **Automated Documentation Generation:** Uses generative AI to add comments and type annotations to Python code.
*   **Requirements File Generation:**  Automatically creates a `requirements.txt` file listing the project dependencies.
*   **README Generation:**  Generates a basic README file based on the project structure and code content.
*   **GitHub URL Processing:**  Can process repositories directly from GitHub URLs.
*   **Zip File Upload:**  Supports uploading zip files of source code for documentation generation.
*   **MCP Manifest Serving:** Includes an endpoint to serve an MCP (Meta Control Protocol) manifest.

## Authors

Aguet Theau, Azdad Bilal.

## License

MIT License.