CLI MCP Server

CLI MCP Server avatar

by anjumanraut

Browser Automation

A simplified MCP server for terminal command execution

What is CLI MCP Server

Command

This repository contains a Model Context Protocol (MCP) server implementation for executing commands. It allows MCP-compatible AI assistants to execute commands in specified directories.

About the Model Context Protocol (MCP)

The Model Context Protocol (MCP) is an open standard developed by Anthropic that enables secure, two-way connections between data sources and AI-powered tools. MCP servers expose data and functionality to AI applications, allowing AI models to intelligently retrieve, process, and leverage information across private data sources.

Tool Schema

This MCP server provides one universal tool called "command" that gives AI agents a broad range of abilities to execute commands in specified directories.

{
  "name": "command",
  "description": "Execute commands in a specified directory",
  "inputSchema": {
    "type": "object",
    "properties": {
      "command": {
        "type": "string",
        "description": "Command to execute"
      },
      "workingDir": {
        "type": "string",
        "description": "Working directory for command execution"
      }
    },
    "required": ["command", "workingDir"]
  }
}

Parameters Description

  • command: The shell command that will be executed (e.g., "ls -la", "dir", "git status")
  • workingDir: The directory where the command will be executed. This must be one of the allowed directories specified in the configuration.

Project Structure

/command
โ”œโ”€โ”€ config/                     # Configuration-related files
โ”‚   โ”œโ”€โ”€ index.js                # Main config exporter
โ”‚   โ””โ”€โ”€ validation.js           # Configuration validation logic
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ core/                   # Core server functionality
โ”‚   โ”‚   โ”œโ”€โ”€ server.js           # Server initialization & management
โ”‚   โ”‚   โ””โ”€โ”€ handlers.js         # MCP request handlers
โ”‚   โ”œโ”€โ”€ tools/                  # Tool implementations
โ”‚   โ”‚   โ”œโ”€โ”€ index.js            # Exports all tools
โ”‚   โ”‚   โ””โ”€โ”€ command/            # Command tool module
โ”‚   โ”‚       โ”œโ”€โ”€ index.js        # Main command tool export
โ”‚   โ”‚       โ”œโ”€โ”€ schema.js       # Command tool schema
โ”‚   โ”‚       โ”œโ”€โ”€ executor.js     # Command execution logic
โ”‚   โ”‚       โ””โ”€โ”€ worker.js       # Command worker implementation
โ”‚   โ”œโ”€โ”€ utils/                  # Utility functions
โ”‚   โ”‚   โ”œโ”€โ”€ logging.js          # Logging utilities
โ”‚   โ”‚   โ””โ”€โ”€ error.js            # Error handling utilities
โ”‚   โ””โ”€โ”€ index.js                # Application entry point
โ”œโ”€โ”€ tests/                      # Test directory
โ”‚   โ””โ”€โ”€ config.test.js          # Configuration tests
โ”œโ”€โ”€ logs/                       # Log output directory
โ”œโ”€โ”€ scripts/                    # Scripts for running/building
โ”‚   โ”œโ”€โ”€ start-server.sh         # Unix start script
โ”‚   โ””โ”€โ”€ start-server.bat        # Windows start script
โ”œโ”€โ”€ package.json                # Project metadata and dependencies
โ””โ”€โ”€ README.md                   # Project documentation

Setup Instructions

Prerequisites

  • Node.js (v16 or higher)
  • npm (v7 or higher)

Local Setup

  1. Install dependencies:
npm install

Configuration

To use this server with Claude, you need to update your Claude configuration to include the Command server.

Update your Claude configuration file (typically located at ~/.config/claude/claude_desktop_config.json or ~/Library/Application Support/Claude/claude_desktop_config.json) to include the following:

{
  "mcpServers": {
    "command": {
      "command": "/path/to/command/start-server.sh",
      "args": [
        "/path/to/allowed/directory1",
        "/path/to/allowed/directory2",
        "/path/to/allowed/directory3"
      ]
    }
  }
}

Replace /path/to/command with the actual path where this repository is located.

Replace /path/to/allowed/directory1, /path/to/allowed/directory2, etc. with the directories you want to allow Claude to execute commands in.

For Windows, use the batch file instead:

{
  "mcpServers": {
    "command": {
      "command": "C:\\path\\to\\command\\start-server.bat",
      "args": [
        "C:\\path\\to\\allowed\\directory1",
        "C:\\path\\to\\allowed\\directory2",
        "C:\\path\\to\\allowed\\directory3"
      ]
    }
  }
}

Usage

Once configured, Claude can execute commands in the specified directories through the CLI MCP server.

The server accepts directory paths as arguments. Only these directories will be accessible for command execution.

Example usage in Claude:

Please run the following command:
command("ls -la", "/path/to/allowed/directory1")

On Windows, you might use:

Please run the following command:
command("dir", "C:\\path\\to\\allowed\\directory1")

Development

Available Scripts

  • npm start - Run the server
  • npm run dev - Run the server with auto-reload on file changes
  • npm test - Run the test suite

Security Considerations

  • The server only allows commands to be executed in directories specified as command-line arguments.
  • Be cautious about the directories you expose to Claude, as it will have access to execute commands in these locations.
  • Consider using a dedicated user with limited permissions for running the server.
  • Review the commands executed by Claude to ensure they are safe and appropriate.
  • The server includes path validation to prevent access to unauthorized directories.

License

MIT License

Leave a Comment

Comments section will be available soon. Stay tuned!

Frequently Asked Questions

What is MCP?

MCP (Model Context Protocol) is an open protocol that standardizes how applications provide context to LLMs. Think of MCP like a USB-C port for AI applications, providing a standardized way to connect AI models to different data sources and tools.

What are MCP Servers?

MCP Servers are lightweight programs that expose specific capabilities through the standardized Model Context Protocol. They act as bridges between LLMs like Claude and various data sources or services, allowing secure access to files, databases, APIs, and other resources.

How do MCP Servers work?

MCP Servers follow a client-server architecture where a host application (like Claude Desktop) connects to multiple servers. Each server provides specific functionality through standardized endpoints and protocols, enabling Claude to access data and perform actions through the standardized protocol.

Are MCP Servers secure?

Yes, MCP Servers are designed with security in mind. They run locally with explicit configuration and permissions, require user approval for actions, and include built-in security features to prevent unauthorized access and ensure data privacy.