get_command_history
Retrieve a history of previously executed commands on the Windows CLI MCP Server, including details like command, output, timestamp, and exit code, with customizable limit options.
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
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | Maximum number of history entries to return (default: 10, max: 1000) |
Implementation Reference
- src/index.ts:438-469 (handler)Handler for the get_command_history tool. Checks if logging is enabled, parses optional limit parameter (default 10, max from config), retrieves recent history entries from this.commandHistory, truncates long outputs, and returns formatted JSON.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:176-207 (registration)Tool registration in ListTools response, defining name, description, and inputSchema for get_command_history.{ 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})` } } } },
- src/types/config.ts:52-58 (schema)TypeScript interface defining the structure of each command history entry returned by the tool.export interface CommandHistoryEntry { command: string; output: string; timestamp: string; exitCode: number; connectionId?: string; }