mcp terminal server
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.
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.
A lightweight FastAPI server that can run as a Windows service and exposes an endpoint to execute shell commands and stream their output.
.install_service.ps1
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
You can customize the installation with the following parameters:
.install_service.ps1 -ApiKey "your-api-key" -Port 8080 -Host "127.0.0.1" -LogLevel "debug"
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
The server can be configured through:
A sample configuration file (config.json.sample
) is provided. You can copy this to config.json
and modify it:
{
"host": "0.0.0.0",
"port": 8000,
"log_level": "info",
"log_file": "mcp_terminal_server.log",
"max_log_size_mb": 10,
"log_backup_count": 5,
"restart_on_failure": true,
"max_restart_attempts": 5,
"restart_delay_seconds": 10,
"shutdown_timeout_seconds": 30,
"working_directory": null
}
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 serverThe service can be managed using the following commands:
# Install the service
python service.py install
# Start the service
python service.py start
# Stop the service
python service.py stop
# Restart the service
python service.py restart
# Remove the service
python service.py remove
# Update the service configuration
python service.py update
# Run in debug mode (not as a service)
python service.py debug
Logs are stored in the configured log file (default: mcp_terminal_server.log
). The logs include:
A robust test client is provided to interact with the server with the following features:
# Run a command
python test_client.py -c "dir" -k "your-api-key"
# Check server health
python test_client.py --health
# Interactive mode
python test_client.py -k "your-api-key"
# Save output to a file
python test_client.py -c "systeminfo" --save-output output.txt
# Specify server URL
python test_client.py -s "http://example.com:8000" -c "dir"
# Enable verbose output
python test_client.py -v -c "dir"
# Show version
python test_client.py --version
The test client can be configured using a JSON configuration file. Create a client_config.json
file based on the provided sample:
{
"server_url": "http://localhost:8000",
"api_key": "your-api-key-here",
"timeout": 60,
"verbose": false
}
Then use it with:
python test_client.py --config client_config.json
The test client also supports configuration via environment variables:
MCP_TERMINAL_API_KEY
: API key for authenticationMCP_TERMINAL_SERVER_URL
: Server URLPOST /run
: Execute a commandX-API-Key
header{"command": "your command"}
Returns streaming response with command output
GET /health
: Check server health
{"status": "healthy", "active_sessions": 0}
127.0.0.1
if the server should only be accessible locallypython service.py debug
Get-Service -Name "MCP_Terminal_Server"
MIT