Skip to main content
Glama
DynamicEndpoints

PowerShell Exec MCP Server

run_powershell

Execute PowerShell commands securely with configurable timeouts for enterprise automation, system monitoring, and management platform script generation.

Instructions

Execute PowerShell commands securely.

Args:
    code: PowerShell code to execute
    timeout: Command timeout in seconds (1-300, default 60)
    ctx: MCP context for logging and progress reporting

Returns:
    Command output as string

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYes
timeoutNo
ctxNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • run.py:45-72 (registration)
    Registers the run_powershell tool including its input schema in the ListTools response.
    @server.setRequestHandler(ListToolsRequestSchema)
    async def handle_list_tools():
        return {
            "tools": [
                {
                    "name": "run_powershell",
                    "description": "Execute PowerShell commands securely",
                    "inputSchema": {
                        "type": "object",
                        "properties": {
                            "code": {
                                "type": "string",
                                "description": "PowerShell code to execute"
                            },
                            "timeout": {
                                "type": "integer",
                                "description": "Command timeout in seconds",
                                "minimum": 1,
                                "maximum": 300,
                                "default": 60
                            }
                        },
                        "required": ["code"]
                    }
                }
            ]
        }
  • run.py:53-69 (schema)
    Input schema definition for the run_powershell tool.
            "type": "object",
            "properties": {
                "code": {
                    "type": "string",
                    "description": "PowerShell code to execute"
                },
                "timeout": {
                    "type": "integer",
                    "description": "Command timeout in seconds",
                    "minimum": 1,
                    "maximum": 300,
                    "default": 60
                }
            },
            "required": ["code"]
        }
    }
  • run.py:74-139 (handler)
    Main handler for run_powershell tool: validates input, executes PowerShell command with timeout handling, returns stdout or errors.
    @server.setRequestHandler(CallToolRequestSchema)
    async def handle_tool_call(request):
        if request.params.name != "run_powershell":
            raise McpError(
                ErrorCode.MethodNotFound,
                f"Unknown tool: {request.params.name}"
            )
    
        code = request.params.arguments.get("code")
        if not isinstance(code, str):
            raise McpError(
                ErrorCode.InvalidParams,
                "code parameter must be a string"
            )
    
        timeout = request.params.arguments.get("timeout", 60)
        if not isinstance(timeout, int) or timeout < 1 or timeout > 300:
            raise McpError(
                ErrorCode.InvalidParams,
                "timeout must be between 1 and 300 seconds"
            )
    
        try:
            process = await asyncio.create_subprocess_exec(
                "powershell",
                "-NoProfile",
                "-NonInteractive",
                "-Command",
                code,
                stdout=subprocess.PIPE,
                stderr=subprocess.PIPE,
                text=True
            )
    
            stdout, stderr = await asyncio.wait_for(
                process.communicate(),
                timeout=timeout
            )
    
            if process.returncode != 0:
                raise McpError(
                    ErrorCode.InternalError,
                    stderr or "Command failed with no error output"
                )
    
            return {
                "content": [
                    {
                        "type": "text",
                        "text": stdout
                    }
                ]
            }
    
        except asyncio.TimeoutError:
            process.kill()
            raise McpError(
                ErrorCode.Timeout,
                f"Command timed out after {timeout} seconds"
            )
        except Exception as e:
            raise McpError(
                ErrorCode.InternalError,
                str(e)
            )
Behavior3/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions 'securely' which hints at safety considerations, and describes the return value format. However, it doesn't address important behavioral aspects like error handling, permissions required, side effects, or what 'securely' specifically entails.

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 well-structured with clear sections (purpose, Args, Returns), uses bullet-like formatting for parameters, and contains no redundant information. Every sentence serves a specific purpose in explaining the tool's functionality.

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?

Given the tool's complexity (executing arbitrary PowerShell code) and no annotations, the description does well by documenting all parameters and the return format. However, it could provide more context about security implications, execution environment, or error scenarios to be fully complete for such a powerful tool.

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

Parameters5/5

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

Despite 0% schema description coverage, the description provides comprehensive parameter documentation in the 'Args' section, explaining each parameter's purpose and constraints (e.g., timeout range 1-300 with default 60). This fully compensates for the schema's lack of descriptions.

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 tool's purpose with a specific verb ('Execute') and resource ('PowerShell commands'), plus the qualifier 'securely' which distinguishes it from generic execution tools. It precisely communicates what the tool does without being tautological.

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 implies usage context (executing PowerShell code) but doesn't explicitly state when to use this tool versus its sibling 'run_powershell_with_progress'. It provides general guidance but lacks specific differentiation from alternatives.

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/DynamicEndpoints/PowerShell-Exec-MCP-Server'

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