diff --git a/README.md b/README.md index dfe3b58..179de3b 100644 --- a/README.md +++ b/README.md @@ -34,21 +34,20 @@ New-MCP d:\temp\testMCP code-insiders d:\temp\testMCP ``` -## Install VS Code Insiders +## Install VS Code -To use PSMCP effectively, you'll need VS Code Insiders. Here's how to install it: +To use PSMCP effectively, you'll need VS Code v1.99.3 or later. Here's how to install it: -1. Visit the [VS Code Insiders download page](https://code.visualstudio.com/insiders/) +1. Visit the [VS Code download page](https://code.visualstudio.com/) 2. Download the appropriate version for your operating system 3. Run the installer and follow the on-screen instructions - ## Set up GitHub Copilot in VS Code + This guide walks you through setting up GitHub Copilot in Visual Studio Code. To use Copilot in VS Code, you need to have access to GitHub Copilot with your GitHub account. [GitHub Copilot Setup Guide](https://code.visualstudio.com/docs/copilot/setup) - ## Getting Started with PSMCP ### New MCP @@ -59,7 +58,6 @@ Start by creating a new MCP server with a simple command. This scaffolds the nec Once initialized, you're ready to configure your MCP tools—no YAML, no fuss. - ### MCP JSON The JSON file defines your available tools. In this example, we’re creating a simple Invoke-Addition function. @@ -69,8 +67,8 @@ The JSON file defines your available tools. In this example, we’re creating a Clicking "Start" embeds the tool definition into the MCP config. Now it’s registered and ready to go. ## After Clicking Start -With the tool registered, starting the server wires up everything under the hood. +With the tool registered, starting the server wires up everything under the hood. ![alt text](media/03-Running.png) @@ -93,6 +91,7 @@ Copilot steps in, proposing to call your registered function based on your promp Confirm to execute and let the AI orchestrate the rest. ## Expand the Run + Peek under the hood—see the actual arguments passed to your function. ![alt text](media/06-ExpandRun.png) @@ -100,12 +99,25 @@ Peek under the hood—see the actual arguments passed to your function. Confirm to execute and let the AI orchestrate the rest. ### After Run + Execution complete. The function ran with your inputs, and now you get the result. ![alt text](media/07-AfterRun.png) This isn’t just code—it’s a conversation. One prompt, one response, and a world of automation opens up. +## Creating your own Functions + +Edit the file adding your functions. + +*TIPS:* + +- Write Help/Comments for your functions that describes what the function does, example(s) and outputs. This will help your MCP Client discover the capabilities and use the functions how you intended. +- Make your Functions Global. (e.g. functionName Global:Get-myFunction {}) +- At the bottom of your add each function comma seperated so that they will be availabile in your MCP Client (e.g. VSCode) + +![alt text](media/08-CreatingYourOwnFunctions.png) + 🟨 Conclusion This workflow redefines how we build and run tools. From scaffolding an MCP server to interacting with it using plain language, the line between prompt and program is disappearing. diff --git a/examples/LocationMCPServer.ps1 b/examples/LocationMCPServer.ps1 new file mode 100644 index 0000000..cdd7303 --- /dev/null +++ b/examples/LocationMCPServer.ps1 @@ -0,0 +1,88 @@ +#Requires -Module PSMCP + +Set-LogFile "$PSScriptRoot\mcp_server.log" + +<# +.SYNOPSIS + Get my public IP Address + + .DESCRIPTION + Uses http://ipinfo.io/json to get the public IP Address of the machine running this script. + This is useful for testing and debugging purposes, especially when working with APIs that require a public IP Address. + + .EXAMPLE + Get-PublicIPAddress + + .OUTPUTS + Returns the public IP Address of the machine running the script. +#> + +function Global:Get-PublicIPAddress { + [CmdletBinding()] + Param + () + Begin { + Write-Verbose -Message "Getting public IP Address" + } + Process { + try { + $ip = Invoke-RestMethod http://ipinfo.io/json | Select-Object -exp ip + Write-Output $ip + } + catch { + Write-Warning -Message "Unable to get public IP Address: $_" + } + } + End { + } +} + + +<# +.Synopsis + Can resolve either an IP Address or a Domain Name and give you geolocation information. +.DESCRIPTION + This module is using https://freegeoip.live API which is free. Yes. It's totally free. They believe that digital businesses need to get such kind of service for free. Many services are selling Geoip API as a service, but they think that it should be totally free. Feel free to their API as much as you want without any limit other than 10,000 queries per hour for one IP address. I thought this would be another good addition to add to the Powershell Gallery. +.Parameter IP + This parameter is used to specify the IP Address you want to find the geolocation information +.Parameter DomainName + This parameter is used to specify the Domain Name address you want to find the geolocation information +.EXAMPLE + Find-Geolocation -DomainName portsmouth.co.uk +.EXAMPLE + Find-Geolocation -IP 141.193.213.10 +#> +function Global:Find-Geolocation { + [CmdletBinding()] + Param + ( + [Parameter(ParameterSetName = 'IP Address Parameter Set')] + [ipaddress]$IP, + [Parameter(ParameterSetName = 'Domain Name Parameter Set')] + [System.Uri]$DomainName + ) + + Begin { + if ($IP) { + $Pattern = $IP + } + if ($DomainName) { + $Pattern = $DomainName + } + } + Process { + foreach ($item in $Pattern) { + Write-Verbose -Message "About to find out more information on $item" + try { + Invoke-RestMethod -Method Get -Uri https://freegeoip.live/json/$item -ErrorAction Stop + } + catch { + Write-Warning -Message "$item : $_" + } + } + } + End { + } +} + +Start-McpServer Find-Geolocation, Get-PublicIPAddress diff --git a/media/08-CreatingYourOwnFunctions.png b/media/08-CreatingYourOwnFunctions.png new file mode 100644 index 0000000..941cac3 Binary files /dev/null and b/media/08-CreatingYourOwnFunctions.png differ