Skip to main content
Glama
marc-shade

Cluster Execution MCP Server

by marc-shade

Cluster Execution MCP Server

Cluster-aware command execution for distributed task routing across the AGI agentic cluster.

Version: 0.2.0

Features

  • Automatic task routing: Commands routed to optimal nodes based on load, capabilities, and requirements

  • Multi-node support: macpro51 (Linux x86_64), mac-studio (macOS ARM64), macbook-air (macOS ARM64), inference node

  • Dynamic IP resolution: mDNS, DNS, and fallback methods with caching

  • Security hardened: No shell injection, environment-based configuration, command validation

  • SSH connectivity verification: Retry logic with configurable timeouts

  • Parallel execution: Distribute commands across cluster for maximum throughput

Related MCP server: remote-admin-mcp

Installation

cd /mnt/agentic-system/mcp-servers/cluster-execution-mcp
pip install -e .

# For development:
pip install -e ".[dev]"

Configuration

Claude Code Configuration

Add to ~/.claude.json:

{
  "mcpServers": {
    "cluster-execution": {
      "command": "/mnt/agentic-system/.venv/bin/python3",
      "args": ["-m", "cluster_execution_mcp.server"]
    }
  }
}

Environment Variables

All configuration is externalized via environment variables:

Variable

Default

Description

CLUSTER_SSH_USER

marcssh

SSH username for remote execution

CLUSTER_SSH_TIMEOUT

5

SSH connection timeout (seconds)

CLUSTER_SSH_CONNECT_TIMEOUT

2

Initial SSH connect timeout (seconds)

CLUSTER_SSH_RETRIES

2

Number of SSH retry attempts

CLUSTER_CPU_THRESHOLD

40

CPU usage % threshold for offloading

CLUSTER_LOAD_THRESHOLD

4

Load average threshold for offloading

CLUSTER_MEMORY_THRESHOLD

80

Memory usage % threshold for offloading

CLUSTER_CMD_TIMEOUT

300

Command execution timeout (seconds)

CLUSTER_STATUS_TIMEOUT

5

Status check timeout (seconds)

CLUSTER_IP_CACHE_TTL

300

IP resolution cache TTL (seconds)

CLUSTER_GATEWAY

192.168.1.1

Gateway IP for route detection

CLUSTER_DNS

8.8.8.8

DNS server for IP detection

AGENTIC_SYSTEM_PATH

/mnt/agentic-system

Base path for databases

Node Configuration

Node hostnames and IPs can be customized:

Variable

Default

Description

CLUSTER_MACPRO51_HOST

macpro51.local

Mac Pro hostname

CLUSTER_MACPRO51_IP

192.168.1.2

Mac Pro fallback IP

CLUSTER_MACSTUDIO_HOST

Marcs-Mac-Studio.local

Mac Studio hostname

CLUSTER_MACSTUDIO_IP

192.168.1.6

Mac Studio fallback IP

CLUSTER_MACBOOKAIR_HOST

Marcs-MacBook-Air.local

MacBook Air hostname

CLUSTER_MACBOOKAIR_IP

192.168.1.7

MacBook Air fallback IP

CLUSTER_INFERENCE_HOST

server.local

Inference node hostname

CLUSTER_INFERENCE_IP

192.168.1.8

Inference node fallback IP

MCP Tools

Tool

Description

cluster_bash

Execute bash commands with automatic cluster routing

cluster_status

Get current cluster state and load distribution

offload_to

Explicitly route command to specific node

parallel_execute

Run multiple commands in parallel across nodes

Usage Examples

Automatic Routing

# Heavy commands auto-route to least loaded node
result = await cluster_bash("make -j8 all")

# Simple commands run locally
result = await cluster_bash("ls -la")

Force Specific Requirements

# Force Linux execution
result = await cluster_bash("docker build .", requires_os="linux")

# Force x86_64 architecture
result = await cluster_bash("cargo build", requires_arch="x86_64")

Explicit Node Routing

# Run on Linux builder
result = await offload_to("podman run -it ubuntu:22.04", node_id="macpro51")

# Run on Mac Studio
result = await offload_to("swift build", node_id="mac-studio")

Parallel Execution

# Run tests across cluster
results = await parallel_execute([
    "pytest tests/unit/",
    "pytest tests/integration/",
    "pytest tests/e2e/"
])

Cluster Status

# Get cluster health before heavy operations
status = await cluster_status()
# Returns:
# {
#   "local_node": "macpro51",
#   "nodes": {
#     "macpro51": {"cpu_percent": 15.2, "memory_percent": 45.3, ...},
#     "mac-studio": {"cpu_percent": 8.1, "memory_percent": 32.1, ...},
#     ...
#   }
# }

Cluster Nodes

Node

OS

Arch

Capabilities

Specialties

macpro51

Linux

x86_64

docker, podman, raid, nvme, compilation, testing, tpu

compilation, testing, containerization, benchmarking

mac-studio

macOS

ARM64

orchestration, coordination, temporal, mlx-gpu, arduino

orchestration, coordination, monitoring

macbook-air

macOS

ARM64

research, documentation, analysis

research, documentation, mobile

inference

macOS

ARM64

ollama, inference, model-serving, llm-api

ollama-inference, model-serving

Offload Patterns

Commands matching these patterns are automatically offloaded:

  • Build: make, cargo, npm, yarn, pnpm

  • Test: pytest, jest, mocha, test

  • Compile: gcc, g++, clang

  • Container: docker, podman, kubectl

  • File ops: rsync, scp, tar, zip, find, grep -r

Commands that stay local:

  • Simple: ls, pwd, cd, echo, cat, head, tail, which, type

Security

Shell Injection Prevention

All commands use subprocess.run() with list arguments where possible:

# SAFE: List arguments
subprocess.run(["ssh", "-o", "ConnectTimeout=5", f"{user}@{ip}", command])

# Complex shell commands are validated before execution

Command Validation

Commands are validated for dangerous patterns:

  • rm -rf /

  • rm -rf /*

  • > /dev/sda

  • Fork bombs

  • And more...

SSH Configuration

  • StrictHostKeyChecking=accept-new - Accept new hosts but verify returning hosts

  • BatchMode=yes - Non-interactive mode for scripting

  • Configurable timeouts and retries

Development

Running Tests

# Install dev dependencies
pip install -e ".[dev]"

# Run tests
pytest tests/ -v

# With coverage
pytest tests/ --cov=cluster_execution_mcp --cov-report=html

Project Structure

cluster-execution-mcp/
├── src/cluster_execution_mcp/
│   ├── __init__.py      # Package exports
│   ├── config.py        # Configuration, validation, node definitions
│   ├── router.py        # Task routing and IP resolution
│   └── server.py        # FastMCP server and tools
├── tests/
│   ├── conftest.py      # Pytest fixtures
│   ├── test_config.py   # Config module tests (29 tests)
│   ├── test_router.py   # Router module tests (21 tests)
│   └── test_server.py   # Server and tool tests (21 tests)
└── pyproject.toml       # Package configuration

CLI Interface

# Submit a command
cluster-router submit "make -j8 all"

# Check task status
cluster-router status <task_id>

# Show cluster status
cluster-router cluster-status

Monitoring

Check cluster health before operations:

User: "Show me cluster status"

Claude Code: cluster_status tool

Output:
  macpro51:
    CPU: 45.2%
    Memory: 18.3%
    Load: 3.21
    Status: healthy

  mac-studio:
    CPU: 22.1%
    Memory: 54.7%
    Load: 2.15
    Status: healthy

  macbook-air:
    CPU: 12.8%
    Memory: 38.2%
    Load: 1.03
    Status: healthy

Troubleshooting

MCP server not loading:

# Check config
cat ~/.claude.json | jq '.mcpServers["cluster-execution"]'

# Test server import
python3 -c "from cluster_execution_mcp.server import main; print('OK')"

Node unreachable:

# Test SSH connectivity
ssh marc@macpro51.local hostname
ssh marc@Marcs-Mac-Studio.local hostname

# Check with fallback IP
ssh marc@192.168.1.183 hostname

Commands timing out:

# Increase timeout via environment
export CLUSTER_CMD_TIMEOUT=600  # 10 minutes
export CLUSTER_SSH_TIMEOUT=10   # 10 seconds

Changelog

v0.2.0

  • New Features:

    • Proper package structure with pyproject.toml

    • Environment-based configuration (no hardcoded credentials)

    • Shared config module with validation functions

    • Retry logic for SSH connectivity

    • IP resolution caching with TTL

    • Inference node support

  • Security Improvements:

    • Eliminated shell injection vulnerabilities

    • Command validation for dangerous patterns

    • IP validation rejecting loopback/Docker/link-local

    • SSH host key handling (accept-new)

  • Code Quality:

    • Full type hints throughout codebase

    • Replaced bare except clauses with specific exceptions

    • Added comprehensive logging

    • 71 unit tests with mocking

  • Bug Fixes:

    • Fixed darwin/macos OS alias handling

    • Proper timeout handling in SSH operations

    • Better error messages for failed operations

v0.1.0

  • Initial release with basic cluster execution

License

MIT


Part of the AGI Agentic System

See also:

  • Node Chat MCP - Inter-node communication

  • Enhanced Memory MCP - Persistent memory with RAG

  • Agent Runtime MCP - Goals and task queue

Available Tools

4 tools
cluster_bashA

Execute bash command with automatic cluster routing.

Commands are automatically routed to optimal nodes based on:

  • Current cluster load (CPU, memory, load average)

  • Command characteristics (build/test/compile patterns)

  • Node capabilities (OS, architecture)

Heavy commands (make, cargo, pytest, docker, etc.) are automatically offloaded. Simple commands (ls, cat, echo) run locally for speed.

Parameters:

  • command (required): Bash command to execute

  • requires_os (optional): Force specific OS (linux/darwin)

  • requires_arch (optional): Force specific architecture (x86_64/arm64)

  • auto_route (optional): Enable auto-routing (default: true)

Returns execution result with node info and output.

ParametersJSON Schema
NameRequiredDescriptionDefault
commandYes
auto_routeNo
requires_osNo
requires_archNo

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

A4.4/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description bears full responsibility for transparency. It reveals routing logic (based on cluster load, command characteristics, node capabilities) and states that heavy commands are offloaded while simple ones run locally. It mentions returning execution result with node info and output. It lacks details on failure handling or timeouts, but overall provides solid behavioral context.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is concisely structured with bullet points for routing criteria and parameters. Every sentence adds value, and the information is front-loaded: the first line states the core function. No wasted words.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

The description covers routing logic, parameter details, and return value. With an output schema present, it does not need to detail return format. It is complete for a tool with 4 parameters, though it could mention error scenarios or security considerations. Overall, it provides sufficient context for an AI agent to use the tool correctly.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate. It explains each parameter: command (required), requires_os/requires_arch (force specific OS/architecture), auto_route (default true). It adds meaning beyond the schema by describing the purpose of requires_os/requires_arch and the auto-routing default. However, it does not enumerate all possible values for requires_os/requires_arch.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states 'Execute bash command with automatic cluster routing', specifying the action (execute), resource (bash command), and core behavior (automatic routing). It distinguishes from siblings like cluster_status (status check) and offload_to (manual offloading) by emphasizing automatic routing.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description explains when to use the tool: for bash commands with automatic routing. It categorizes commands as 'heavy' (offloaded) or 'simple' (local). It also describes parameters like requires_os and requires_arch for forcing specific nodes. However, it does not explicitly mention when not to use it or compare to siblings.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

cluster_statusA

Get current cluster status and load distribution.

Shows real-time metrics for all cluster nodes:

  • CPU usage percentage

  • Memory usage percentage

  • 1-minute load average

  • Active task count

  • Health status (healthy/overloaded)

  • Reachability

Use this to:

  • Check cluster health before heavy operations

  • Determine optimal node for manual routing

  • Debug cluster connectivity issues

  • Monitor distributed execution

Returns JSON with status for each node.

ParametersJSON Schema
NameRequiredDescriptionDefault

No parameters

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

A4.5/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full responsibility. It discloses real-time nature, listed metrics, and JSON output. It omits details like refresh rate or potential latency, but these are minor for a read-only tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Description is well-structured with a brief opening, bullet list of metrics, and actionable use cases. Every sentence adds value; no redundancy.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a parameterless tool with an output schema mentioned, the description covers purpose, metrics, use cases, and return format. It fully informs the agent's decision alongside sibling tools.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

No parameters exist, so schema coverage is complete. The description adds no parameter info (none needed). Baseline for 0 parameters is 4, which is appropriate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

Description clearly states it gets cluster status and load distribution with specific metrics. It is distinct from sibling tools like cluster_bash (execution) and offload_to/parallel_execute (task routing), making it easy to select.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Explicit usage scenarios are listed (check health, determine optimal node, debug, monitor). While it doesn't explicitly say when not to use it, the provided contexts are clear and sufficient. Missing exclusions reduces to 4.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

offload_toA

Explicitly route command to specific cluster node.

Use when you need to:

  • Run Linux-specific commands -> offload to macpro51

  • Test on specific architecture

  • Balance load manually

  • Debug node-specific issues

Available nodes:

  • macpro51: Linux x86_64 builder (docker, podman, compilation)

  • mac-studio: macOS ARM64 orchestrator

  • macbook-air: macOS ARM64 researcher

Parameters:

  • command (required): Bash command to execute

  • node_id (required): Target node ID

Returns execution result from specified node.

ParametersJSON Schema
NameRequiredDescriptionDefault
commandYes
node_idYes

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

A4/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations provided, so description carries full burden, but it only states routing and returns execution result, lacking details on safety, authentication, rate limits, or side effects of command execution.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Structured with bullet points, front-loaded purpose, every sentence adds value, no wasted words.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Covers main aspects: purpose, use cases, nodes, parameters, and return value (execution result); output schema exists. Missing error handling or failure modes.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 0%, description adds meaning by explaining command is a bash command and node_id is target node ID, and lists available nodes, but lacks details on format, constraints, or examples.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

Explicitly states routing command to specific cluster node, lists use cases and available nodes, clearly differentiating from sibling tools like cluster_bash, cluster_status, and parallel_execute.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Provides explicit when-to-use scenarios (Linux commands, specific architecture, load balancing, debugging) and lists available nodes, though does not directly compare to siblings or mention when not to use.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

parallel_executeA

Execute multiple commands in parallel across cluster.

Distributes commands across available nodes for maximum parallelism. Use for:

  • Running test suites across multiple files

  • Parallel builds

  • Batch processing

  • Load testing

Commands are automatically distributed based on node availability and load.

Parameters:

  • commands (required): List of bash commands to execute in parallel

Returns list of results, one per command, with execution details.

ParametersJSON Schema
NameRequiredDescriptionDefault
commandsYes

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

A3.7/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations provided, so description carries burden. Mentions automatic distribution based on node availability and load, and return format, but lacks details on error handling, timeouts, or resource effects.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Well-structured with bullet points for use cases, but slightly redundant (mentions distribution twice). Generally concise for the content.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Covers purpose, usage, and basic behavior for a simple one-parameter tool, but lacks details on error handling, limits, or output schema specifics.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 0%; description only repeats that commands is a list of bash commands, adding minimal meaning beyond the property name.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

Clearly states the action (execute multiple commands in parallel across cluster) and distinguishes from sibling tools like cluster_bash (likely single command) and cluster_status (status).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Provides explicit use cases (test suites, parallel builds, batch processing, load testing) and describes distribution behavior, but does not explicitly state when not to use or suggest alternatives.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

TDQS

A3.9/5.0
Disambiguation5/5

Each tool has a clearly distinct purpose: cluster_bash for general command execution, cluster_status for monitoring, offload_to for explicit routing to a node, and parallel_execute for batch execution. There is no overlap in functionality.

Naming Consistency2/5

Tool names follow mixed conventions: cluster_bash and cluster_status share a prefix, but offload_to and parallel_execute use verb phrases without the prefix. The naming patterns are inconsistent, making it harder to infer the pattern at a glance.

Tool Count4/5

With 4 tools, the server is lean but covers the core functions of cluster execution. It could benefit from a dedicated node listing tool, but the count is appropriate for its scope.

Completeness4/5

The tool set covers the key operations: executing commands, getting status, explicit routing, and parallel execution. Minor gaps like the absence of a tool to list available nodes dynamically are present but do not severely hinder typical workflows.

Maintenance

ActivityInactive
ResponsivenessSyncing

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Connectors

Related MCP Servers

  • A
    license
    Not graded
    quality
    D
    maintenance
    Transforms idle LAN machines into a unified compute cluster for AI agents to offload CPU-intensive tasks like simulations and backtesting. It provides a broker-worker architecture that integrates with MCP-compatible tools to distribute workloads across a local network.
    5
    MIT
  • A
    license
    Not graded
    quality
    D
    maintenance
    Enables LLMs to execute CLI commands and scripts for system deployment and management tasks, with support for directory listing, system info, and deployment templates.
    1
    MIT
  • A
    license
    Not graded
    quality
    C
    maintenance
    Enables AI agents to orchestrate a heterogeneous machine fleet via SSH, with unified command execution, file transfer, and dispatch of coding agents across platforms.
    1
    Apache 2.0

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/marc-shade/cluster-execution-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server