MCP server for automatic Python package documentation context
Project description
AutoDocs MCP Server
Intelligent documentation context provider for AI assistants
AutoDocs MCP Server automatically provides AI assistants with contextual, version-specific documentation for Python project dependencies. It uses intelligent dependency resolution to include both the requested package and its most relevant dependencies, giving AI assistants comprehensive context for accurate code assistance.
✨ Features
🧠 Phase 4: Dependency Context System
- Smart dependency resolution with relevance scoring for major frameworks
- AI-optimized documentation extraction with token management
- Concurrent fetching of dependency documentation (3-5 second response times)
- Contextual intelligence - includes 3-8 most relevant dependencies automatically
🛠️ Core Functionality
- Automatic dependency scanning from pyproject.toml files
- Version-specific caching for optimal performance
- Graceful degradation with partial results on failures
- FastMCP integration for seamless AI tool compatibility
🎯 Intelligent Context
- Framework-aware: Special handling for FastAPI, Django, Flask ecosystems
- Token-aware: Respects context window limits (30k tokens default)
- Performance-optimized: Concurrent requests with caching
- Configurable scope: Primary-only, runtime deps, or smart context
🚀 Installation
From PyPI (Recommended)
# Using uv (recommended)
uv tool install autodoc-mcp
# Using pip
pip install autodoc-mcp
For Development
# Clone and install
git clone https://github.com/bradleyfay/autodoc-mcp.git
cd autodoc-mcp
uv sync --all-extras
# Run tests
uv run pytest
# Start development server
uv run python -m src.autodocs_mcp.main
🔌 Usage
MCP Client Configuration
Cursor Desktop
Add to your Cursor settings (Cmd+, → Extensions → Rules for AI → MCP Servers):
{
"mcpServers": {
"autodoc-mcp": {
"command": "uv",
"args": ["run", "--from", "autodoc-mcp", "autodocs-mcp"],
"env": {
"AUTODOCS_CACHE_DIR": "~/.autodocs/cache"
}
}
}
}
Claude Desktop
Add to your claude_desktop_config.json:
{
"mcpServers": {
"autodoc-mcp": {
"command": "autodocs-mcp",
"env": {
"AUTODOCS_CACHE_DIR": "~/.autodocs/cache"
}
}
}
}
Other MCP Clients
{
"mcpServers": {
"autodoc-mcp": {
"command": "python",
"args": ["-m", "autodocs_mcp.main"],
"cwd": "/path/to/autodoc-mcp",
"env": {
"AUTODOCS_CACHE_DIR": "~/.autodocs/cache"
}
}
}
}
Testing Your Setup
-
Start the MCP server manually to test:
# Should show FastMCP startup screen uv run --from autodoc-mcp autodocs-mcp
-
Test in your AI client:
- Ask: "What packages are available in this project?" (uses
scan_dependencies) - Ask: "Tell me about the FastAPI package with its dependencies" (uses
get_package_docs_with_context)
- Ask: "What packages are available in this project?" (uses
🛠️ Available MCP Tools
scan_dependencies
Scans project dependencies from pyproject.toml files with graceful error handling.
Parameters:
project_path(optional): Path to project directory (defaults to current directory)
Returns:
- Project metadata and dependency specifications
- Graceful degradation info for malformed dependencies
- Success/failure counts and error details
Example:
# AI Assistant can call this to understand your project
{
"success": true,
"project_name": "my-fastapi-app",
"total_dependencies": 12,
"dependencies": [
{"name": "fastapi", "version_constraint": ">=0.100.0"},
{"name": "pydantic", "version_constraint": "^2.0.0"}
]
}
get_package_docs_with_context ⭐ Main Feature
Retrieves comprehensive documentation context including the requested package and its most relevant dependencies.
Parameters:
package_name(required): Primary package to documentversion_constraint(optional): Version constraint for primary packageinclude_dependencies(optional): Include dependency context (default: true)context_scope(optional): "primary_only", "runtime", or "smart" (default: "smart")max_dependencies(optional): Maximum dependencies to include (default: 8)max_tokens(optional): Token budget for context (default: 30000)
Returns:
- Rich documentation context with primary package + key dependencies
- Performance metrics (response times, cache hits)
- Token estimates and context scope information
Example:
# AI Assistant gets comprehensive context
{
"success": true,
"context": {
"primary_package": {
"name": "fastapi",
"version": "0.104.1",
"summary": "FastAPI framework, high performance...",
"key_features": ["Automatic API docs", "Type hints", "Async support"],
"main_classes": ["FastAPI", "APIRouter", "Depends"],
"usage_examples": "from fastapi import FastAPI\napp = FastAPI()..."
},
"runtime_dependencies": [
{
"name": "pydantic",
"version": "2.5.1",
"why_included": "Required by fastapi",
"summary": "Data validation using Python type hints",
"key_features": ["Data validation", "Serialization"]
},
{
"name": "starlette",
"version": "0.27.0",
"why_included": "Required by fastapi",
"summary": "Lightweight ASGI framework/toolkit"
}
],
"context_scope": "with_runtime (2 deps)",
"total_packages": 3,
"token_estimate": 15420
},
"performance": {
"total_time": 0.89,
"cache_hits": 1,
"cache_misses": 2
}
}
get_package_docs (Legacy)
Retrieves basic documentation for a single package without dependency context.
Parameters:
package_name(required): Package to documentversion_constraint(optional): Version constraintquery(optional): Filter documentation sections
Note: For rich context with dependencies, use get_package_docs_with_context instead.
refresh_cache
Clears the local documentation cache.
Returns:
- Statistics about cleared entries and freed space
get_cache_stats
Gets statistics about the documentation cache.
Returns:
- Cache statistics (total entries, size, hit rates)
- List of cached packages
⚙️ Configuration
Environment Variables
AUTODOCS_CACHE_DIR: Cache directory (default:~/.autodocs/cache)AUTODOCS_MAX_DEPENDENCY_CONTEXT: Max dependencies in context (default: 8)AUTODOCS_MAX_CONTEXT_TOKENS: Token budget for context (default: 30000)AUTODOCS_LOG_LEVEL: Logging level (default: INFO)
Advanced Configuration
# Increase context size for complex projects
export AUTODOCS_MAX_DEPENDENCY_CONTEXT=12
export AUTODOCS_MAX_CONTEXT_TOKENS=50000
# Use custom cache location
export AUTODOCS_CACHE_DIR="/tmp/autodocs-cache"
# Enable debug logging
export AUTODOCS_LOG_LEVEL=DEBUG
🏗️ Architecture
Intelligent Dependency Resolution
- Relevance scoring: Core frameworks (FastAPI, Django) get priority
- Package relationships: Framework-specific dependency boosts
- Token awareness: Respects context window limits
- Graceful degradation: Partial results when some deps fail
Performance Optimizations
- Version-based caching: Immutable package versions cached indefinitely
- Concurrent fetching: Up to 5 simultaneous PyPI requests
- Smart timeouts: 15-second max for dependency fetching
- Circuit breakers: Prevents cascade failures
AI-Optimized Output
- Structured data: Clean JSON with consistent formatting
- Token estimation: Helps AI clients manage context windows
- Relevance filtering: Only includes most important information
- Context metadata: Clear indication of what was included/excluded
🧪 Testing
# Run all tests
uv run pytest
# Run with coverage
uv run pytest --cov=src --cov-report=html
# Run linting
uv run ruff check
# Type checking
uv run mypy src
# Integration test with real packages
uv run python -c "
import asyncio
from src.autodocs_mcp.main import initialize_services
from src.autodocs_mcp.core.context_fetcher import create_context_fetcher
from src.autodocs_mcp.core.cache_manager import FileCacheManager
from pathlib import Path
async def test():
await initialize_services()
cache_manager = FileCacheManager(Path.home() / '.autodocs' / 'cache')
await cache_manager.initialize()
context_fetcher = await create_context_fetcher(cache_manager)
context, metrics = await context_fetcher.fetch_package_context('fastapi')
print(f'FastAPI context: {len(context.runtime_dependencies)} deps, {context.token_estimate} tokens')
asyncio.run(test())
"
🤔 Troubleshooting
Common Issues
"Context fetcher not initialized" error:
- Ensure the MCP server started successfully
- Check logs for initialization errors
- Verify network connectivity to PyPI
"No dependencies found" for known packages:
- Check if the package has dependencies in its PyPI metadata
- Try with
context_scope="smart"parameter - Some packages have optional-only dependencies
Slow response times:
- Dependencies are fetched on first request (cache miss)
- Subsequent requests use cache (much faster)
- Network latency to PyPI affects first-time fetching
MCP client can't connect:
- Verify the command path in your MCP configuration
- Check if
autodoc-mcppackage is installed correctly - Test manual server startup:
uv run --from autodoc-mcp autodocs-mcp
Debug Mode
# Enable debug logging
export AUTODOCS_LOG_LEVEL=DEBUG
# Run server manually to see debug output
uv run --from autodoc-mcp autodocs-mcp
# Check cache contents
ls ~/.autodocs/cache/
🔮 Roadmap
- Multi-language support: Expand beyond Python packages
- Enhanced relevance scoring: Machine learning-based dependency ranking
- Semantic search: Query-based documentation filtering
- Performance monitoring: Built-in metrics and alerting
📄 License
MIT License - see LICENSE for details.
🤝 Contributing
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Follow conventional commits (
feat:,fix:,docs:, etc.) - Run tests and linting (
uv run pytest && uv run ruff check) - Create a Pull Request
Built with ❤️ using FastMCP
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 autodoc_mcp-0.3.0.tar.gz.
File metadata
- Download URL: autodoc_mcp-0.3.0.tar.gz
- Upload date:
- Size: 76.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fcd6b41a9e92ba16358182e676bbb75a498baf3f0b32adf6d6db0648c5ea6e5a
|
|
| MD5 |
fe000a93a24c289f171088019870947f
|
|
| BLAKE2b-256 |
89f9c63a00edfcd8fb572ac525d6e3ac4836e7069ff4b28b1b67c537a881fdd8
|
Provenance
The following attestation bundles were made for autodoc_mcp-0.3.0.tar.gz:
Publisher:
ci.yml on bradleyfay/autodoc-mcp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
autodoc_mcp-0.3.0.tar.gz -
Subject digest:
fcd6b41a9e92ba16358182e676bbb75a498baf3f0b32adf6d6db0648c5ea6e5a - Sigstore transparency entry: 370605223
- Sigstore integration time:
-
Permalink:
bradleyfay/autodoc-mcp@83561f35a8ee5ac1e7297092e81927a1dd8e4864 -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/bradleyfay
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@83561f35a8ee5ac1e7297092e81927a1dd8e4864 -
Trigger Event:
push
-
Statement type:
File details
Details for the file autodoc_mcp-0.3.0-py3-none-any.whl.
File metadata
- Download URL: autodoc_mcp-0.3.0-py3-none-any.whl
- Upload date:
- Size: 49.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
616605b11805bb5caeeb3a68ce105dd5b502819fafe9389c8f11405e464b4a95
|
|
| MD5 |
11a0f5048002e87bbc987bd0449b6f2f
|
|
| BLAKE2b-256 |
d8964e80f218ff4200a870241f66c9920220268d8cea91e98edb72194a98906f
|
Provenance
The following attestation bundles were made for autodoc_mcp-0.3.0-py3-none-any.whl:
Publisher:
ci.yml on bradleyfay/autodoc-mcp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
autodoc_mcp-0.3.0-py3-none-any.whl -
Subject digest:
616605b11805bb5caeeb3a68ce105dd5b502819fafe9389c8f11405e464b4a95 - Sigstore transparency entry: 370605244
- Sigstore integration time:
-
Permalink:
bradleyfay/autodoc-mcp@83561f35a8ee5ac1e7297092e81927a1dd8e4864 -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/bradleyfay
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@83561f35a8ee5ac1e7297092e81927a1dd8e4864 -
Trigger Event:
push
-
Statement type: