Model Context Protocol (MCP) server providing documentation and code analysis for Python packages
Project description
MCPyDoc - Python Package Documentation MCP Server
AI assistants often hallucinate when code depends on private or unfamiliar Python packages: guessed APIs, wrong signatures, and outdated usage that breaks at runtime. MCPyDoc fixes that by giving your assistant real-time access to the actual documentation and source code of the Python packages installed in your environment.
MCPyDoc is a Model Context Protocol (MCP) server that provides comprehensive documentation and code analysis capabilities for Python packages. It enables AI agents like Cline and GitHub Copilot to understand and work with Python codebases more effectively.
✨ Features
- 📚 Package Documentation: Get comprehensive docs for any Python package
- 🔍 Symbol Search: Find classes, functions, and modules by pattern
- 💻 Source Code Access: Retrieve actual implementation code
- 🏗️ Structure Analysis: Analyze complete package architecture
- 🔧 Type Hints: Extract and analyze type annotations
- 📖 Docstring Parsing: Support for Google, NumPy, and Sphinx formats
- 🏃 High Performance: Efficient caching and optimized operations
- 🛡️ Error Handling: Robust error management and validation
🚀 Quick Start
VS Code Extension
For a zero-config setup inside VS Code, install the MCPyDoc extension.
It registers the server using the MCP Server Definition Provider API and
automatically ensures the mcpydoc package is available when the server starts.
Installation for PyCharm AI Assistant
-
Install MCPyDoc in the Python interpreter PyCharm will use for AI Assistant:
pip install mcpydoc
💡 If you use multiple interpreters/virtual environments, make sure
mcpydocis installed in the same environment PyCharm uses for MCP servers. You can check or change this in Settings → Project → Python Interpreter. -
Open MCP configuration: Go to Settings → Tools → AI Assistant → Model Context Protocol (MCP).
-
Add a new server:
-
Click Add → As JSON, and paste:
{ "mcpServers": { "mcpydoc": { "command": "python", "args": ["-m", "mcpydoc"], "env": {}, "description": "Python package documentation and code analysis server" } } }
Or use Add → Command and fill:
- Command:
python - Arguments:
-m mcpydoc
- Command:
-
-
Apply and restart AI Assistant: PyCharm will launch MCPyDoc automatically when the AI Assistant starts.
Installation for Other Platforms
Option 1: No Installation Required (Recommended)
Use pipx to run MCPyDoc without installing it first:
{
"mcpServers": {
"mcpydoc": {
"command": "pipx",
"args": ["run", "mcpydoc"],
"description": "Python package documentation and code analysis server"
}
}
}
💡 Alternative: You can also use
uvxinstead ofpipx- just replace"command": "pipx"with"command": "uvx"and"args": ["run", "mcpydoc"]with"args": ["mcpydoc"].
Alternatively, if you prefer to install it once:
pipx install mcpydoc
Then use:
{
"mcpServers": {
"mcpydoc": {
"command": "mcpydoc",
"args": [],
"description": "Python package documentation and code analysis server"
}
}
}
Option 2: Traditional pip Installation
-
Install MCPyDoc:
pip install mcpydoc
-
Add to your MCP configuration:
{ "mcpServers": { "mcpydoc": { "command": "python", "args": ["-m", "mcpydoc"], "env": {}, "description": "Python package documentation and code analysis server" } } }
💡 Platform Note: On some Linux/macOS systems, you may need to use
python3instead ofpython. To check which command is available, runpython --versionorpython3 --versionin your terminal.
Development Installation
If you want to contribute or modify the source code:
git clone https://github.com/amit608/MCPyDoc.git
cd MCPyDoc
pip install -e .[dev]
📊 Supported Package Types
- ✅ Standard Library - Built-in modules (
json,os,sys, etc.) - ✅ Third-Party Packages - pip-installed packages
- ✅ Local Packages - Development packages in current environment
- ✅ Virtual Environments - Proper path resolution
🔧 Environment Detection
MCPyDoc automatically detects and uses the correct Python environment for your project, even when installed via pipx or uvx. This ensures it can access packages installed in your working repository.
How It Works
MCPyDoc searches for Python environments in the following order:
MCPYDOC_PYTHON_PATHenvironment variable (manual override)VIRTUAL_ENVenvironment variable (activated virtual environment)- Virtual environment in current directory (
.venv/,venv/,env/,.env/) - Poetry environments (detected via
poetry.tomlorpyproject.toml) - System Python (if not in pipx/uvx isolated environment)
- Current environment (fallback)
Configuration
If automatic detection doesn't work for your setup, you can manually specify the Python environment:
# Set the environment variable before running your AI assistant
export MCPYDOC_PYTHON_PATH=/path/to/your/project/.venv
# Or add it to your MCP configuration
{
"mcpServers": {
"mcpydoc": {
"command": "python",
"args": ["-m", "mcpydoc"],
"env": {
"MCPYDOC_PYTHON_PATH": "/path/to/your/project/.venv"
}
}
}
}
🔍 Troubleshooting
Package Not Found Errors
If MCPyDoc can't find a package that you know is installed:
-
Activate your virtual environment before starting your AI assistant:
source .venv/bin/activate # Linux/macOS .venv\Scripts\activate # Windows
-
Create a virtual environment in your project if you don't have one:
python -m venv .venv source .venv/bin/activate pip install your-package
-
Use the
MCPYDOC_PYTHON_PATHenvironment variable to point to your Python environment:export MCPYDOC_PYTHON_PATH=/path/to/your/.venv
-
Check which environments MCPyDoc is searching: The error message will list all searched paths and provide context-aware suggestions.
pipx/uvx Installations
When MCPyDoc is installed via pipx or uvx, it runs in an isolated environment. The environment detection feature automatically handles this by:
- Detecting when running in a pipx/uvx isolated environment
- Prioritizing your project's virtual environment over the isolated environment
- Providing clear error messages with setup instructions when packages aren't found
For best results with pipx/uvx:
- Work in a directory with a virtual environment (
.venv,venv, etc.) - Or activate your project's virtual environment before starting the AI assistant
- Or set
MCPYDOC_PYTHON_PATHin your MCP server configuration
📝 License
MIT License - see LICENSE file for details.
🤝 Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Run the test suite
- Submit a pull request
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 mcpydoc-1.3.0.tar.gz.
File metadata
- Download URL: mcpydoc-1.3.0.tar.gz
- Upload date:
- Size: 853.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fb67d178df629a7cf63c398cca29b138743018738747c4b1e095d8a2bc045ecd
|
|
| MD5 |
cfad54183c6cf1d959b2a69cf283de35
|
|
| BLAKE2b-256 |
7c12d71c3e0a66740cb8aa8a244dee2481d92ed2c0815c27c85202418c0debb7
|
File details
Details for the file mcpydoc-1.3.0-py3-none-any.whl.
File metadata
- Download URL: mcpydoc-1.3.0-py3-none-any.whl
- Upload date:
- Size: 31.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1dc3a67c8a6836cff6a574185cc894c2aa8b76edac7109459a576f2e07d99dd8
|
|
| MD5 |
da386f689fe37f0f71a7e54f9462977a
|
|
| BLAKE2b-256 |
32d96089cd04e4b08ed74b449abb880315f1090b393dcc2b77dd782b4dabed0b
|