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 Code style: black

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

Installation

# Install from PyPI (Recommended)
pip install mcpydoc

# Or install from source
git clone https://github.com/amit608/MCPyDoc.git
cd MCPyDoc
pip install .

Once installed and configured with your AI agent, the server will automatically start when needed.

๐Ÿ”Œ Integration with Cline

Configuration

Add MCPyDoc to your Cline MCP configuration:

{
  "mcpServers": {
    "mcpydoc": {
      "command": "python",
      "args": ["-m", "mcpydoc"],
      "env": {},
      "description": "Python package documentation and code analysis server"
    }
  }
}

Recommended Cline Rules

To help Cline use MCPyDoc effectively, consider adding these rules to your .clinerules file:

# Python Package Analysis Guidelines

## When to Use MCPyDoc Tools

### Always use MCPyDoc when:
- User asks about Python package functionality or capabilities
- Need to understand how to use a specific Python library
- Looking for specific functions or classes in a package
- Want to see source code implementation details
- Need to understand package structure or available modules
- Troubleshooting Python package usage issues

### Recommended workflow:
1. **Start with `analyze_structure`** to understand package organization
2. **Use `search_symbols`** to find relevant functions/classes
3. **Use `get_package_docs`** for comprehensive documentation of packages/modules
4. **Use `get_package_docs` with `module_path`** for specific method/class documentation
5. **Use `get_source_code`** when you need to see implementation details

### For specific method documentation:
- **Option 1**: `get_package_docs` with `module_path` parameter (e.g., `package="requests", module_path="Session.get"`)
- **Option 2**: `search_symbols` to find the method, then `get_package_docs` for details
- **Option 3**: `get_source_code` for the method implementation and its docstring

### Examples of when to use MCPyDoc:
- "I need to understand how to use the SQLAlchemy Session.query() method - show me its documentation and parameters"
- "How do I use requests to make HTTP calls?"
- "What classes are available in the pathlib module?"
- "Show me the source code for json.loads"
- "What functions does the os module provide for file operations?"
- "How do I use pandas for data analysis?"

### Don't use MCPyDoc for:
- Questions about Python language syntax
- General programming concepts
- Non-Python packages or libraries
- Questions already answered in previous context

Place this in your .clinerules file to help Cline automatically use MCPyDoc when working with Python packages.

๐Ÿ“Š 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

๐Ÿ› ๏ธ API Reference

Core Methods

get_module_documentation(package, module_path=None, version=None)

Get comprehensive documentation for a package or specific module.

Parameters:

  • package (str): Package name
  • module_path (str, optional): Dot-separated path to specific module
  • version (str, optional): Specific version to use

Returns: ModuleDocumentationResult

search_package_symbols(package, pattern=None, version=None)

Search for symbols in a package.

Parameters:

  • package (str): Package name
  • pattern (str, optional): Search pattern (case-insensitive)
  • version (str, optional): Specific version to use

Returns: List[SymbolSearchResult]

get_source_code(package, symbol_name, version=None)

Get source code for a specific symbol.

Parameters:

  • package (str): Package name
  • symbol_name (str): Dot-separated path to symbol
  • version (str, optional): Specific version to use

Returns: SourceCodeResult

analyze_package_structure(package, version=None)

Analyze complete package structure.

Parameters:

  • package (str): Package name
  • version (str, optional): Specific version to use

Returns: PackageStructure

๐Ÿ—๏ธ Architecture

MCPyDoc uses a clean, modular architecture:

mcpydoc/
โ”œโ”€โ”€ __init__.py          # Package interface
โ”œโ”€โ”€ __main__.py          # CLI entry point
โ”œโ”€โ”€ server.py            # Core MCPyDoc class
โ”œโ”€โ”€ mcp_server.py        # MCP JSON-RPC server
โ”œโ”€โ”€ analyzer.py          # Package analysis engine
โ”œโ”€โ”€ documentation.py     # Docstring parsing
โ”œโ”€โ”€ models.py            # Pydantic data models
โ”œโ”€โ”€ exceptions.py        # Custom exceptions
โ””โ”€โ”€ utils.py             # Utility functions

Key Components

  • Analyzer: Package introspection and symbol discovery
  • Documentation Parser: Multi-format docstring parsing
  • MCP Server: JSON-RPC protocol implementation
  • Models: Type-safe data structures with Pydantic
  • Exception Handling: Comprehensive error management

๐Ÿ“ˆ Performance

  • Package Info: < 100ms (cached after first request)
  • Symbol Search: < 200ms for most packages
  • Source Retrieval: < 150ms
  • Structure Analysis: < 500ms for typical packages
  • Memory Usage: < 100MB for normal operations

๐Ÿ› Troubleshooting

Common Issues

  1. "Package not found" errors

    • Ensure the package is installed: pip install package_name
    • Check virtual environment activation
  2. Import errors

    • Verify MCPyDoc installation: pip install .
    • Check Python path configuration
  3. Source code unavailable

    • Some built-in functions don't have accessible source
    • This is expected behavior for C extensions

Debug Commands

# Check environment
python -c "import sys; print(f'Python: {sys.version}'); print(f'Prefix: {sys.prefix}')"

# Test basic functionality
python -c "
import asyncio
from mcpydoc import MCPyDoc
async def test():
    mcpydoc = MCPyDoc()
    result = await mcpydoc.get_module_documentation('json')
    print(f'Success: {result.package.name}')
asyncio.run(test())
"

๐Ÿ“ 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

Made with โค๏ธ for the Python community

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-0.1.4.tar.gz (34.2 kB view details)

Uploaded Source

Built Distribution

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

mcpydoc-0.1.4-py3-none-any.whl (24.2 kB view details)

Uploaded Python 3

File details

Details for the file mcpydoc-0.1.4.tar.gz.

File metadata

  • Download URL: mcpydoc-0.1.4.tar.gz
  • Upload date:
  • Size: 34.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for mcpydoc-0.1.4.tar.gz
Algorithm Hash digest
SHA256 a0410549d5ddf845800561e0b06537d3c7c20242a1a918e119ee476fa06e0dee
MD5 144288c4f63432c0c1f7411c34ee1c48
BLAKE2b-256 7a460076f18bc54c9447ff75fef60c52fa206b9c52cea95f5f5c57d2ea896d81

See more details on using hashes here.

File details

Details for the file mcpydoc-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: mcpydoc-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 24.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for mcpydoc-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 98a724ee5bd9646da988ecc76d84e68893ab0a860417ce579773cda29b095421
MD5 8e4bf068419f8f090d1a28a64e4a80ba
BLAKE2b-256 0c6e7d831fcefe467b26ab0b4f94593806e4e7a3b9a74c1283b15e13093dbc5d

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