Python开发工具箱
STDIO为AI助手提供Python开发工具集
为AI助手提供Python开发工具集
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.
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:
FileOperations
)CodeAnalyzer
)ProjectManager
)CodeExecutor
)git clone https://github.com/gianlucamazza/mcp_python_toolbox.git cd mcp_python_toolbox
python -m venv .venv source .venv/bin/activate # Linux/Mac # or .venv\Scripts\activate # Windows
pip install -e ".[dev]"
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
Claude Desktop can automatically launch and manage the MCP Python Toolbox server. Here's how to configure it:
"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": "" } }
from mcp_python_toolbox import PythonToolboxServer server = PythonToolboxServer(workspace_root="/path/to/your/project") server.setup() server.run()
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")
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']}")
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
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']}")
pytest
mypy src/mcp_python_toolbox
pylint src/mcp_python_toolbox
black src/mcp_python_toolbox
git checkout -b feature/amazing-feature
)git commit -m 'Add some amazing feature'
)git push origin feature/amazing-feature
)This project is licensed under the MIT License - see the LICENSE file for details.