Skip to main content
Glama
alxspiker

Windows Command Line MCP Server

get_scheduled_tasks

Retrieve and query scheduled tasks or check detailed status of a specific task on a Windows system using a secure command-line MCP server.

Instructions

Retrieve information about scheduled tasks on the system. Can query all tasks or get detailed status of a specific task.

Input Schema

NameRequiredDescriptionDefault
actionNoAction to performquery
taskNameNoName of the specific task (optional)

Input Schema (JSON Schema)

{ "$schema": "http://json-schema.org/draft-07/schema#", "additionalProperties": false, "properties": { "action": { "default": "query", "description": "Action to perform", "enum": [ "query", "status" ], "type": "string" }, "taskName": { "description": "Name of the specific task (optional)", "type": "string" } }, "type": "object" }

Implementation Reference

  • The anonymous async handler function implementing the core logic for the get_scheduled_tasks tool. It constructs and executes PowerShell commands to query or get status of scheduled tasks based on parameters.
    async ({ action, taskName }) => { if (!isWindows) { return { content: [ { type: "text", text: "The scheduled tasks tool is only available on Windows. Current platform: " + platform(), }, ], }; } try { let cmd = "powershell.exe -Command \""; if (action === "query") { if (taskName) { cmd += "Get-ScheduledTask -TaskName '" + taskName + "' | Format-List TaskName, State, Description, Author, LastRunTime, NextRunTime, LastTaskResult"; } else { cmd += "Get-ScheduledTask | Select-Object TaskName, State, Description | Format-Table -AutoSize | Out-String"; } } else if (action === "status" && taskName) { cmd += "Get-ScheduledTask -TaskName '" + taskName + "' | Format-List *; " + "Get-ScheduledTaskInfo -TaskName '" + taskName + "' | Format-List *"; } else { return { isError: true, content: [ { type: "text", text: "For 'status' action, taskName parameter is required", }, ], }; } cmd += "\""; const stdout = executeCommand(cmd); return { content: [ { type: "text", text: stdout.toString(), }, ], }; } catch (error) { return { isError: true, content: [ { type: "text", text: `Error retrieving scheduled tasks: ${error}`, }, ], }; } }
  • Zod input schema defining parameters for the get_scheduled_tasks tool: action (query or status) and optional taskName.
    { action: z.enum(["query", "status"]).default("query").describe("Action to perform"), taskName: z.string().optional().describe("Name of the specific task (optional)"), },
  • index.ts:255-323 (registration)
    MCP server.tool registration for the get_scheduled_tasks tool, specifying name, description, input schema, and inline handler.
    // Register the get_scheduled_tasks tool server.tool( "get_scheduled_tasks", "Retrieve information about scheduled tasks on the system. Can query all tasks or get detailed status of a specific task.", { action: z.enum(["query", "status"]).default("query").describe("Action to perform"), taskName: z.string().optional().describe("Name of the specific task (optional)"), }, async ({ action, taskName }) => { if (!isWindows) { return { content: [ { type: "text", text: "The scheduled tasks tool is only available on Windows. Current platform: " + platform(), }, ], }; } try { let cmd = "powershell.exe -Command \""; if (action === "query") { if (taskName) { cmd += "Get-ScheduledTask -TaskName '" + taskName + "' | Format-List TaskName, State, Description, Author, LastRunTime, NextRunTime, LastTaskResult"; } else { cmd += "Get-ScheduledTask | Select-Object TaskName, State, Description | Format-Table -AutoSize | Out-String"; } } else if (action === "status" && taskName) { cmd += "Get-ScheduledTask -TaskName '" + taskName + "' | Format-List *; " + "Get-ScheduledTaskInfo -TaskName '" + taskName + "' | Format-List *"; } else { return { isError: true, content: [ { type: "text", text: "For 'status' action, taskName parameter is required", }, ], }; } cmd += "\""; const stdout = executeCommand(cmd); return { content: [ { type: "text", text: stdout.toString(), }, ], }; } catch (error) { return { isError: true, content: [ { type: "text", text: `Error retrieving scheduled tasks: ${error}`, }, ], }; } } );
  • Helper function executeCommand used by the handler to safely run the constructed PowerShell command on Windows or adapted for other platforms.
    function executeCommand(command: string, options: any = {}) { if (isWindows) { return execSync(command, options); } else { // Log warning for non-Windows environments console.error(`Warning: Running in a non-Windows environment (${platform()}). Windows commands may not work.`); // For testing purposes on non-Windows platforms try { // For Linux/MacOS, we'll strip cmd.exe and powershell.exe references let modifiedCmd = command; // Replace cmd.exe /c with empty string modifiedCmd = modifiedCmd.replace(/cmd\.exe\s+\/c\s+/i, ''); // Replace powershell.exe -Command with empty string or a compatible command modifiedCmd = modifiedCmd.replace(/powershell\.exe\s+-Command\s+("|')/i, ''); // Remove trailing quotes if we removed powershell -Command if (modifiedCmd !== command) { modifiedCmd = modifiedCmd.replace(/("|')$/, ''); } console.error(`Attempting to execute modified command: ${modifiedCmd}`); return execSync(modifiedCmd, options); } catch (error) { console.error(`Error executing modified command: ${error}`); return Buffer.from(`This tool requires a Windows environment. Current platform: ${platform()}`); } } }

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/alxspiker/Windows-Command-Line-MCP-Server'

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