├── .vscode └── mcp.json ├── LICENSE ├── README.md ├── sales.csv └── server.py /.vscode/mcp.json: -------------------------------------------------------------------------------- 1 | { 2 | "servers": { 3 | "powershell-integration": { 4 | "command": "py", 5 | "args": [ 6 | "d:/mygit/mcp-powershell-exec/server.py" 7 | ], 8 | "env": {} 9 | } 10 | } 11 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2025 Doug Finke 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MCP PowerShell Exec Server 2 | 3 | ## Overview 4 | MCP PowerShell Exec Server is a lightweight server that accepts PowerShell scripts as strings, executes them, and returns the output. Enabling AI assistants to understand and work with PowerShell. 5 | 6 | ## Features 7 | - Accepts PowerShell scripts via string input 8 | - Executes scripts securely in an MCP Server environment 9 | - Returns execution results in real-time 10 | 11 | ## Installation 12 | Clone the repository and set up the server: 13 | 14 | ```powershell 15 | git clone https://github.com/yourusername/mcp-powershell-exec.git 16 | cd mcp-powershell-exec 17 | ``` 18 | ## In Action 19 | 20 | Watch the video to see MCP PowerShell Exec Server in action: 21 | 22 | 23 | 24 | ## Usage 25 | 26 | ### Integration with GitHub Copilot in VSCode Insiders 27 | 28 | To use this MCP server with GitHub Copilot in VSCode Insiders, follow these steps: 29 | 30 | 1. **Install VSCode Insiders** 31 | - Download and install the latest version of [VSCode Insiders](https://code.visualstudio.com/insiders/) 32 | 33 | 1. **Install GitHub Copilot Extension** 34 | - Open VSCode Insiders 35 | - Go to the Extensions marketplace 36 | - Search for and install "GitHub Copilot" 37 | 38 | 3. **Configure MCP Server** 39 | - Open .vscode/mcp.json 40 | ```json 41 | { 42 | "servers": { 43 | "powershell-integration": { 44 | "command": "py", // Python executable 45 | "args": [ 46 | "drive:/yourpath/server.py" 47 | ], 48 | "env": {} 49 | } 50 | } 51 | } 52 | ``` 53 | Replace the path with the actual path to your `server.py` file. 54 | 55 | 56 | 1. **Enable Agent Mode** 57 | - Open Copilot chat in VSCode Insiders 58 | - Click on "Copilot Edits" 59 | - Choose "Agent mode" 60 | - Click the refresh button in the chat input to load the available tools 61 | 62 | ## System Requirements 63 | 64 | - **Python**: Version 3.10 or higher (required for optimal performance) 65 | - **PowerShell**: Version 5.1 66 | 67 | ## License 68 | 69 | This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. 70 | 71 | ## Support 72 | 73 | For issues and questions: 74 | - Create an issue in this GitHub repository -------------------------------------------------------------------------------- /sales.csv: -------------------------------------------------------------------------------- 1 | "Region","State","Units","Price" 2 | "West","Texas","927","923.71" 3 | "North","Tennessee","466","770.67" 4 | "East","Florida","520","458.68" 5 | "East","Maine","828","661.24" 6 | "West","Virginia","465","53.58" 7 | "North","Missouri","436","235.67" 8 | "South","Kansas","214","992.47" 9 | "North","North Dakota","789","640.72" 10 | "South","Delaware","712","508.55" 11 | -------------------------------------------------------------------------------- /server.py: -------------------------------------------------------------------------------- 1 | from mcp.server.fastmcp import FastMCP 2 | 3 | # Initialize the MCP server 4 | mcp = FastMCP("powershell-integration") 5 | 6 | # Define the command to run PowerShell code 7 | @mcp.tool() 8 | def run_powershell(code: str) -> str: 9 | """Runs PowerShell code and returns the output.""" 10 | import subprocess 11 | 12 | # Run the PowerShell command 13 | process = subprocess.Popen( 14 | ["powershell", "-Command", code], 15 | stdout=subprocess.PIPE, 16 | stderr=subprocess.PIPE, 17 | text=True, 18 | ) 19 | 20 | # Get the output and error messages 21 | output, error = process.communicate() 22 | 23 | if process.returncode != 0: 24 | return f"Error: {error}" 25 | 26 | return output 27 | 28 | if __name__ == "__main__": 29 | # Run the MCP server 30 | mcp.run() 31 | --------------------------------------------------------------------------------