Skip to main content
Glama
simon-ami

Windows CLI MCP Server

by simon-ami

get_command_history

Retrieve recent command execution records from Windows CLI sessions to review past actions, outputs, and timestamps for troubleshooting or auditing purposes.

Instructions

Get the history of executed commands

Example usage:

{
  "limit": 5
}

Example response:

[
  {
    "command": "Get-Process",
    "output": "...",
    "timestamp": "2024-03-20T10:30:00Z",
    "exitCode": 0
  }
]

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
limitNoMaximum number of history entries to return (default: 10, max: 1000)

Implementation Reference

  • Handler function for the 'get_command_history' tool. Checks if command logging is enabled, parses optional limit parameter, retrieves recent history entries from this.commandHistory, truncates output, and returns JSON-formatted history.
    case "get_command_history": {
      if (!this.config.security.logCommands) {
        return {
          content: [{
            type: "text",
            text: "Command history is disabled in configuration. Consult the server admin for configuration changes (config.json - logCommands)."
          }]
        };
      }
    
      const args = z.object({
        limit: z.number()
          .min(1)
          .max(this.config.security.maxHistorySize)
          .optional()
          .default(10)
      }).parse(request.params.arguments);
    
      const history = this.commandHistory
        .slice(-args.limit)
        .map(entry => ({
          ...entry,
          output: entry.output.slice(0, 1000) // Limit output size
        }));
    
      return {
        content: [{
          type: "text",
          text: JSON.stringify(history, null, 2)
        }]
      };
    }
  • src/index.ts:324-355 (registration)
    Registration of the 'get_command_history' tool in the list of tools returned by ListToolsRequestSchema, including description and input schema definition.
            {
              name: "get_command_history",
              description: `Get the history of executed commands
    
    Example usage:
    \`\`\`json
    {
      "limit": 5
    }
    \`\`\`
    
    Example response:
    \`\`\`json
    [
      {
        "command": "Get-Process",
        "output": "...",
        "timestamp": "2024-03-20T10:30:00Z",
        "exitCode": 0
      }
    ]
    \`\`\``,
              inputSchema: {
                type: "object",
                properties: {
                  limit: {
                    type: "number",
                    description: `Maximum number of history entries to return (default: 10, max: ${this.config.security.maxHistorySize})`
                  }
                }
              }
            },
  • Type definition for CommandHistoryEntry used in command history storage and output of get_command_history tool.
    export interface CommandHistoryEntry {
      command: string;
      output: string;
      timestamp: string;
      exitCode: number;
      connectionId?: string;
    }

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observed

TDQS

A4/5.0
Behavior3/5

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

No annotations are provided, so the description carries the full burden. It adds transparency by showing a detailed example response with fields (command, output, timestamp, exitCode), which clarifies the return format. However, it does not explicitly state whether history is session-scoped, how results are ordered, or that it has no side effects. Given the absence of annotations, there are notable but not critical gaps.

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 concise: a single opening sentence plus two compact JSON examples. The purpose is front-loaded, and every element adds value—the example usage demonstrates the parameter, and the example response shows the expected output structure. No redundancy or filler.

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 simple one-parameter, no-output-schema tool, the description is quite complete: it states the purpose, shows how to invoke it, and provides a representative response. Minor omissions like ordering or session scope are not critical for a list-history tool. The example response effectively substitutes for an output schema, making the tool actionable for an agent.

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?

The input schema already fully documents the 'limit' parameter with default (10) and max (1000) values, providing 100% coverage. The description's example usage (limit: 5) reinforces the parameter but adds no new semantic meaning beyond the schema. Baseline 3 is appropriate because the schema does the heavy lifting.

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 opens with a clear verb+resource statement: 'Get the history of executed commands'. It distinguishes itself from sibling tools like execute_command (execution) and ssh_execute (remote execution) by focusing specifically on retrieval of prior commands. The example response reinforces the purpose.

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 provides a clear usage context: to retrieve previously executed commands, with an example showing the optional limit parameter. It does not explicitly state when not to use it, but the purpose is self-evident and no competing history tools exist among siblings. No explicit exclusions are given, but this is clearly a read-only counterpart to the execution siblings.

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