Integrations
Provides a lightweight server implementation that exposes an endpoint to execute shell commands and stream their output in real-time.
Leverages Python 3.7+ to provide a Windows service that can execute commands with robust error handling, logging, and automatic process restart capabilities.
Enables remote execution of shell commands with streaming output, allowing for running and monitoring command-line operations through an authenticated API.
MCP Terminal Server
A lightweight FastAPI server that can run as a Windows service and exposes an endpoint to execute shell commands and stream their output.
Features
- Run as a Windows service or in debug mode
- Execute shell commands and stream their output in real-time
- API key authentication
- Rate limiting
- Configurable via environment variables or configuration file
- Robust error handling and logging
- Automatic process restart on failure
Installation
Prerequisites
- Windows operating system
- Python 3.7 or higher
- Administrator privileges (for service installation)
Install Steps
- Clone this repository or download the source code
- Open PowerShell as Administrator
- Navigate to the project directory
- Run the installation script:
This will:
- Install required Python dependencies
- Generate a random API key (or use the one you provide)
- Create a configuration file
- Install and start the Windows service
Installation Options
You can customize the installation with the following parameters:
Available parameters:
-ApiKey
: Custom API key for authentication-Port
: Port number for the server (default: 8000)-Host
: Host address to bind to (default: 0.0.0.0)-LogLevel
: Log level (debug, info, warning, error, critical)-ConfigFile
: Path to a custom configuration file
Configuration
The server can be configured through:
- Environment variables
- Configuration file (config.json)
- Command-line arguments during installation
Configuration File
A sample configuration file (config.json.sample
) is provided. You can copy this to config.json
and modify it:
Environment Variables
You can also configure the server using environment variables:
MCP_TERMINAL_API_KEY
: API key for authenticationMCP_HOST
: Host address to bind toMCP_PORT
: Port number for the serverMCP_LOG_LEVEL
: Log levelMCP_LOG_FILE
: Path to log fileMCP_MAX_LOG_SIZE_MB
: Maximum log file size in MBMCP_LOG_BACKUP_COUNT
: Number of log backup files to keepMCP_RESTART_ON_FAILURE
: Whether to restart the server on failureMCP_MAX_RESTART_ATTEMPTS
: Maximum number of restart attemptsMCP_RESTART_DELAY_SECONDS
: Delay between restart attemptsMCP_SHUTDOWN_TIMEOUT_SECONDS
: Timeout for graceful shutdownMCP_WORKING_DIRECTORY
: Working directory for the server
Service Management
Service Commands
The service can be managed using the following commands:
Logs
Logs are stored in the configured log file (default: mcp_terminal_server.log
). The logs include:
- Service start/stop events
- Command execution
- Errors and warnings
- Health check results
API Usage
Test Client
A robust test client is provided to interact with the server with the following features:
- Command-line arguments for better usability
- API key authentication support
- Colored output for better readability
- Support for saving output to a file
- Robust error handling and logging
- Interactive mode with command history
- Server health check functionality
Basic Usage
Configuration File
The test client can be configured using a JSON configuration file. Create a client_config.json
file based on the provided sample:
Then use it with:
Environment Variables
The test client also supports configuration via environment variables:
MCP_TERMINAL_API_KEY
: API key for authenticationMCP_TERMINAL_SERVER_URL
: Server URL
API Endpoints
POST /run
: Execute a command- Requires API key in
X-API-Key
header - Request body:
{"command": "your command"}
- Returns streaming response with command output
- Requires API key in
GET /health
: Check server health- Returns
{"status": "healthy", "active_sessions": 0}
- Returns
Security Considerations
- Always change the default API key in production
- Restrict the host to
127.0.0.1
if the server should only be accessible locally - Consider using HTTPS in production
- The server blocks potentially dangerous commands, but additional security measures may be needed
Troubleshooting
- Check the log file for errors
- Run in debug mode to see console output:
python service.py debug
- Verify the service is running:
Get-Service -Name "MCP_Terminal_Server"
- Check Windows Event Viewer for service-related errors
License
MIT
This server cannot be installed
A lightweight FastAPI server that allows remote execution of shell commands on Windows, with real-time output streaming and security features like API key authentication and rate limiting.
Related MCP Servers
- AsecurityAlicenseAqualityA secure shell command execution server implementing the Model Context Protocol (MCP). This server allows remote execution of whitelisted shell commands with support for stdin input.Last updated -168PythonMIT License
- AsecurityFlicenseAqualityA CLI command execution server that enables running shell commands with structured output, providing detailed execution results including stdout, stderr, exit code, and execution duration.Last updated -216TypeScript
- -securityAlicense-qualityA Model Context Protocol server that enables remote execution of shell commands across different operating systems, automatically handling platform-specific differences between Windows and Unix-like systems.Last updated -JavaScriptMIT License
- -securityAlicense-qualityAn MCP server that enables secure execution of shell commands across Windows, macOS, and Linux with built-in whitelisting and approval mechanisms for enhanced security.Last updated -13JavaScriptMIT License