Skip to main content

๐Ÿ AI-powered Python package intelligence - search, analyze, and understand PyPI packages through MCP

Project description

๐Ÿ MCP-PyPI

PyPI License Python Downloads

A security-focused Model Context Protocol (MCP) server that helps AI agents write safer Python code. Search packages, scan for vulnerabilities, audit dependencies, and ensure security across your entire Python project.

โœจ What is MCP-PyPI?

MCP-PyPI is a security-focused Model Context Protocol server that empowers AI assistants to write safer Python code. Beyond basic package information, it provides comprehensive vulnerability scanning, dependency auditing, and proactive security recommendations to ensure AI-generated code uses secure, up-to-date dependencies.

๐Ÿ›ก๏ธ Security First: Every tool is designed to encourage security best practices, from checking vulnerabilities before suggesting packages to scanning entire project dependency trees for hidden risks.

๐ŸŽฏ Key Features

  • ๐Ÿ›ก๏ธ Comprehensive Security Scanning - Check vulnerabilities using OSV database across packages, dependencies, and entire projects
  • ๐Ÿ” Security-Aware Package Search - Find safe packages from 500,000+ options with vulnerability status
  • ๐Ÿ“‹ Project-Wide Security Audits - Scan requirements.txt, pyproject.toml, and installed environments
  • ๐Ÿ”— Deep Dependency Analysis - Detect vulnerabilities in transitive dependencies others might miss
  • ๐Ÿšจ Proactive Security Alerts - Get warnings before adding vulnerable packages to projects
  • ๐Ÿ“Š Risk Assessment & Scoring - Security scores, fix time estimates, and prioritized remediation plans
  • โšก Smart Caching - Fast vulnerability checks with configurable TTL for different data types
  • ๐Ÿš€ Version Management - Track releases, compare versions, identify security updates

๐Ÿค” Why Security Matters

When AI assistants suggest Python packages, they might unknowingly recommend packages with known vulnerabilities. MCP-PyPI ensures that:

  • Before Installation: AI checks for vulnerabilities before suggesting any package
  • During Development: Continuous scanning catches new vulnerabilities in existing dependencies
  • Before Deployment: Comprehensive audits ensure production code is secure
  • Transitive Safety: Hidden vulnerabilities in dependencies-of-dependencies are detected

๐Ÿš€ Quick Start

Installation

# Basic installation
pip install mcp-pypi

# With HTTP transport support
pip install "mcp-pypi[http]"

# With all features
pip install "mcp-pypi[all]"

Running the Server

# Start with default stdio transport (for Claude Desktop)
mcp-pypi serve

# Alternative stdio command (for compatibility)
mcp-pypi stdio

# Start with HTTP transport
mcp-pypi serve --transport http

# With custom cache directory
mcp-pypi serve --cache-dir ~/.pypi-cache

๐Ÿค– Using with Claude Desktop

Add to your Claude Desktop configuration (claude.json):

{
  "servers": {
    "pypi": {
      "command": "mcp-pypi",
      "args": ["serve"],
      "description": "Access Python package information from PyPI"
    }
  }
}

// Alternative using stdio command (equivalent to above)
{
  "servers": {
    "pypi": {
      "command": "mcp-pypi",
      "args": ["stdio"],
      "description": "Access Python package information from PyPI"
    }
  }
}

๐Ÿ–ฅ๏ธ Using with Claude Code (Terminal)

Add the MCP server to Claude Code:

# Add the server (using serve command)
claude mcp add mcp-pypi -- mcp-pypi serve

# Alternative using stdio command
claude mcp add mcp-pypi -- mcp-pypi stdio

# The server will be available in your next Claude Code session

๐Ÿ› ๏ธ Available Tools

Package Discovery

  • search_packages - ๐Ÿ” Search PyPI to discover Python packages
  • get_package_info - ๐Ÿ“ฆ Get comprehensive package details
  • check_package_exists - โœ… Verify if a package exists on PyPI

Version Management

  • get_latest_version - ๐Ÿš€ Check the latest available version
  • list_package_versions - ๐Ÿ“š List all available versions
  • compare_versions - ๐Ÿ”„ Compare two package versions

Dependency Analysis

  • get_dependencies - ๐Ÿ”— Analyze package dependencies
  • get_dependency_tree - ๐ŸŒณ Visualize complete dependency tree
  • check_vulnerabilities - ๐Ÿ›ก๏ธ Scan for security vulnerabilities using OSV database
  • scan_dependency_vulnerabilities - ๐Ÿ›ก๏ธ๐Ÿ” Deep scan entire dependency tree for vulnerabilities

Project Management

  • check_requirements_txt - ๐Ÿ“‹๐Ÿ›ก๏ธ Security audit requirements.txt files
  • check_pyproject_toml - ๐ŸŽฏ๐Ÿ›ก๏ธ Security audit pyproject.toml dependencies
  • scan_installed_packages - ๐Ÿ›ก๏ธ๐Ÿ’ป Scan virtual/system environments for vulnerabilities
  • security_audit_project - ๐Ÿ›ก๏ธ๐Ÿ”๐Ÿšจ Comprehensive project-wide security audit

Statistics & Info

  • get_package_stats - ๐Ÿ“Š Get download statistics
  • get_package_metadata - ๐Ÿ“‹ Access complete metadata
  • get_package_documentation - ๐Ÿ“– Find documentation links

๐Ÿ’ก Example Usage

Once configured, you can ask Claude:

  • "Search for web scraping packages on PyPI"
  • "What's the latest version of Django?"
  • "Check if my requirements.txt has any outdated packages"
  • "Show me the dependencies for FastAPI"
  • "Find popular data visualization libraries"
  • "Compare pandas version 2.0.0 with 2.1.0"

๐Ÿ”ง Advanced Configuration

Environment Variables

# Custom cache directory
export PYPI_CACHE_DIR=/path/to/cache

# Cache TTL (seconds)
export PYPI_CACHE_TTL=3600

# Vulnerability cache TTL (seconds) - default 1 hour
export PYPI_VULNERABILITY_CACHE_TTL=3600

# Custom user agent
export PYPI_USER_AGENT="MyApp/1.0"

Programmatic Usage

from mcp_pypi.server import PyPIMCPServer
from mcp_pypi.core.models import PyPIClientConfig

# Custom configuration
config = PyPIClientConfig(
    cache_dir="/tmp/pypi-cache",
    cache_ttl=7200,
    cache_strategy="hybrid"
)

# Create and run server
server = PyPIMCPServer(config=config)
server.run(transport="http", host="0.0.0.0", port=8080)

๐Ÿ“Š Performance

  • Intelligent Caching: Hybrid memory/disk caching with LRU/LFU/FIFO strategies
  • Concurrent Requests: Async architecture for parallel operations
  • Minimal Overhead: Direct PyPI API integration
  • Configurable TTL: Control cache duration based on your needs

๐Ÿ›ก๏ธ Security & Caching

Vulnerability Data Caching

Vulnerability checks are cached to improve performance and reduce API load:

  • Default TTL: 1 hour (3600 seconds)
  • Configurable: Use PYPI_VULNERABILITY_CACHE_TTL environment variable
  • Cache Key: Based on package name + version
  • OSV API: Queries are cached to avoid repeated lookups

Why Caching Matters

  1. Performance: Vulnerability checks can be slow, caching makes subsequent checks instant
  2. Rate Limiting: Prevents hitting OSV API rate limits during large scans
  3. Consistency: Ensures consistent results during a security audit
  4. Offline Support: Cached results available even if OSV API is unreachable

Cache Management

# Clear all caches
mcp-pypi cache clear

# View cache statistics
mcp-pypi cache stats

# Set shorter TTL for development (5 minutes)
export PYPI_VULNERABILITY_CACHE_TTL=300

๐Ÿค Contributing

Contributions are welcome! Please check out our Contributing Guide for details.

Development Setup

# Clone the repository
git clone https://github.com/kimasplund/mcp-pypi.git
cd mcp-pypi

# Install in development mode
pip install -e ".[dev]"

# Run tests
pytest

# Run with debug logging
mcp-pypi serve --log-level DEBUG

๐Ÿ“„ License

This project is dual-licensed:

  • Open Source: MIT License for personal, educational, and non-profit use - see LICENSE
  • Commercial: Commercial License required for business use - see LICENSE-COMMERCIAL

Quick License Guide:

  • โœ… Free to use: Personal projects, education, non-profits, open source
  • ๐Ÿ’ฐ Commercial license required: For-profit companies, commercial products, consulting
  • ๐Ÿ“ง Contact: kim.asplund@gmail.com for commercial licensing

๐Ÿ™ Acknowledgments

๐Ÿ“ž Support


Made with โค๏ธ for the Python and AI communities

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

mcp_pypi-2.6.5.tar.gz (122.4 kB view details)

Uploaded Source

Built Distribution

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

mcp_pypi-2.6.5-py3-none-any.whl (86.4 kB view details)

Uploaded Python 3

File details

Details for the file mcp_pypi-2.6.5.tar.gz.

File metadata

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

File hashes

Hashes for mcp_pypi-2.6.5.tar.gz
Algorithm Hash digest
SHA256 fb1af7cb6f9a17272dd5defea5a8b777c3ad4c8aa789b44056c2df0860132a4b
MD5 66f756f2b9cb2d22904bef74fe41a9f7
BLAKE2b-256 c26643c5364b3d3e1ab94ba809d6b04dbfc6eac0cf5aed976140a923b631e0fe

See more details on using hashes here.

File details

Details for the file mcp_pypi-2.6.5-py3-none-any.whl.

File metadata

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

File hashes

Hashes for mcp_pypi-2.6.5-py3-none-any.whl
Algorithm Hash digest
SHA256 118f36e43421cee60876492bbb2208697b33651e89a9164ec1503038a9a82b4b
MD5 66eaafaddf2a89ba3d3992043c47a9c2
BLAKE2b-256 3a034b7839e19e1a6b05f596ac1ca4dc63be7631bff9a19b41ae23bb76d7404c

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