Cover image
Try Now
2025-03-01

Un serveur de protocole de contexte de modèle (MCP) qui fournit un ensemble complet d'outils pour le développement de Python

3 years

Works with Finder

1

Github Watches

1

Github Forks

1

Github Stars

MCP Python Toolbox

A Model Context Protocol (MCP) server that provides a comprehensive set of tools for Python development, enabling AI assistants like Claude to effectively work with Python code and projects.

Overview

MCP Python Toolbox implements a Model Context Protocol server that gives Claude the ability to perform Python development tasks through a standardized interface. It enables Claude to:

  • Read, write, and manage files within a workspace
  • Analyze, format, and lint Python code
  • Manage virtual environments and dependencies
  • Execute Python code safely

Features

File Operations (FileOperations)

  • Safe file operations within a workspace directory
  • Path validation to prevent unauthorized access outside workspace
  • Read and write files with line-specific operations
  • Create and delete files and directories
  • List directory contents with detailed metadata (size, type, modification time)
  • Automatic parent directory creation when writing files

Code Analysis (CodeAnalyzer)

  • Parse and analyze Python code structure using AST
  • Extract detailed information about:
    • Import statements and their aliases
    • Function definitions with arguments and decorators
    • Class definitions with base classes and methods
    • Global variable assignments
  • Format code using:
    • Black (default)
    • PEP8 (using autopep8)
  • Comprehensive code linting using Pylint with detailed reports

Project Management (ProjectManager)

  • Create and manage virtual environments with pip support
  • Flexible dependency management:
    • Install from requirements.txt
    • Install from pyproject.toml
    • Support for specific package versions
  • Advanced dependency handling:
    • Check for version conflicts between packages
    • List all installed packages with versions
    • Update packages to specific versions
    • Generate requirements.txt from current environment

Code Execution (CodeExecutor)

  • Execute Python code in a controlled environment
  • Uses project's virtual environment for consistent dependencies
  • Temporary file management for code execution
  • Capture stdout, stderr, and exit codes
  • Support for custom working directories

Installation

  1. Clone the repository:
git clone https://github.com/gianlucamazza/mcp_python_toolbox.git
cd mcp_python_toolbox
  1. Create and activate a virtual environment:
python -m venv .venv
source .venv/bin/activate  # Linux/Mac
# or
.venv\Scripts\activate  # Windows
  1. Install the package in development mode:
pip install -e ".[dev]"

Usage

Running as a CLI Tool

The simplest way to start the server is using the CLI:

# Start with current directory as workspace
python -m mcp_python_toolbox

# Or specify a workspace directory
python -m mcp_python_toolbox --workspace /path/to/your/project

Setting Up with Claude Desktop

Claude Desktop can automatically launch and manage the MCP Python Toolbox server. Here's how to configure it:

  1. Install and set up the MCP Python Toolbox as described above
  2. Add a configuration entry for the Python Toolbox in Claude Desktop's MCP tools configuration:
"python-toolbox": {
  "command": "/Users/username/path/to/mcp_python_toolbox/.venv/bin/python",
  "args": [
    "-m",
    "mcp_python_toolbox",
    "--workspace",
    "/Users/username/path/to/workspace"
  ],
  "env": {
    "PYTHONPATH": "/Users/username/path/to/mcp_python_toolbox/src",
    "PATH": "/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin",
    "VIRTUAL_ENV": "/Users/username/path/to/mcp_python_toolbox/.venv",
    "PYTHONHOME": ""
  }
}
  1. Customize the paths to match your environment
  2. Claude Desktop will automatically start the MCP server when needed
  3. Claude will now have access to Python development tools through the MCP interface

Programmatic Usage

from mcp_python_toolbox import PythonToolboxServer

server = PythonToolboxServer(workspace_root="/path/to/your/project")
server.setup()
server.run()

Core Module Examples

File Operations

from mcp_python_toolbox.core import FileOperations

file_ops = FileOperations(workspace_root="/path/to/project")

# Read file contents
content = file_ops.read_file("src/example.py")
# Read specific lines
lines = file_ops.read_file("src/example.py", start_line=10, end_line=20)

# Write to file
file_ops.write_file("output.txt", "Hello, World!")
# Append to file
file_ops.write_file("log.txt", "New entry\n", mode='a')

# List directory contents
contents = file_ops.list_directory("src")
for item in contents:
    print(f"{item['name']} - {item['type']} - {item['size']} bytes")

Code Analysis

from mcp_python_toolbox.core import CodeAnalyzer

analyzer = CodeAnalyzer(workspace_root="/path/to/project")

# Analyze Python file structure
analysis = analyzer.parse_python_file("src/example.py")
print(f"Found {len(analysis['functions'])} functions")
print(f"Found {len(analysis['classes'])} classes")

# Format code
formatted = analyzer.format_code(code, style='black')

# Lint code
issues = analyzer.lint_code("src/example.py")
for issue in issues:
    print(f"Line {issue['line']}: {issue['message']}")

Project Management

from mcp_python_toolbox.core import ProjectManager

pm = ProjectManager(workspace_root="/path/to/project")

# Create virtual environment
pm.create_virtual_environment()

# Install dependencies
pm.install_dependencies()  # from requirements.txt or pyproject.toml
pm.install_dependencies("requirements-dev.txt")  # from specific file

# Check for conflicts
conflicts = pm.check_dependency_conflicts()
if conflicts:
    print("Found dependency conflicts:")
    for conflict in conflicts:
        print(f"{conflict['package']} requires {conflict['requires']}")

# Update packages
pm.update_package("requests")  # to latest
pm.update_package("flask", version="2.0.0")  # to specific version

Code Execution

from mcp_python_toolbox.core import CodeExecutor

executor = CodeExecutor(workspace_root="/path/to/project")

code = '''
def greet(name):
    return f"Hello, {name}!"

print(greet("World"))
'''

result = executor.execute_code(code)
print(f"Output: {result['stdout']}")
print(f"Errors: {result['stderr']}")
print(f"Exit code: {result['exit_code']}")

Development

Running Tests

pytest

Type Checking

mypy src/mcp_python_toolbox

Linting

pylint src/mcp_python_toolbox

Formatting

black src/mcp_python_toolbox

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • Implements the Model Context Protocol specification
  • Built with modern Python development tools and best practices
  • Uses industry-standard formatting (Black) and linting (Pylint) tools

相关推荐

  • NiKole Maxwell
  • I craft unique cereal names, stories, and ridiculously cute Cereal Baby images.

  • Joshua Armstrong
  • Confidential guide on numerology and astrology, based of GG33 Public information

  • https://suefel.com
  • Latest advice and best practices for custom GPT development.

  • Emmet Halm
  • Converts Figma frames into front-end code for various mobile frameworks.

  • Khalid kalib
  • Write professional emails

  • https://tovuti.be
  • Oede knorrepot die vasthoudt an de goeie ouwe tied van 't boerenleven

  • Elijah Ng Shi Yi
  • Advanced software engineer GPT that excels through nailing the basics.

  • ANGEL LEON
  • A world class elite tech co-founder entrepreneur, expert in software development, entrepreneurship, marketing, coaching style leadership and aligned with ambition for excellence, global market penetration and worldy perspectives.

  • Gil kaminski
  • Make sure you are post-ready before you post on social media

  • INFOLAB OPERATIONS 2
  • A medical specialist offering assistance grounded in clinical guidelines. Disclaimer: This is intended for research and is NOT safe for clinical use!

  • apappascs
  • Découvrez la collection la plus complète et la plus à jour de serveurs MCP sur le marché. Ce référentiel sert de centre centralisé, offrant un vaste catalogue de serveurs MCP open-source et propriétaires, avec des fonctionnalités, des liens de documentation et des contributeurs.

  • ShrimpingIt
  • Manipulation basée sur Micropython I2C de l'exposition GPIO de la série MCP, dérivée d'Adafruit_MCP230XX

  • OffchainLabs
  • Aller la mise en œuvre de la preuve de la participation Ethereum

  • huahuayu
  • Une passerelle API unifiée pour intégrer plusieurs API d'explorateur de blockchain de type étherscan avec la prise en charge du protocole de contexte modèle (MCP) pour les assistants d'IA.

  • deemkeen
  • Contrôlez votre MBOT2 avec un combo d'alimentation: MQTT + MCP + LLM

  • zhaoyunxing92
  • 本项目是一个钉钉 MCP (Protocole de connecteur de message) 服务 , 提供了与钉钉企业应用交互的 API 接口。项目基于 Go 语言开发 , 支持员工信息查询和消息发送等功能。

  • pontusab
  • La communauté du curseur et de la planche à voile, recherchez des règles et des MCP

    Reviews

    3 (1)
    Avatar
    user_3IVcbZ5h
    2025-04-16

    As a loyal user of the mcp_python_toolbox by gianlucamazza, I am thoroughly impressed with its functionality and ease of use. This toolbox is a must-have for anyone working in Python, providing a comprehensive set of tools to streamline the coding process. Check it out here: https://github.com/gianlucamazza/mcp_python_toolbox!