Enables the execution and monitoring of Docker build processes as background jobs, allowing agents to start, track progress, and manage Docker builds asynchronously.
Supports running npm scripts as background jobs, such as development servers (npm run dev), allowing agents to start, monitor, and interact with npm-based processes.
Enables interaction with Python REPLs as background processes, allowing agents to execute Python code, send commands, and collect output asynchronously.
Provides comprehensive management of shell commands as background jobs, with capabilities for executing, monitoring, and interacting with any long-running shell process.
MCP Background Job Server
An MCP (Model Context Protocol) server that enables coding agents to execute long-running shell commands asynchronously with full process management capabilities.
Overview
The MCP Background Job Server provides a robust solution for running shell commands in the background, allowing agents to start processes, monitor their status, interact with them, and manage their lifecycle. This is particularly useful for development workflows involving build processes, test suites, servers, or any long-running operations.
Features
- Asynchronous Process Execution: Execute shell commands as background jobs with unique job IDs
- Process Lifecycle Management: Start, monitor, interact with, and terminate background processes
- Real-time Output Monitoring: Capture and retrieve stdout/stderr with buffering and tailing capabilities
- Interactive Process Support: Send input to running processes via stdin
- Resource Management: Configurable job limits and automatic cleanup of completed processes
- MCP Protocol Integration: Full integration with Model Context Protocol for agent interactions
Installation
Quick Install (Recommended)
Install directly from PyPI using uvx
:
Claude Code Integration
Add the server to your Claude Code configuration:
- Option A: Using Claude Code Desktop
- Open Claude Code settings/preferences
- Navigate to MCP Servers section
- Add a new server:
- Name:
background-job
- Command:
uvx
- Args:
["mcp-background-job"]
- Name:
- Option B: Configuration File
Add to your Claude Code configuration file:
- Restart Claude Code to load the new MCP server.
Development Setup
For local development or contributing:
Prerequisites
- Python 3.12 or higher
- uv package manager
Setup Steps
- Clone and navigate to the project directory:
- Install dependencies:
- Install in development mode:
Quick Start
Using with Claude Code
Once configured, ask Claude to help you with background tasks:
Manual Server Usage
For development or direct usage:
Basic Usage Example
MCP Tools Reference
The server exposes 7 MCP tools for process management:
Read-only Tools
Tool | Description | Parameters | Returns |
---|---|---|---|
list | List all background jobs | None | {jobs: [JobSummary]} |
status | Get job status | job_id: str | {status: JobStatus} |
output | Get complete job output | job_id: str | {stdout: str, stderr: str} |
tail | Get recent output lines | job_id: str, lines: int | {stdout: str, stderr: str} |
Interactive Tools
Tool | Description | Parameters | Returns |
---|---|---|---|
execute | Start new background job | command: str | {job_id: str} |
interact | Send input to job stdin | job_id: str, input: str | {stdout: str, stderr: str} |
kill | Terminate running job | job_id: str | {status: str} |
Job Status Values
running
- Process is currently executingcompleted
- Process finished successfullyfailed
- Process terminated with errorkilled
- Process was terminated by user
Configuration
Environment Variables
Configure the server behavior using these environment variables:
Claude Code Configuration with Environment Variables
Programmatic Configuration
Architecture
The server is built with a modular architecture:
- JobManager: Central service for job lifecycle management
- ProcessWrapper: Abstraction layer for subprocess handling with I/O buffering
- FastMCP Server: MCP protocol implementation with tool definitions
- Pydantic Models: Type-safe data validation and serialization
Key Components
Development
Running Tests
Code Formatting
Development Workflow
- Make your changes
- Run tests:
uv run pytest tests/
- Format code:
uv run ruff format
- Commit changes
Examples
Development Server Workflow
Long-running Build Process
Interactive Process Example
Security Considerations
- Process Isolation: Each job runs as a separate subprocess
- Resource Limits: Configurable limits on concurrent jobs and memory usage
- Input Validation: All parameters are validated using Pydantic models
- Command Restrictions: Consider implementing command allowlists in production
- Output Sanitization: Be aware that process output may contain sensitive information
Transport Support
The server supports multiple MCP transports:
- stdio: Default transport for local development and agent integration
- HTTP: For remote access (requires additional setup)
For stdio transport, ensure logging goes to stderr only to avoid protocol conflicts.
Troubleshooting
Common Issues
Import Errors: Ensure the package is installed in development mode:
Tests Not Running: Install the package first, then run tests:
Permission Errors: Ensure proper permissions for the commands you're trying to execute.
Memory Issues: Adjust MCP_BG_MAX_OUTPUT_SIZE
if dealing with processes that generate large amounts of output.
Contributing
- Fork the repository
- Create a feature branch
- Make your changes with tests
- Run the test suite and formatting
- Submit a pull request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Changelog
v0.1.1
- Published to PyPI for easy installation via
uvx
- Added console script entry point (
mcp-background-job
) - Updated documentation with installation and usage instructions
- Fixed linting issues and improved code quality
v0.1.0
- Initial implementation with full MCP tool support
- Process lifecycle management
- Configurable resource limits
- Comprehensive test suite
Built with ❤️ using FastMCP and Python 3.12+
This server cannot be installed
hybrid server
The server is able to function both locally and remotely, depending on the configuration or use case.
An MCP server that enables coding agents to execute and manage long-running shell commands asynchronously with capabilities for process monitoring, interaction, and lifecycle management.
Related MCP Servers
- AsecurityAlicenseAqualityA server that uses the Model Context Protocol (MCP) to allow AI agents to safely execute shell commands on a host system.Last updated -1204TypeScriptMIT License
- AsecurityAlicenseAqualityA powerful MCP server that provides interactive user feedback and command execution capabilities for AI-assisted development, featuring a graphical interface with text and image support.Last updated -133PythonMIT License
- -securityAlicense-qualityGive hands to AI. MCP server to run shell commands securely, auditably, and on demand.Last updated -12GoMIT License
- AsecurityFlicenseAqualityAn MCP server that enhances AI agents' coding capabilities by providing zero hallucinations, improved code quality, security-first approach, high test coverage, and efficient context management.Last updated -15701TypeScript