Universal FastAPI documentation generator - automatically document REST endpoints and MCP tools
Project description
FastAPI Report
Automatically generate comprehensive documentation for FastAPI applications including REST API endpoints and MCP (Model Context Protocol) tools.
Features
- 🔍 Automatic Discovery: Introspects FastAPI applications to extract all endpoints and MCP tools
- 📝 Multiple Formats: Generate documentation in JSON, Markdown, and HTML formats
- 🌐 Dual Mode Support:
- Module Mode: Direct Python introspection of local FastAPI applications
- URL Mode: Remote discovery via HTTP using OpenAPI spec and MCP protocol
- 🛠️ MCP Protocol Support: Discovers MCP tools from running servers using the MCP JSON-RPC protocol
- 📊 Rich Metadata: Captures parameters, types, constraints, descriptions, request/response schemas
- 🎨 Beautiful Output: Styled HTML with navigation, formatted Markdown, and structured JSON
Installation
pip install "git+https://github.com/maat16/fastapi-report.git"
Quick Start
Command Line Usage
Analyze a running server (URL mode):
# Discover both REST endpoints and MCP tools from a running server
fastapi-report --server http://localhost:8000 --format all
# Generate only JSON documentation
fastapi-report --server http://localhost:8000 --format json
# Specify custom output directory
fastapi-report --server http://localhost:8000 --format all --output ./docs
Analyze a Python module (Module mode):
# Analyze a local FastAPI module
fastapi-report --server my_api_module --format all
# Analyze nested module
fastapi-report --server app.main --format md
Python API Usage
from fastapi_report.reporter import EndpointReporter
# URL mode - analyze running server
reporter = EndpointReporter("http://localhost:8000")
report = reporter.generate_report()
print(f"Found {len(report.endpoints)} endpoints")
print(f"Found {len(report.mcp_tools)} MCP tools")
# Generate documentation files
reporter.output_report(report, ["json", "md", "html"], "./output")
# Module mode - analyze local module
reporter = EndpointReporter("my_api_module")
report = reporter.generate_report()
How It Works
Module Mode
When you provide a Python module name, the tool:
- Dynamically imports the module
- Extracts the FastAPI application instance
- Introspects routes using FastAPI's internal APIs
- Discovers MCP tools from the MCP instance (if available)
- Generates comprehensive documentation
URL Mode
When you provide a URL, the tool:
- Fetches the OpenAPI specification from
/openapi.json - Parses REST endpoints from the OpenAPI spec
- Discovers MCP tools using the MCP protocol:
- Calls
/mcpwithinitializemethod to establish a session - Extracts
Mcp-Session-Idfrom response headers - Calls
/mcpwithtools/listmethod using the session ID - Parses tool metadata (name, description, input schema)
- Calls
- Generates documentation from discovered information
MCP Protocol Discovery
The tool supports discovering MCP tools from running servers using the MCP JSON-RPC protocol:
# The tool automatically:
# 1. Initializes MCP session
POST /mcp
{
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {
"protocolVersion": "2024-11-05",
"capabilities": {},
"clientInfo": {"name": "fastapi-report", "version": "1.0.0"}
}
}
# 2. Lists available tools
POST /mcp
Headers: Mcp-Session-Id: <session-id>
{
"jsonrpc": "2.0",
"id": 2,
"method": "tools/list",
"params": {"cursor": null}
}
Output Formats
JSON
Structured JSON with complete metadata:
{
"server_name": "My API",
"server_version": "1.0.0",
"endpoints": [...],
"mcp_tools": [...],
"openapi_spec": {...},
"generated_at": "2024-01-01T12:00:00"
}
Markdown
Human-readable documentation with tables and code blocks:
# My API
## REST Endpoints
### GET /users
Get all users
**Parameters:**
| Name | Type | Required | Description |
|------|------|----------|-------------|
| limit | int | No | Maximum results |
## MCP Tools
### get_users
Retrieve user list via MCP
HTML
Styled, browsable web page with:
- Navigation sidebar
- Syntax-highlighted code
- Collapsible sections
- Responsive design
Development
Setup
# Clone the repository
git clone https://github.com/maat16/fastapi-report.git
cd fastapi-report
# Install in development mode
pip install -e .
# Install development dependencies
pip install -r requirements-dev.txt
Running Tests
# Run all tests
pytest
# Run with coverage
pytest --cov=fastapi_report --cov-report=html
# Run specific test file
pytest tests/test_mcp_discovery.py -v
Test Coverage
The package includes comprehensive tests:
- Property-based tests using Hypothesis for data models
- Unit tests for all discovery components
- Integration tests for formatters and reporters
- Mock-based tests for MCP protocol discovery
Current test coverage: 46 tests, all passing
Requirements
- Python 3.8+
- FastAPI 0.100.0+
- Pydantic 2.0.0+
- Requests 2.28.0+
Use Cases
- API Documentation: Generate up-to-date documentation automatically
- CI/CD Integration: Include in pipelines to validate API changes
- Development: Quick reference for available endpoints and tools
- Testing: Verify endpoint metadata and MCP tool configurations
- Comparison: Compare production vs. mock server implementations
Examples
Example 1: Basic Usage
fastapi-report --server http://localhost:8000 --format all
Output:
Analyzing http://localhost:8000 (URL)...
Discovering endpoints and tools...
Found 10 endpoints and 4 MCP tools
Generating documentation in json, md, html format(s)...
✓ Generated JSON report: reports/api_documentation.json
✓ Generated MD report: reports/api_documentation.md
✓ Generated HTML report: reports/api_documentation.html
✓ Documentation generation complete!
Example 2: Module Analysis
fastapi-report --server my_app.main --format md --output ./docs
Example 3: Programmatic Usage
from fastapi_report.reporter import EndpointReporter
from fastapi_report.formatters import MarkdownFormatter
# Generate report
reporter = EndpointReporter("http://localhost:8000")
report = reporter.generate_report()
# Custom formatting
formatter = MarkdownFormatter()
markdown_content = formatter.format(report)
# Save to file
with open("api_docs.md", "w") as f:
f.write(markdown_content)
Contributing
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
License
MIT License - see LICENSE file for details
Changelog
Version 1.0.0
- Initial release
- REST endpoint discovery
- MCP tool discovery (module and URL modes)
- MCP protocol support for remote discovery
- JSON, Markdown, and HTML formatters
- Comprehensive test suite
- CLI and Python API
Support
For issues, questions, or contributions, please visit: https://github.com/maat16/fastapi-report
Acknowledgments
Built with:
- FastAPI - Modern web framework
- Pydantic - Data validation
- Hypothesis - Property-based testing
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fastapi_report-1.0.2.tar.gz.
File metadata
- Download URL: fastapi_report-1.0.2.tar.gz
- Upload date:
- Size: 60.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
990b6411822f27699ef87075965387608431ed3b735f459fcd4d64bb307fdb7e
|
|
| MD5 |
f6ca7a8afbbc03056ef6d5f9b52d9bf3
|
|
| BLAKE2b-256 |
3cd02a1af123150f465ed98226045ba4408c0c2c98bd884fc604bef79f3102b8
|
Provenance
The following attestation bundles were made for fastapi_report-1.0.2.tar.gz:
Publisher:
python-publish.yml on maat16/fastapi-report
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastapi_report-1.0.2.tar.gz -
Subject digest:
990b6411822f27699ef87075965387608431ed3b735f459fcd4d64bb307fdb7e - Sigstore transparency entry: 760570766
- Sigstore integration time:
-
Permalink:
maat16/fastapi-report@da448ec3ab5e47bc0492a6e88bb5cebd81f1f372 -
Branch / Tag:
refs/tags/1.0.2 - Owner: https://github.com/maat16
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@da448ec3ab5e47bc0492a6e88bb5cebd81f1f372 -
Trigger Event:
release
-
Statement type:
File details
Details for the file fastapi_report-1.0.2-py3-none-any.whl.
File metadata
- Download URL: fastapi_report-1.0.2-py3-none-any.whl
- Upload date:
- Size: 43.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1d6aa2365d2955bbe38846076dabd1279e9966731ad6cb226ed92886092f912a
|
|
| MD5 |
162645a25a1b5c93b6b6ca3bef6b2370
|
|
| BLAKE2b-256 |
86055918af3cf80b998f2a924ac40ba204da95227aede16159e1e35968bb1a0a
|
Provenance
The following attestation bundles were made for fastapi_report-1.0.2-py3-none-any.whl:
Publisher:
python-publish.yml on maat16/fastapi-report
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastapi_report-1.0.2-py3-none-any.whl -
Subject digest:
1d6aa2365d2955bbe38846076dabd1279e9966731ad6cb226ed92886092f912a - Sigstore transparency entry: 760570769
- Sigstore integration time:
-
Permalink:
maat16/fastapi-report@da448ec3ab5e47bc0492a6e88bb5cebd81f1f372 -
Branch / Tag:
refs/tags/1.0.2 - Owner: https://github.com/maat16
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@da448ec3ab5e47bc0492a6e88bb5cebd81f1f372 -
Trigger Event:
release
-
Statement type: