This document provides examples of how to use the Python Package Manager MCP Server.
# Using the run script
./scripts/run_stdio.sh
# Using the CLI
python -m python_package_mcp_server.cli stdio
# Using uv directly
uv run python -m python_package_mcp_server.cli stdio# Using the run script
./scripts/run_http.sh --host localhost --port 8000
# Using the CLI
python -m python_package_mcp_server.cli http --host localhost --port 8000
# In background
./scripts/run_http.sh --background# Using the dev script
./scripts/dev.sh
# Using the CLI
python -m python_package_mcp_server.cli dev --host localhost --port 8000Automated Setup (Recommended):
# Linux/macOS
./scripts/setup_ide.sh cursor
# Windows PowerShell
.\scripts\setup_ide.ps1 cursorOption 1: Global Configuration (~/.cursor/mcp.json):
{
"mcpServers": {
"python-package-manager": {
"command": "python",
"args": ["-m", "python_package_mcp_server.cli", "stdio"],
"env": {
"MCP_PROJECT_ROOT": ".",
"MCP_LOG_LEVEL": "INFO",
"MCP_LOG_FORMAT": "json"
}
}
}
}Option 2: Project-Specific (.cursor/mcp_config.json):
{
"mcpServers": {
"python-package-manager": {
"command": "python",
"args": ["-m", "python_package_mcp_server.cli", "stdio"],
"env": {
"MCP_PROJECT_ROOT": ".",
"MCP_LOG_LEVEL": "INFO",
"MCP_LOG_FORMAT": "json"
}
}
}
}The server can be configured in VS Code using the MCP extension. See .vscode/launch.json for debug configurations.
Configuration (.vscode/settings.json):
{
"mcp.servers": {
"python-package-manager": {
"command": "python",
"args": ["-m", "python_package_mcp_server.cli", "stdio"],
"env": {
"MCP_PROJECT_ROOT": "${workspaceFolder}",
"MCP_LOG_LEVEL": "INFO"
}
}
}
}If using a virtual environment, use the venv Python path:
macOS/Linux:
{
"mcpServers": {
"python-package-manager": {
"command": ".venv/bin/python",
"args": ["-m", "python_package_mcp_server.cli", "stdio"],
"env": {
"MCP_PROJECT_ROOT": "."
}
}
}
}Windows:
{
"mcpServers": {
"python-package-manager": {
"command": ".venv\\Scripts\\python.exe",
"args": ["-m", "python_package_mcp_server.cli", "stdio"],
"env": {
"MCP_PROJECT_ROOT": "."
}
}
}
}For detailed configuration options, see the MCP Configuration Guide.
-
Enable User Authentication:
export MCP_ENABLE_USER_AUTH=true export MCP_USERS_FILE=~/.mcp_server/users.json
-
Create First Admin Account:
# With auto-generated API key python -m python_package_mcp_server.cli create-admin --username admin # With custom API key python -m python_package_mcp_server.cli create-admin --username admin --api-key my-secure-key-123
-
Create Additional Users (via MCP tool, admin only):
{ "tool": "create_user", "arguments": { "username": "developer1", "role": "user" } }
HTTP Transport:
# Include API key in request headers
curl -H "X-API-Key: your-api-key" http://localhost:8000/health
curl -H "Authorization: Bearer your-api-key" http://localhost:8000/healthStdio Transport:
# Set API key in environment
export MCP_API_KEY=your-api-key
python -m python_package_mcp_server.cli stdioClient Configuration with API Key:
{
"mcpServers": {
"python-package-manager": {
"command": "python",
"args": ["-m", "python_package_mcp_server.cli", "stdio"],
"env": {
"MCP_PROJECT_ROOT": ".",
"MCP_ENABLE_USER_AUTH": "true",
"MCP_API_KEY": "your-api-key-here"
}
}
}
}List All Users (admin only):
{
"tool": "list_users",
"arguments": {}
}Delete a User (admin only):
{
"tool": "delete_user",
"arguments": {
"username": "user1"
}
}Note: Cannot delete the last admin user.
# Resource URI: python:packages://installed
# Returns JSON with list of installed packages# Resource URI: python:dependencies://tree
# Returns JSON with dependency tree visualization# Resource URI: project://index
# Returns complete project index with structure, files, and metadata# Resource URI: codebase://search?pattern=def.*&extensions=.py
# Returns search results matching the pattern{
"name": "install",
"arguments": {
"packages": ["requests==2.31.0", "pytest"],
"editable": false
}
}{
"name": "add",
"arguments": {
"packages": ["fastapi"],
"dev": false
}
}{
"name": "sync",
"arguments": {}
}{
"name": "index_project",
"arguments": {
"path": "/path/to/project"
}
}{
"name": "analyze_codebase",
"arguments": {
"path": "/path/to/project"
}
}{
"name": "dart_format",
"arguments": {
"paths": ["lib/main.dart"],
"line_length": 80
}
}{
"name": "dart_analyze",
"arguments": {
"paths": ["lib/"]
}
}{
"name": "dart_fix",
"arguments": {
"paths": ["lib/main.dart"]
}
}{
"name": "dart_generate_code",
"arguments": {
"code_description": "Create a User class with name and email fields",
"file_path": "lib/models/user.dart",
"include_tests": true
}
}{
"name": "dart_check_standards",
"arguments": {
"file_path": "lib/main.dart"
}
}{
"name": "typescript_format",
"arguments": {
"paths": ["src/index.ts"]
}
}{
"name": "typescript_lint",
"arguments": {
"paths": ["src/"]
}
}{
"name": "typescript_type_check",
"arguments": {
"project_path": "tsconfig.json"
}
}{
"name": "typescript_generate_code",
"arguments": {
"code_description": "Create a User interface with name and email properties",
"file_path": "src/types/user.ts",
"include_tests": true
}
}{
"name": "typescript_check_standards",
"arguments": {
"file_path": "src/index.ts"
}
}# Resource URI: dart:standards://effective-dart
# Returns Effective Dart guidelines
# Resource URI: dart:standards://style-guide
# Returns Dart style guide
# Resource URI: dart:standards://linter-rules
# Returns Dart linter rules
# Resource URI: dart:standards://best-practices
# Returns Dart best practices# Resource URI: typescript:standards://style-guide
# Returns TypeScript style guide
# Resource URI: typescript:standards://tsconfig-options
# Returns TypeScript tsconfig options
# Resource URI: typescript:standards://eslint-rules
# Returns TypeScript ESLint rules
# Resource URI: typescript:standards://best-practices
# Returns TypeScript best practicesMCP Inspector provides an interactive web-based UI for testing and debugging the MCP server. It's an excellent tool for exploring available resources and tools.
Basic usage:
# Linux/macOS
./scripts/inspect.sh
# Windows PowerShell
.\scripts\inspect.ps1The inspector will:
- Start the MCP server via stdio transport
- Launch a web UI at
http://localhost:5173 - Open the UI in your default browser
In the Inspector UI, navigate to the Resources tab to:
-
Browse available resources:
python:packages://installed- View installed packagespython:packages://outdated- Check for outdated packagesproject://index- Explore project structuredart:standards://effective-dart- Read Dart guidelinestypescript:standards://style-guide- Read TypeScript style guide
-
Read resource content:
- Click on any resource to fetch its content
- View JSON responses in formatted view
- Test resource subscriptions
In the Tools tab, you can:
-
Test package management:
{ "name": "install", "arguments": { "packages": ["requests"], "editable": false } } -
Test Dart tools:
{ "name": "dart_format", "arguments": { "paths": ["lib/main.dart"], "line_length": 80 } } -
Test TypeScript tools:
{ "name": "typescript_lint", "arguments": { "paths": ["src/"] } }
The Logs tab shows:
- Real-time JSON-RPC messages
- Request/response pairs
- Error messages and warnings
- Server state changes
To test with HTTP transport:
-
Start HTTP server in one terminal:
./scripts/run_http.sh --host localhost --port 8000
-
Run inspector in another terminal:
./scripts/inspect.sh --transport http --host localhost --port 8000
You can configure the inspector with environment variables:
# Set project root
MCP_PROJECT_ROOT=/path/to/project ./scripts/inspect.sh
# Enable debug logging
MCP_LOG_LEVEL=DEBUG ./scripts/inspect.sh
# Use custom ports
CLIENT_PORT=8080 SERVER_PORT=9000 ./scripts/inspect.shThe server can be configured using environment variables:
MCP_TRANSPORT: Transport type (stdioorhttp)MCP_HOST: HTTP server host (default:localhost)MCP_PORT: HTTP server port (default:8000)MCP_API_KEY: API key for HTTP authenticationMCP_ENABLE_AUTH: Enable authentication (true/false)MCP_ALLOWED_PACKAGES: Comma-separated list of allowed package patternsMCP_BLOCKED_PACKAGES: Comma-separated list of blocked package patternsMCP_LOG_LEVEL: Logging level (DEBUG,INFO,WARNING,ERROR)MCP_LOG_FORMAT: Log format (jsonortext)MCP_PROJECT_ROOT: Project root directoryMCP_WORKSPACE_ROOT: Workspace root directory
When integrated with an LLM assistant, you can ask questions like:
- "What packages are installed in this project?"
- "Show me the dependency tree"
- "Install the requests package"
- "What files are in this project?"
- "Search for all functions named 'handle_*'"
- "Show me the project structure"
- "Format my Dart code according to style guide"
- "Check if my TypeScript code follows best practices"
- "Show me the Dart linter rules"
- "Generate TypeScript code for a User interface"
- "Analyze my Dart code for errors"
The LLM will use the MCP server's resources and tools to answer these questions and perform actions.