This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is an MCP (Model Context Protocol) server that enables coding agents to execute long-running shell commands asynchronously. The server provides process management capabilities including starting, monitoring, controlling, and interacting with background processes.
This is a Python project using the uv package manager:
uv sync- Sync project dependencies and create virtual environmentuvx pytest tests/- Run all testsuvx pytest tests/unit/ -v- Run unit tests with verbose outputuvx pytest tests/integration/ -v- Run integration tests with verbose outputuvx ruff format- Format code before committinguv run python -m mcp_background_job- Run the MCP server (when implemented)
The server implements the following core components:
- JobManager: Central service managing background processes and job registry
- ProcessWrapper: Abstraction layer for child processes with I/O handling
- BackgroundJobConfig: Configuration management with environment variable support
- BackgroundJob: Complete job information with status, timestamps, and process details
- JobSummary: Minimal job information for listing operations
- ProcessOutput: Structured stdout/stderr output
- Tool Input/Output Models: Validation for all MCP tool parameters
The server exposes 7 tools through the Model Context Protocol:
Read-only tools:
list: Show all background jobs with statusstatus: Get status of specific joboutput: Get complete stdout/stderr of jobtail: Get last N lines of job output
Interactive tools:
execute: Start new background job, returns job_idinteract: Send input to job's stdinkill: Terminate running job
- Uses subprocess with proper I/O handling and buffering
- Ring buffer implementation for stdout/stderr (max 10MB per job)
- UUID-based job identification
- Automatic cleanup of terminated processes
- Command validation and sanitization to prevent shell injection
- Configurable job limits and resource constraints
- Process timeout handling and graceful termination
- Memory usage monitoring and cleanup
- Custom exception classes: JobNotFoundError, JobAlreadyTerminatedError, ProcessExecutionError
- Structured error responses through MCP ToolError
- Comprehensive input validation with Pydantic
The server supports configuration through:
Environment Variables:
MCP_BG_MAX_JOBS: Maximum concurrent jobs (default: 10)MCP_BG_MAX_OUTPUT_SIZE: Maximum output buffer per job (default: 10MB)MCP_BG_JOB_TIMEOUT: Default job timeout in secondsMCP_BG_CLEANUP_INTERVAL: Cleanup interval in seconds (default: 300)
The project implements comprehensive testing:
Unit Tests: Core functionality of JobManager, ProcessWrapper, and data models Integration Tests: End-to-end workflows, concurrent job handling, long-running processes Test Commands: Safe commands for testing (echo, sleep, python scripts)
This is currently a specification-only project. The actual implementation follows the detailed technical specification in SPEC.md and the implementation roadmap in TODO.md.
Designed to support:
- stdio: Primary transport for local development (must log to stderr only)
- HTTP: For remote access with proper CORS and Origin header validation
- Binding to localhost (127.0.0.1) for security, not all interfaces (0.0.0.0)
- Do not use emojis
- Always commit changes after all tests have passed. Write a concise message that includes a list of all changes. Do not credit claude in commit messages.