The MCP Terminal Server is a high-performance server implementing the Model Context Protocol (MCP) for secure terminal execution across platforms. It enables applications to safely execute terminal commands through a standardized protocol interface.
To build the MCP Terminal Server from source:
# Build the server
make build
The server can be run in two modes:
# Run in HTTP mode with StreamableHTTP transport
./mcp-terminal-server --http --port 8080
# Run in STDIO mode (default)
./mcp-terminal-server
Once the server is running in HTTP mode, you can test it with curl commands:
# Start server in HTTP mode
./mcp-terminal-server --http --port 8080
# Test MCP initialization
curl -X POST http://localhost:8080/mcp \
-H "Content-Type: application/json" \
-d '{"jsonrpc": "2.0", "id": 1, "method": "initialize", "params": {"protocolVersion": "2024-11-05", "capabilities": {}, "clientInfo": {"name": "test-client", "version": "1.0.0"}}}'
# Test tools listing (use session ID from initialize response)
curl -X POST http://localhost:8080/mcp \
-H "Content-Type: application/json" \
-H "Mcp-Session-Id: <session-id>" \
-d '{"jsonrpc": "2.0", "id": 2, "method": "tools/list"}'
# Execute a command
curl -X POST http://localhost:8080/mcp \
-H "Content-Type: application/json" \
-H "Mcp-Session-Id: <session-id>" \
-d '{"jsonrpc": "2.0", "id": 3, "method": "tools/call", "params": {"name": "execute_command", "arguments": {"command": "echo Hello StreamableHTTP!"}}}'
The server supports persistent shell sessions:
# Test persistent shell functionality
chmod +x examples/persistent_shell_examples.sh
./examples/persistent_shell_examples.sh
The MCP Terminal Server provides the following tools:
Configure the server using these environment variables:
MCP_COMMAND_TIMEOUT
- Default command timeout in seconds (default: 30)MCP_SHELL
- Custom shell to use for command execution (default: /bin/bash on Unix)DISPLAY
- X11 display for GUI applications (automatically forwarded to commands)The server automatically forwards the DISPLAY
environment variable to executed commands, enabling GUI applications:
# Set DISPLAY when starting the server
DISPLAY=:0 ./mcp-terminal-server
# GUI applications launched through MCP will use the correct display
# e.g., xterm, firefox, gedit, etc.
When running in HTTP mode (--http
flag), the server provides:
POST /mcp
- StreamableHTTP transport endpoint for all MCP operations
initialize
, tools/list
, tools/call
methodsMcp-Session-Id
header for authenticated requestsinitialize
callsAdd to your claude_desktop_config.json
:
{
"mcpServers": {
"terminal": {
"command": "/path/to/mcp-terminal-server",
"env": {
"MCP_COMMAND_TIMEOUT": "30",
"DISPLAY": ":0"
}
}
}
}
# Run AMD64 image
docker run --rm -p 8080:8080 terminal-mcp:latest-linux-amd64 --http --port 8080
# Run ARM64 image
docker run --rm -p 8080:8080 terminal-mcp:latest-linux-arm64 --http --port 8080
# Run with persistent shell session
docker run --rm -p 8080:8080 -v /tmp:/tmp terminal-mcp:latest-linux-amd64 --http --port 8080
To add this MCP server to Claude Code, run this command in your terminal:
claude mcp add-json "terminal" '{"command":"/path/to/mcp-terminal-server","env":{"MCP_COMMAND_TIMEOUT":"30","DISPLAY":":0"}}'
See the official Claude Code MCP documentation for more details.
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"terminal": {
"command": "/path/to/mcp-terminal-server",
"env": {
"MCP_COMMAND_TIMEOUT": "30",
"DISPLAY": ":0"
}
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.
To add this MCP server to Claude Desktop:
1. Find your configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
~/.config/Claude/claude_desktop_config.json
2. Add this to your configuration file:
{
"mcpServers": {
"terminal": {
"command": "/path/to/mcp-terminal-server",
"env": {
"MCP_COMMAND_TIMEOUT": "30",
"DISPLAY": ":0"
}
}
}
}
3. Restart Claude Desktop for the changes to take effect