Skip to main content
Glama
lin2000wl

Serena MCP Server

by lin2000wl

execute_shell_command

Execute shell commands directly from the Serena MCP Server to run system operations, manage files, and perform terminal tasks with output capture.

Instructions

Execute a shell command and return its output.

IMPORTANT: you should always consider the memory about suggested shell commands before using this tool. If this memory was not loaded in the current conversation, you should load it using the read_memory tool before using this tool.

You should have at least once looked at the suggested shell commands from the corresponding memory created during the onboarding process before using this tool. Never execute unsafe shell commands like rm -rf / or similar! Generally be very careful with deletions. Returns a JSON object containing the command's stdout and optionally stderr output.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
commandYesThe shell command to execute.
cwdNoThe working directory to execute the command in. If None, the project root will be used.
capture_stderrNoWhether to capture and return stderr output.
max_answer_charsNoIf the output is longer than this number of characters, no content will be returned. Don't adjust unless there is really no other way to get the content required for the task.

Implementation Reference

  • The handler function that executes the given shell command in the specified directory, optionally capturing stderr, and returns structured output including stdout, stderr, return code, and cwd.
    def execute_shell_command(command: str, cwd: str | None = None, capture_stderr: bool = False) -> ShellCommandResult:
        """
        Execute a shell command and return the output.
    
        :param command: The command to execute.
        :param cwd: The working directory to execute the command in. If None, the current working directory will be used.
        :param capture_stderr: Whether to capture the stderr output.
        :return: The output of the command.
        """
        if cwd is None:
            cwd = os.getcwd()
    
        is_windows = platform.system() == "Windows"
        process = subprocess.Popen(
            command,
            shell=not is_windows,
            stdin=subprocess.DEVNULL,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE if capture_stderr else None,
            creationflags=subprocess.CREATE_NO_WINDOW if is_windows else 0,  # type: ignore
            text=True,
            encoding="utf-8",
            errors="replace",
            cwd=cwd,
        )
    
        stdout, stderr = process.communicate()
        return ShellCommandResult(stdout=stdout, stderr=stderr, return_code=process.returncode, cwd=cwd)
  • Pydantic BaseModel defining the output schema for the shell command execution result.
    class ShellCommandResult(BaseModel):
        stdout: str
        return_code: int
        cwd: str
        stderr: str | None = None
Behavior4/5

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

With no annotations provided, the description carries full burden and does so effectively. It discloses critical behavioral traits: safety warnings about dangerous commands, memory prerequisites, output format (JSON with stdout/stderr), and a character limit constraint. It doesn't mention rate limits or authentication needs, but covers the most essential behavioral aspects for a shell execution tool.

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?

The description is appropriately sized and front-loaded with the core purpose. Each sentence adds value: purpose, prerequisites, safety warnings, and output format. While slightly verbose due to the safety emphasis, every sentence serves a clear function in guiding proper tool usage.

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?

For a potentially dangerous shell execution tool with no annotations and no output schema, the description provides substantial context: safety constraints, prerequisites, behavioral warnings, and output format. It doesn't specify error handling or timeout behavior, but covers the critical aspects needed for responsible tool invocation given the complexity and risk profile.

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 description coverage is 100%, providing complete parameter documentation. The description adds minimal parameter-specific information beyond the schema, only mentioning that output includes 'stdout and optionally stderr' which relates to the capture_stderr parameter. This meets the baseline 3 when schema coverage is high.

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 the specific action ('Execute a shell command') and the outcome ('return its output'), distinguishing it from all sibling tools which are file operations, memory management, or project utilities. It provides a complete verb+resource+result statement that leaves no ambiguity about its function.

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

Usage Guidelines5/5

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

The description provides explicit guidance on when to use this tool: only after consulting the 'suggested shell commands' memory via `read_memory`, and never for unsafe commands like `rm -rf /`. It also specifies prerequisites (memory must be loaded) and clear exclusions (unsafe deletions), offering comprehensive usage context.

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

Install Server

Other Tools

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/lin2000wl/Serena-cursor-mcp'

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