Skip to main content
Glama

run_script

Execute PowerShell scripts on Windows systems through the PowerShell MCP Server by specifying the script path and optional parameters for automation and system management tasks.

Input Schema

NameRequiredDescriptionDefault
parametersNoOptional parameters to pass to the script
scriptPathYesPath to the PowerShell script file

Input Schema (JSON Schema)

{ "$schema": "http://json-schema.org/draft-07/schema#", "additionalProperties": false, "properties": { "parameters": { "description": "Optional parameters to pass to the script", "type": "string" }, "scriptPath": { "description": "Path to the PowerShell script file", "type": "string" } }, "required": [ "scriptPath" ], "type": "object" }

Implementation Reference

  • The asynchronous handler function for the 'run_script' tool. It constructs a PowerShell command to execute the script file with optional parameters using execAsync, handles stdout/stderr, and returns formatted content or error response.
    async ({ scriptPath, parameters }: { scriptPath: string; parameters?: string }) => { try { const fullCommand = parameters ? `powershell -File "${scriptPath}" ${parameters}` : `powershell -File "${scriptPath}"`; const { stdout, stderr } = await execAsync(fullCommand); if (stderr) { return { isError: true, content: [ { type: 'text' as const, text: `Error running script: ${stderr}`, }, ], }; } return { content: [ { type: 'text' as const, text: stdout || 'Script executed successfully with no output.', }, ], }; } catch (error) { return { isError: true, content: [ { type: 'text' as const, text: `Error running script: ${(error as Error).message}`, }, ], }; }
  • Zod input schema defining 'scriptPath' as required string (path to PS script) and 'parameters' as optional string.
    { scriptPath: z.string().describe('Path to the PowerShell script file'), parameters: z.string().optional().describe('Optional parameters to pass to the script'),
  • src/index.ts:313-359 (registration)
    Registration of the 'run_script' tool on the MCP server using this.server.tool(), specifying the name, input schema, and handler function.
    this.server.tool( 'run_script', { scriptPath: z.string().describe('Path to the PowerShell script file'), parameters: z.string().optional().describe('Optional parameters to pass to the script'), }, async ({ scriptPath, parameters }: { scriptPath: string; parameters?: string }) => { try { const fullCommand = parameters ? `powershell -File "${scriptPath}" ${parameters}` : `powershell -File "${scriptPath}"`; const { stdout, stderr } = await execAsync(fullCommand); if (stderr) { return { isError: true, content: [ { type: 'text' as const, text: `Error running script: ${stderr}`, }, ], }; } return { content: [ { type: 'text' as const, text: stdout || 'Script executed successfully with no output.', }, ], }; } catch (error) { return { isError: true, content: [ { type: 'text' as const, text: `Error running script: ${(error as Error).message}`, }, ], }; } } );

Other Tools

Related 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/posidron/mcp-powershell'

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