Skip to content

Commit e7dbebe

Browse files
committed
#213 Register-IshRemoveMcpInstructions markdown should escape variables, Invoke request try catch error handling...Next is the problem of the availability of the built-in $ISHRemoteSessionStateIshSession... Later offer the instructions also as explicit must-read Resource as not all LLMs seem to interpret them, append the resource to error messages if possible , then tune the LLM instructions, then proper build that generates resourcesListJson at compile time, performance improvement and cleanup, and review all the tripple-slash help as described in Execution.md [PublishToPSGalleryAsPreview]
1 parent 84b2042 commit e7dbebe

4 files changed

Lines changed: 22 additions & 10 deletions

File tree

.vscode/mcp.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"args": [
77
"-NoProfile",
88
"-Command",
9-
"& { Start-IshRemoteMcpServer -CmdletsToRegister (((Get-Command -Module ISHRemote -ListImported -CommandType Cmdlet).Name) + \"Get-Help\") -LogFilePath \"C:\\GITHUB\\ISHRemote\\IshRemoteMcpServer.log\" }"
9+
"& { Start-IshRemoteMcpServer -CmdletsToRegister (((Get-Command -Module ISHRemote -ListImported -CommandType Cmdlet).Name) + \"Get-Help\") -LogFilePath \"D:\\GITHUB\\ISHRemote\\IshRemoteMcpServer.log\" }"
1010
]
1111
},
1212
"IshRemoteMcpServerDEBUG": {

Doc/TheExecution-ISHRemote-8.2.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Main tasks are
2626
"args": [
2727
"-NoProfile",
2828
"-Command",
29-
"& { Start-IshRemoteMcpServer -CmdletsToRegister (Get-Command -Module ISHRemote -ListImported -CommandType Cmdlet).Name -LogFilePath \"C:\\GITHUB\\ISHRemote\\IshRemoteMcpServer.log\" }"
29+
"& { Start-IshRemoteMcpServer -CmdletsToRegister (Get-Command -Module ISHRemote -ListImported -CommandType Cmdlet).Name -LogFilePath \"D:\\GITHUB\\ISHRemote\\IshRemoteMcpServer.log\" }"
3030
]
3131
}
3232
}
@@ -55,7 +55,7 @@ Main tasks are
5555

5656
```powershell
5757
Install-PSResource -Name PSMCP -Repository PSGallery
58-
CD C:\GITHUB\ISHRemote\MCP
58+
CD D:\GITHUB\ISHRemote\MCP
5959
New-MCP -Path .\ISHRemoteMcpServer -ServerName 'ISHRemoteMcpServer'
6060
```
6161
PSMCP `Register-MCPTool.ps1` does not implement 'description'. There is `Get-Help` that prefers .SYNOPSIS over .DESCRIPTION but eventually it puts the cmdlet name in the description for `tools/list` endpoint
@@ -97,11 +97,11 @@ Overall [PSMCP/Public at main · dfinke/PSMCP](https://github.com/dfinke/PSMCP/t
9797

9898
Is 'inspect' required?
9999

100-
Debugging for now from C:\Github\ISHREMOTE>Copy-Item -Path Source\ISHRemote\Trisoft.ISHRemote\Scripts -Destination Source\ISHRemote\Trisoft.ISHRemote\bin\Debug\ISHRemote\ -Force -Recurse; Import-Module C:\GITHUB\ISHRemote\Source\ISHRemote\Trisoft.ISHRemote\bin\Debug\ISHRemote\ISHRemote.psm1 -Force; start-ishremotemcpserver -ActivateWhileLoop $false
100+
Debugging for now from D:\GITHUB\ISHREMOTE>Copy-Item -Path Source\ISHRemote\Trisoft.ISHRemote\Scripts -Destination Source\ISHRemote\Trisoft.ISHRemote\bin\Debug\ISHRemote\ -Force -Recurse; Import-Module D:\GITHUB\ISHRemote\Source\ISHRemote\Trisoft.ISHRemote\bin\Debug\ISHRemote\ISHRemote.psm1 -Force; start-ishremotemcpserver -ActivateWhileLoop $false
101101

102102
More debugging is:
103-
1. pwsh -NoProfile -Command "& { Copy-Item -Path "C:\GITHUB\ISHRemote\Source\ISHRemote\Trisoft.ISHRemote\Scripts" -Destination "C:\GITHUB\\ISHRemote\Source\ISHRemote\Trisoft.ISHRemote\bin\Debug\ISHRemote\" -Force -Recurse;Import-Module "C:\GITHUB\\ISHRemote\Source\ISHRemote\Trisoft.ISHRemote\bin\Debug\ISHRemote\ISHRemote.psm1" -Verbose -Debug -Force;Import-Module "C:\GITHUB\\ISHRemote\Source\ISHRemote\Trisoft.ISHRemote\bin\Debug\ISHRemote\net6.0\Trisoft.ISHRemote.dll" -Verbose -Debug -Force;Get-IshVersion;(Get-Command -Module ISHRemote -ListImported -CommandType Cmdlet).Name;(Get-Help New-IShSession).Description.Text;(Get-Help New-IShSession).Description;Start-IshRemoteMcpServer -CmdletsToRegister (Get-Command -Module ISHRemote -ListImported -CommandType Cmdlet).Name -ActivateWhileLoop 0 -LogFilePath "C:\GITHUB\ISHRemote\IshRemoteMcpServer.log" }"
104-
2. pwsh -NoProfile -Command "& { $env:PSModulePath=$env:PSModulePath + \";\" + \"C:\GITHUB\ISHRemote\Source\ISHRemote\Trisoft.ISHRemote\bin\Debug\ISHRemote\";Get-IshVersion;(Get-Command -Module ISHRemote -ListImported -CommandType Cmdlet).Name;(Get-Help New-IShSession).Description.Text;(Get-Help New-IShSession).Description;Start-IshRemoteMcpServer -CmdletsToRegister (Get-Command -Module ISHRemote -ListImported -CommandType Cmdlet).Name -ActivateWhileLoop 0 -LogFilePath "C:\GITHUB\ISHRemote\IshRemoteMcpServer.log" }"
103+
1. pwsh -NoProfile -Command "& { Copy-Item -Path "D:\GITHUB\ISHRemote\Source\ISHRemote\Trisoft.ISHRemote\Scripts" -Destination "D:\GITHUB\\ISHRemote\Source\ISHRemote\Trisoft.ISHRemote\bin\Debug\ISHRemote\" -Force -Recurse;Import-Module "D:\GITHUB\\ISHRemote\Source\ISHRemote\Trisoft.ISHRemote\bin\Debug\ISHRemote\ISHRemote.psm1" -Verbose -Debug -Force;Import-Module "D:\GITHUB\\ISHRemote\Source\ISHRemote\Trisoft.ISHRemote\bin\Debug\ISHRemote\net6.0\Trisoft.ISHRemote.dll" -Verbose -Debug -Force;Get-IshVersion;(Get-Command -Module ISHRemote -ListImported -CommandType Cmdlet).Name;(Get-Help New-IShSession).Description.Text;(Get-Help New-IShSession).Description;Start-IshRemoteMcpServer -CmdletsToRegister (Get-Command -Module ISHRemote -ListImported -CommandType Cmdlet).Name -ActivateWhileLoop 0 -LogFilePath "D:\GITHUB\ISHRemote\IshRemoteMcpServer.log" }"
104+
2. pwsh -NoProfile -Command "& { $env:PSModulePath=$env:PSModulePath + \";\" + \"D:\GITHUB\ISHRemote\Source\ISHRemote\Trisoft.ISHRemote\bin\Debug\ISHRemote\";Get-IshVersion;(Get-Command -Module ISHRemote -ListImported -CommandType Cmdlet).Name;(Get-Help New-IShSession).Description.Text;(Get-Help New-IShSession).Description;Start-IshRemoteMcpServer -CmdletsToRegister (Get-Command -Module ISHRemote -ListImported -CommandType Cmdlet).Name -ActivateWhileLoop 0 -LogFilePath "D:\GITHUB\ISHRemote\IshRemoteMcpServer.log" }"
105105

106106

107107

Source/ISHRemote/Trisoft.ISHRemote/Scripts/Public/Invoke-IshRemoteMcpHandleRequest.ps1

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ function Invoke-IshRemoteMcpHandleRequest {
99
# Initialize Method
1010
if ($Request.method -eq "initialize") {
1111
# Static response for simplicity, adjust serverInfo as needed
12-
$response = '{"jsonrpc":"2.0","id":' + ($Request.id | ConvertTo-Json -Depth 10 -Compress) + ',"result":{"protocolVersion":"0.3.0","capabilities":{"tools":{"listChanged":false}},"instructions":"' + $instructionsJson + '","serverInfo":{"name":"PowerShell MCP Server (Template)","version":"0.1.0"}}}'
12+
$response = '{"jsonrpc":"2.0","id":' + ($Request.id | ConvertTo-Json -Depth 10 -Compress) + ',"result":{"protocolVersion":"0.3.0","capabilities":{"tools":{"listChanged":false}},"instructions":' + $instructionsJson + ',"serverInfo":{"name":"PowerShell MCP Server (Template)","version":"0.1.0"}}}'
1313
return $response
1414
}
1515

@@ -45,8 +45,20 @@ function Invoke-IshRemoteMcpHandleRequest {
4545
if ($Request.method -eq "tools/call") {
4646
$toolName = $Request.params.name
4747
$targetArgs = $Request.params.arguments | ConvertTo-Json -Depth 10 | ConvertFrom-Json -Depth 10 -AsHashtable
48-
49-
$result = & $toolName @targetArgs
48+
$result = $null
49+
try {
50+
$result = & $toolName @targetArgs
51+
}
52+
catch {
53+
Write-IshRemoteLog -LogEntry @{
54+
Level = 'Error'
55+
Message = "Error invoking tool [$toolName]: $_"
56+
RequestId = $Request.id
57+
Method = $Request.method
58+
ToolName = $toolName
59+
Arguments = $targetArgs
60+
}
61+
}
5062

5163
# Log structured data
5264
Write-IshRemoteLog -LogEntry @{

Source/ISHRemote/Trisoft.ISHRemote/Scripts/Public/Register-IshRemoteMcpInstructions.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ To execute these MCP Tools, so IShRemote cmdlets, you need to create a `IshSessi
1616
1717
# Rules
1818
19-
1. IShRemote PowerShell cmdlets can be recognized by their naming convention as the noun starts with `ISh`, so verb-`ISh`noun like `New-IShSession`. Most the cmdlets of IShRemote are made available as MCP Tools with the same or reduced parameter set - for example `-IshSession $ishSession` is superfluous and should be avoided.
19+
1. IShRemote PowerShell cmdlets can be recognized by their naming convention as the noun starts with `ISh`, so verb-`ISh`noun like `New-IShSession`. Most the cmdlets of IShRemote are made available as MCP Tools with the same or reduced parameter set - for example parameter `-IshSession` with value `$ishSession` is superfluous and should be avoided.
2020
2. Do not pass parameter `-IshSession` to any MCP Tool.
2121
3. Do not make up parameters for the cmdlets! Do not use and JSON parameters! Do note use hash table structures (`@{ Name = "FUSERNAME"; Value = ...}`) for ISHRemote cmdlets! All parameters should exist and can be verified over the MCP Tool description or by triggering standard PowerShell `Get-Help` cmdlet on it.
2222
4. Do not make up field names or imagine their field level! You must use `Get-IshTypeFieldDefinition` to understand the available field and object types, including custom fields. You can reuse the `Get-IshTypeFieldDefinition` result until a `New-IShSession` was triggered to save tokens. Do not ask for `Continue` for this `Get-IshTypeFieldDefinition` MCP Tool.

0 commit comments

Comments
 (0)