Skip to main content

Model Context Protocol (MCP) server providing documentation and code analysis for Python packages

Project description

MCPyDoc - Python Package Documentation MCP Server

CI PyPI version Python 3.9+ License: MIT

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

  1. Install MCPyDoc in the Python interpreter PyCharm will use for AI Assistant:

    pip install mcpydoc
    

    💡 If you use multiple interpreters/virtual environments, make sure mcpydoc is installed in the same environment PyCharm uses for MCP servers. You can check or change this in Settings → Project → Python Interpreter.

  2. Open MCP configuration: Go to Settings → Tools → AI Assistant → Model Context Protocol (MCP).

  3. 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
  4. 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 uvx instead of pipx - 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

  1. Install MCPyDoc:

    pip install mcpydoc
    
  2. 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 python3 instead of python. To check which command is available, run python --version or python3 --version in 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:

  1. MCPYDOC_PYTHON_PATH environment variable (manual override)
  2. VIRTUAL_ENV environment variable (activated virtual environment)
  3. Virtual environment in current directory (.venv/, venv/, env/, .env/)
  4. Poetry environments (detected via poetry.toml or pyproject.toml)
  5. System Python (if not in pipx/uvx isolated environment)
  6. 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:

  1. Activate your virtual environment before starting your AI assistant:

    source .venv/bin/activate  # Linux/macOS
    .venv\Scripts\activate     # Windows
    
  2. 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
    
  3. Use the MCPYDOC_PYTHON_PATH environment variable to point to your Python environment:

    export MCPYDOC_PYTHON_PATH=/path/to/your/.venv
    
  4. 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_PATH in your MCP server configuration

📝 License

MIT License - see LICENSE file for details.

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests
  5. Run the test suite
  6. Submit a pull request

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mcpydoc-1.3.0.tar.gz (853.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mcpydoc-1.3.0-py3-none-any.whl (31.8 kB view details)

Uploaded Python 3

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

Hashes for mcpydoc-1.3.0.tar.gz
Algorithm Hash digest
SHA256 fb67d178df629a7cf63c398cca29b138743018738747c4b1e095d8a2bc045ecd
MD5 cfad54183c6cf1d959b2a69cf283de35
BLAKE2b-256 7c12d71c3e0a66740cb8aa8a244dee2481d92ed2c0815c27c85202418c0debb7

See more details on using hashes here.

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

Hashes for mcpydoc-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1dc3a67c8a6836cff6a574185cc894c2aa8b76edac7109459a576f2e07d99dd8
MD5 da386f689fe37f0f71a7e54f9462977a
BLAKE2b-256 32d96089cd04e4b08ed74b449abb880315f1090b393dcc2b77dd782b4dabed0b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page