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
Metadata
Release files for fastapi-report 1.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| fastapi_report-1.0.2.tar.gz | 60.7 kB | With provenance | Details for fastapi_report-1.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| fastapi_report-1.0.2-py3-none-any.whl | Python 3 | none | any | Details for fastapi_report-1.0.2-py3-none-any.whl |
Total release size: 103.9 kB
Release files / fastapi_report-1.0.2.tar.gz
| Download URL | fastapi_report-1.0.2.tar.gz |
|---|---|
| Size | 60.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
990b6411822f27699ef87075965387608431ed3b735f459fcd4d64bb307fdb7e
|
|
BLAKE2b-256 checksum How to use checksums |
3cd02a1af123150f465ed98226045ba4408c0c2c98bd884fc604bef79f3102b8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 11, 2025.
Transparency logRelease files / fastapi_report-1.0.2-py3-none-any.whl
| Download URL | fastapi_report-1.0.2-py3-none-any.whl |
|---|---|
| Size | 43.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1d6aa2365d2955bbe38846076dabd1279e9966731ad6cb226ed92886092f912a
|
|
BLAKE2b-256 checksum How to use checksums |
86055918af3cf80b998f2a924ac40ba204da95227aede16159e1e35968bb1a0a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 11, 2025.
Transparency logSecurity for fastapi-report 1.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for fastapi_report-1.0.2.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 11, 2025.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.