mc

mcp-server-commands

Run any command with `run_command` and `run_script` tools.

Publishermcp-server-commands
Submitted date4/13/2025

Unleashing LLMs: The Power of Tools and the Model Context Protocol

The Model Context Protocol (MCP) is revolutionizing how Large Language Models (LLMs) interact with the world. By providing a standardized interface for LLMs to access external data sources and tools, MCP unlocks a new realm of possibilities for AI-powered applications. This document delves into the practical application of MCP, focusing on the use of tools to extend the capabilities of LLMs like Claude.

Empowering LLMs with Tools

Tools enable LLMs to perform actions and gather information beyond their pre-trained knowledge. Consider them as extensions of the LLM's capabilities, allowing them to interact with the environment and access real-time data.

This implementation provides two powerful tools:

  • run_command: Executes shell commands directly on the server. This allows the LLM to perform tasks such as:
    • Retrieving system information (hostname)
    • Listing directory contents (ls -al)
    • Performing simple text manipulation (echo "hello world")
    • The tool returns both standard output (STDOUT) and standard error (STDERR) as text, providing comprehensive feedback to the LLM.
  • run_script: Executes scripts written in various languages (e.g., fish, bash, zsh, python). This empowers the LLM to:
    • Run code it generates dynamically.
    • Perform complex operations that are difficult or impossible with single commands.
    • Leverage the full power of scripting languages for data processing and automation.
    • The script is passed to the tool via standard input (STDIN), and the tool functions as run_command with the script provided as input.
    • Interestingly, LLMs like Claude have demonstrated creativity in using this tool, even employing cat as an interpreter to create new files.

Security Considerations:

[!WARNING] Exercising caution when using these tools is paramount. The run_command and run_script tools can potentially execute arbitrary code on the server.

When using with Claude Desktop, it is highly recommended to use the Approve Once option instead of Allow for This Chat. This allows you to carefully review each command before execution. If you are unsure about the safety of a command, use the Deny option.

The permissions granted to the LLM are determined by the user account running the server. Never run the server with sudo or elevated privileges.

Practical Applications: Prompts for Interaction

Prompts serve as the bridge between the user and the LLM, guiding its behavior and providing context. In environments like Zed's AI Chat panel, prompts can be used to trigger specific actions.

  • run_command Prompt: This prompt type allows users to directly request the execution of a command and receive the output within the chat interface.

Development and Setup

This section outlines the steps required to set up and run the MCP server.

Prerequisites:

  • Node.js and npm installed

Installation:

  1. Install Dependencies:
    npm install
  2. Build the Server:
    npm run build
  3. Development Mode (Auto-Rebuild):
    npm run watch

Integration with Claude Desktop

To enable the MCP server within the Claude Desktop application, you need to configure the claude_desktop_config.json file.

Configuration File Location:

  • MacOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%/Claude/claude_desktop_config.json

Configuration Options:

Option 1: Using the Published npm Package

This is the recommended approach for most users.

{ "mcpServers": { "mcp-server-commands": { "command": "npx", "args": ["mcp-server-commands"] } } }

Option 2: Using a Local Build (Repo Checkout)

This option is useful for developers who are actively modifying the server code.

{ "mcpServers": { "mcp-server-commands": { // works b/c of shebang in index.js "command": "/path/to/mcp-server-commands/build/index.js" } } }

Monitoring and Debugging

Effective monitoring and debugging are crucial for ensuring the stability and reliability of the MCP server.

Logging:

Claude Desktop writes logs to: ~/Library/Logs/Claude/mcp-server-mcp-server-commands.log

By default, only errors and important messages are logged. To increase the verbosity of the logs, add the --verbose flag to the args in the server configuration.

Example:

{ "mcpServers": { "mcp-server-commands": { "command": "npx", "args": ["mcp-server-commands", "--verbose"] } } }

Note: Logs are written to STDERR because that is the channel used by Claude Desktop for log file routing. Future implementations may utilize the STDIO transport for more structured log messages.

Debugging with MCP Inspector:

The MCP Inspector provides a powerful set of debugging tools for MCP servers. It can be launched using the following npm script:

npm run inspector

This will provide a URL to access the Inspector in your browser, allowing you to inspect the communication between the LLM and the server.

By leveraging the power of tools and the Model Context Protocol, developers can create intelligent and interactive AI applications that seamlessly integrate with the real world.

Visit More

View All